diff options
-rw-r--r-- | Http/Firewall.php | 36 | ||||
-rw-r--r-- | Http/Firewall/AbstractAuthenticationListener.php | 23 | ||||
-rw-r--r-- | Http/Firewall/AbstractPreAuthenticatedListener.php | 23 | ||||
-rw-r--r-- | Http/Firewall/AccessListener.php | 18 | ||||
-rw-r--r-- | Http/Firewall/AnonymousAuthenticationListener.php | 19 | ||||
-rw-r--r-- | Http/Firewall/BasicAuthenticationListener.php | 18 | ||||
-rw-r--r-- | Http/Firewall/ChannelListener.php | 18 | ||||
-rw-r--r-- | Http/Firewall/ContextListener.php | 28 | ||||
-rw-r--r-- | Http/Firewall/DigestAuthenticationListener.php | 18 | ||||
-rw-r--r-- | Http/Firewall/ExceptionListener.php | 8 | ||||
-rw-r--r-- | Http/Firewall/ListenerInterface.php | 23 | ||||
-rw-r--r-- | Http/Firewall/LogoutListener.php | 18 | ||||
-rw-r--r-- | Http/Firewall/RememberMeListener.php | 25 | ||||
-rw-r--r-- | Http/Firewall/SwitchUserListener.php | 23 | ||||
-rw-r--r-- | Http/Firewall/UsernamePasswordFormAuthenticationListener.php | 9 | ||||
-rw-r--r-- | Http/Firewall/X509AuthenticationListener.php | 5 |
16 files changed, 35 insertions, 277 deletions
diff --git a/Http/Firewall.php b/Http/Firewall.php index 66b3ce6..4935985 100644 --- a/Http/Firewall.php +++ b/Http/Firewall.php @@ -32,19 +32,16 @@ use Symfony\Component\HttpFoundation\Request; class Firewall { private $map; - private $dispatcher; - private $currentListeners; /** * Constructor. * * @param FirewallMap $map A FirewallMap instance */ - public function __construct(FirewallMapInterface $map, EventDispatcherInterface $dispatcher) + public function __construct(FirewallMapInterface $map) { $this->map = $map; $this->dispatcher = $dispatcher; - $this->currentListeners = array(); } /** @@ -58,38 +55,19 @@ class Firewall return; } - $request = $event->get('request'); - - // disconnect all listeners from core.security to avoid the overhead - // of most listeners having to do this manually - $this->dispatcher->disconnect('core.security'); - - // ensure that listeners disconnect from wherever they have connected to - foreach ($this->currentListeners as $listener) { - $listener->unregister($this->dispatcher); - } - // register listeners for this firewall - list($listeners, $exception) = $this->map->getListeners($request); + list($listeners, $exception) = $this->map->getListeners($event->get('request')); if (null !== $exception) { $exception->register($this->dispatcher); } - foreach ($listeners as $listener) { - $listener->register($this->dispatcher); - } - - // save current listener instances - $this->currentListeners = $listeners; - if (null !== $exception) { - $this->currentListeners[] = $exception; - } // initiate the listener chain - $ret = $this->dispatcher->notifyUntil($securityEvent = new Event($request, 'core.security', array('request' => $request))); - if ($securityEvent->isProcessed()) { - $event->setProcessed(); + foreach ($listeners as $listener) { + $response = $listener->handle($event); - return $ret; + if ($event->isProcessed()) { + return $response; + } } } } diff --git a/Http/Firewall/AbstractAuthenticationListener.php b/Http/Firewall/AbstractAuthenticationListener.php index eefe2f4..2108980 100644 --- a/Http/Firewall/AbstractAuthenticationListener.php +++ b/Http/Firewall/AbstractAuthenticationListener.php @@ -66,7 +66,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface * @param array $options An array of options for the processing of a successful, or failed authentication attempt * @param LoggerInterface $logger A LoggerInterface instance */ - public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null) + public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $eventDispatcher = null) { if (empty($providerKey)) { throw new \InvalidArgumentException('$providerKey must not be empty.'); @@ -89,6 +89,7 @@ abstract class AbstractAuthenticationListener implements ListenerInterface 'failure_forward' => false, ), $options); $this->logger = $logger; + $this->eventDispatcher = $eventDispatcher; } /** @@ -102,26 +103,6 @@ abstract class AbstractAuthenticationListener implements ListenerInterface } /** - * Subscribe to the core.security event - * - * @param EventDispatcher $dispatcher An EventDispatcher instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - - $this->eventDispatcher = $dispatcher; - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - } - - /** * Handles form based authentication. * * @param Event $event An Event instance diff --git a/Http/Firewall/AbstractPreAuthenticatedListener.php b/Http/Firewall/AbstractPreAuthenticatedListener.php index 716f575..72808f5 100644 --- a/Http/Firewall/AbstractPreAuthenticatedListener.php +++ b/Http/Firewall/AbstractPreAuthenticatedListener.php @@ -36,32 +36,13 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface private $providerKey; private $eventDispatcher; - public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, LoggerInterface $logger = null) + public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, LoggerInterface $logger = null, EventDispatcherInterface $eventDispatcher = null) { $this->securityContext = $securityContext; $this->authenticationManager = $authenticationManager; $this->providerKey = $providerKey; $this->logger = $logger; - } - - /** - * - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - - $this->eventDispatcher = $dispatcher; - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { + $this->eventDispatcher = $eventDispatcher; } /** diff --git a/Http/Firewall/AccessListener.php b/Http/Firewall/AccessListener.php index 3bbbc4b..a4faeb5 100644 --- a/Http/Firewall/AccessListener.php +++ b/Http/Firewall/AccessListener.php @@ -44,24 +44,6 @@ class AccessListener implements ListenerInterface } /** - * Registers a core.security listener to enforce authorization rules. - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - } - - /** * Handles access authorization. * * @param EventInterface $event An EventInterface instance diff --git a/Http/Firewall/AnonymousAuthenticationListener.php b/Http/Firewall/AnonymousAuthenticationListener.php index 9450006..47ca58f 100644 --- a/Http/Firewall/AnonymousAuthenticationListener.php +++ b/Http/Firewall/AnonymousAuthenticationListener.php @@ -37,25 +37,6 @@ class AnonymousAuthenticationListener implements ListenerInterface } /** - * Registers a core.security listener to load the SecurityContext from the - * session. - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - } - - /** * Handles anonymous authentication. * * @param EventInterface $event An EventInterface instance diff --git a/Http/Firewall/BasicAuthenticationListener.php b/Http/Firewall/BasicAuthenticationListener.php index 3ae3e51..b9a764a 100644 --- a/Http/Firewall/BasicAuthenticationListener.php +++ b/Http/Firewall/BasicAuthenticationListener.php @@ -49,24 +49,6 @@ class BasicAuthenticationListener implements ListenerInterface } /** - * - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - } - - /** * Handles basic authentication. * * @param EventInterface $event An EventInterface instance diff --git a/Http/Firewall/ChannelListener.php b/Http/Firewall/ChannelListener.php index b0db398..92a9c3b 100644 --- a/Http/Firewall/ChannelListener.php +++ b/Http/Firewall/ChannelListener.php @@ -37,24 +37,6 @@ class ChannelListener implements ListenerInterface } /** - * - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - } - - /** * Handles channel management. * * @param EventInterface $event An EventInterface instance diff --git a/Http/Firewall/ContextListener.php b/Http/Firewall/ContextListener.php index c61885d..4779b70 100644 --- a/Http/Firewall/ContextListener.php +++ b/Http/Firewall/ContextListener.php @@ -36,7 +36,7 @@ class ContextListener implements ListenerInterface private $logger; private $userProviders; - public function __construct(SecurityContext $context, array $userProviders, $contextKey, LoggerInterface $logger = null) + public function __construct(SecurityContext $context, array $userProviders, $contextKey, LoggerInterface $logger = null, EventDispatcherInterface $eventDispatcher = null) { if (empty($contextKey)) { throw new \InvalidArgumentException('$contextKey must not be empty.'); @@ -45,28 +45,10 @@ class ContextListener implements ListenerInterface $this->context = $context; $this->userProviders = $userProviders; $this->contextKey = $contextKey; - $this->logger = $logger; - } - /** - * Registers a core.security listener to load the SecurityContext from the - * session. - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'read'), 0); - $dispatcher->connect('core.response', array($this, 'write'), 0); - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - $dispatcher->disconnect('core.response', array($this, 'write')); + if (null !== $this->eventDispatcher) { + $this->eventDispatcher->connect('core.response', array($this, 'write'), 0); + } } /** @@ -74,7 +56,7 @@ class ContextListener implements ListenerInterface * * @param EventInterface $event An EventInterface instance */ - public function read(EventInterface $event) + public function handle(EventInterface $event) { $request = $event->get('request'); diff --git a/Http/Firewall/DigestAuthenticationListener.php b/Http/Firewall/DigestAuthenticationListener.php index de5ba18..c64cf1c 100644 --- a/Http/Firewall/DigestAuthenticationListener.php +++ b/Http/Firewall/DigestAuthenticationListener.php @@ -52,24 +52,6 @@ class DigestAuthenticationListener implements ListenerInterface } /** - * - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - } - - /** * Handles digest authentication. * * @param EventInterface $event An EventInterface instance diff --git a/Http/Firewall/ExceptionListener.php b/Http/Firewall/ExceptionListener.php index 90f5a01..110290c 100644 --- a/Http/Firewall/ExceptionListener.php +++ b/Http/Firewall/ExceptionListener.php @@ -63,14 +63,6 @@ class ExceptionListener implements ListenerInterface } /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - $dispatcher->disconnect('core.exception', array($this, 'handleException')); - } - - /** * Handles security related exceptions. * * @param EventInterface $event An EventInterface instance diff --git a/Http/Firewall/ListenerInterface.php b/Http/Firewall/ListenerInterface.php index 73a30cd..44d2902 100644 --- a/Http/Firewall/ListenerInterface.php +++ b/Http/Firewall/ListenerInterface.php @@ -11,32 +11,21 @@ namespace Symfony\Component\Security\Http\Firewall; +use Symfony\Component\EventDispatcher\EventInterface; + use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Interface that must be implemented by firewall listeners - * + * * @author Johannes M. Schmitt <schmittjoh@gmail.com> */ interface ListenerInterface { /** - * The implementation must connect this listener to all necessary events. - * - * Typical events are: "core.security", and "core.response" - * - * @param EventDispatcherInterface $dispatcher - */ - function register(EventDispatcherInterface $dispatcher); - - /** - * The implementation must remove this listener from any events that it had - * connected to in register(). - * - * It may remove this listener from "core.security", but this is ensured by - * the firewall anyway. + * This interface must be implemented by firewall listeners. * - * @param EventDispatcherInterface $dispatcher + * @param EventInterface $dispatcher */ - function unregister(EventDispatcherInterface $dispatcher); + function handle(EventInterface $event); }
\ No newline at end of file diff --git a/Http/Firewall/LogoutListener.php b/Http/Firewall/LogoutListener.php index 9963757..bdb92bc 100644 --- a/Http/Firewall/LogoutListener.php +++ b/Http/Firewall/LogoutListener.php @@ -61,24 +61,6 @@ class LogoutListener implements ListenerInterface } /** - * Registers a core.security listener. - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { - } - - /** * Performs the logout if requested * * @param EventInterface $event An EventInterface instance diff --git a/Http/Firewall/RememberMeListener.php b/Http/Firewall/RememberMeListener.php index f0755db..725755d 100644 --- a/Http/Firewall/RememberMeListener.php +++ b/Http/Firewall/RememberMeListener.php @@ -45,32 +45,13 @@ class RememberMeListener implements ListenerInterface * @param AuthenticationManagerInterface $authenticationManager * @param LoggerInterface $logger */ - public function __construct(SecurityContext $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null) + public function __construct(SecurityContext $securityContext, RememberMeServicesInterface $rememberMeServices, AuthenticationManagerInterface $authenticationManager, LoggerInterface $logger = null, EventDispatcherInterface $eventDispatcher = null) { $this->securityContext = $securityContext; $this->rememberMeServices = $rememberMeServices; $this->authenticationManager = $authenticationManager; $this->logger = $logger; - } - - /** - * Listen to core.security, and core.response event - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'checkCookies'), 0); - - $this->eventDispatcher = $dispatcher; - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { + $this->eventDispatcher = $eventDispatcher; } /** @@ -78,7 +59,7 @@ class RememberMeListener implements ListenerInterface * * @param Event $event An Event instance */ - public function checkCookies(EventInterface $event) + public function handle(EventInterface $event) { if (null !== $this->securityContext->getToken()) { return; diff --git a/Http/Firewall/SwitchUserListener.php b/Http/Firewall/SwitchUserListener.php index 96891bd..e1925bd 100644 --- a/Http/Firewall/SwitchUserListener.php +++ b/Http/Firewall/SwitchUserListener.php @@ -49,7 +49,7 @@ class SwitchUserListener implements ListenerInterface /** * Constructor. */ - public function __construct(SecurityContextInterface $securityContext, UserProviderInterface $provider, UserCheckerInterface $userChecker, $providerKey, AccessDecisionManagerInterface $accessDecisionManager, LoggerInterface $logger = null, $usernameParameter = '_switch_user', $role = 'ROLE_ALLOWED_TO_SWITCH') + public function __construct(SecurityContextInterface $securityContext, UserProviderInterface $provider, UserCheckerInterface $userChecker, $providerKey, AccessDecisionManagerInterface $accessDecisionManager, LoggerInterface $logger = null, $usernameParameter = '_switch_user', $role = 'ROLE_ALLOWED_TO_SWITCH', EventDispatcherInterface $eventDispatcher = null) { if (empty($providerKey)) { throw new \InvalidArgumentException('$providerKey must not be empty.'); @@ -63,26 +63,7 @@ class SwitchUserListener implements ListenerInterface $this->usernameParameter = $usernameParameter; $this->role = $role; $this->logger = $logger; - } - - /** - * - * - * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance - * @param integer $priority The priority - */ - public function register(EventDispatcherInterface $dispatcher) - { - $dispatcher->connect('core.security', array($this, 'handle'), 0); - - $this->eventDispatcher = $dispatcher; - } - - /** - * {@inheritDoc} - */ - public function unregister(EventDispatcherInterface $dispatcher) - { + $this->eventDispatcher = $eventDispatcher; } /** diff --git a/Http/Firewall/UsernamePasswordFormAuthenticationListener.php b/Http/Firewall/UsernamePasswordFormAuthenticationListener.php index 3008273..2402105 100644 --- a/Http/Firewall/UsernamePasswordFormAuthenticationListener.php +++ b/Http/Firewall/UsernamePasswordFormAuthenticationListener.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Security\Http\Firewall; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + use Symfony\Component\Form\CsrfProvider\CsrfProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Log\LoggerInterface; @@ -35,7 +37,7 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL /** * {@inheritdoc} */ - public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, CsrfProviderInterface $csrfProvider = null) + public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, $providerKey, array $options = array(), AuthenticationSuccessHandlerInterface $successHandler = null, AuthenticationFailureHandlerInterface $failureHandler = null, LoggerInterface $logger = null, EventDispatcherInterface $eventDispatcher = null, CsrfProviderInterface $csrfProvider = null) { parent::__construct($securityContext, $authenticationManager, $sessionStrategy, $providerKey, array_merge(array( 'username_parameter' => '_username', @@ -43,7 +45,7 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL 'csrf_parameter' => '_csrf_token', 'csrf_page_id' => 'form_login', 'post_only' => true, - ), $options), $successHandler, $failureHandler, $logger); + ), $options), $successHandler, $failureHandler, $logger, $eventDispatcher); $this->csrfProvider = $csrfProvider; } @@ -76,5 +78,4 @@ class UsernamePasswordFormAuthenticationListener extends AbstractAuthenticationL return $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $password, $this->providerKey)); } -} - +}
\ No newline at end of file diff --git a/Http/Firewall/X509AuthenticationListener.php b/Http/Firewall/X509AuthenticationListener.php index 3505b99..22b62dc 100644 --- a/Http/Firewall/X509AuthenticationListener.php +++ b/Http/Firewall/X509AuthenticationListener.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Security\Http\Firewall; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; use Symfony\Component\HttpKernel\Log\LoggerInterface; @@ -27,9 +28,9 @@ class X509AuthenticationListener extends AbstractPreAuthenticatedListener protected $userKey; protected $credentialKey; - public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, $userKey = 'SSL_CLIENT_S_DN_Email', $credentialKey = 'SSL_CLIENT_S_DN', LoggerInterface $logger = null) + public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, $userKey = 'SSL_CLIENT_S_DN_Email', $credentialKey = 'SSL_CLIENT_S_DN', LoggerInterface $logger = null, EventDispatcherInterface $eventDispatcher = null) { - parent::__construct($securityContext, $authenticationManager, $providerKey, $logger); + parent::__construct($securityContext, $authenticationManager, $providerKey, $logger, $eventDispatcher); $this->userKey = $userKey; $this->credentialKey = $credentialKey; |