...
Code Block | ||
---|---|---|
| ||
security:
providers:
# Chaining in_memory and ezpublish user providers
chain_provider:
chain:
providers: [in_memory, ezpublish]
ezpublish:
id: ezpublish.security.user_provider
in_memory:
memory:
users:
# You will then be able to login with username "user" and password "userpass"
user: { password: userpass, roles: [ 'ROLE_USER' ] }
# The "in memory" provider requires an encoder for Symfony\Component\Security\Core\User\User
encoders:
Symfony\Component\Security\Core\User\User: plaintext |
Implementing the listener
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?php namespace Acme\TestBundle\EventListener; use eZ\Publish\API\Repository\UserService; use eZ\Publish\Core\MVC\Symfony\Event\InteractiveLoginEvent; use eZ\Publish\Core\MVC\Symfony\MVCEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class InteractiveLoginListener implements EventSubscriberInterface { /** * @var \eZ\Publish\API\Repository\UserService */ private $userService; public function __construct( UserService $userService ) { $this->userService = $userService; } public static function getSubscribedEvents() { return array( MVCEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin' ); } public function onInteractiveLogin( InteractiveLoginEvent $event ) { // We just load a generic user and assign it back to the event. // You may want to create users here, or even load predefined users depending on your own rules. $event->setApiUser( $this->userService->loadUserByLogin( 'lolautruche' ) ); } } |
+ # The "in memory" provider requires an encoder for Symfony\Component\Security\Core\User\User |
+ encoders: |
+ Symfony\Component\Security\Core\User\User: