Permalink
Browse files

added two events "security.interactive_login", and "security.switch_u…

…ser"
  • Loading branch information...
schmittjoh authored and fabpot committed Jan 26, 2011
1 parent 00d3d8c commit 8ccb8eb8c2c8a1aec2aa042366353476ca8af728
@@ -224,7 +224,9 @@ protected function onSuccess(EventInterface $event, Request $request, TokenInter
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::LAST_USERNAME);
$this->eventDispatcher->notify(new Event($this, 'security.login_success', array('request' => $request, 'token' => $token)));
if (null !== $this->eventDispatcher) {
$this->eventDispatcher->notify(new Event($this, 'security.interactive_login', array('request' => $request, 'token' => $token)));
}
if (null !== $this->successHandler) {
$response = $this->successHandler->onAuthenticationSuccess($request, $token);
@@ -33,6 +33,7 @@
protected $authenticationManager;
protected $providerKey;
protected $logger;
protected $eventDispatcher;
public function __construct(SecurityContext $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, LoggerInterface $logger = null)
{
@@ -51,6 +52,8 @@ public function __construct(SecurityContext $securityContext, AuthenticationMana
public function register(EventDispatcherInterface $dispatcher)
{
$dispatcher->connect('core.security', array($this, 'handle'), 0);
$this->eventDispatcher = $dispatcher;
}
/**
@@ -96,6 +99,10 @@ public function handle(EventInterface $event)
$this->logger->debug(sprintf('Authentication success: %s', $token));
}
$this->securityContext->setToken($token);
if (null !== $this->eventDispatcher) {
$this->eventDispatcher->notify(new Event($this, 'security.interactive_login', array('request' => $request, 'token' => $token)));
}
} catch (AuthenticationException $failed) {
$this->securityContext->setToken(null);
@@ -35,6 +35,7 @@ class RememberMeListener implements ListenerInterface
protected $authenticationManager;
protected $logger;
protected $lastState;
protected $eventDispatcher;
/**
* Constructor
@@ -62,6 +63,8 @@ public function register(EventDispatcherInterface $dispatcher)
{
$dispatcher->connect('core.security', array($this, 'checkCookies'), 0);
$dispatcher->connect('core.response', array($this, 'updateCookies'), 0);
$this->eventDispatcher = $dispatcher;
}
/**
@@ -97,6 +100,10 @@ public function checkCookies(EventInterface $event)
$this->securityContext->setToken($token);
if (null !== $this->eventDispatcher) {
$this->eventDispatcher->notify(new Event($this, 'security.interactive_login', array('request' => $request, 'token' => $token)));
}
if (null !== $this->logger) {
$this->logger->debug('SecurityContext populated with remember-me token.');
}
@@ -42,6 +42,7 @@ class SwitchUserListener implements ListenerInterface
protected $usernameParameter;
protected $role;
protected $logger;
protected $eventDispatcher;
/**
* Constructor.
@@ -71,6 +72,8 @@ public function __construct(SecurityContext $securityContext, UserProviderInterf
public function register(EventDispatcherInterface $dispatcher)
{
$dispatcher->connect('core.security', array($this, 'handle'), 0);
$this->eventDispatcher = $dispatcher;
}
/**
@@ -145,6 +148,10 @@ protected function attemptSwitchUser(Request $request)
$token = new UsernamePasswordToken($user, $user->getPassword(), $this->providerKey, $roles);
$token->setImmutable(true);
if (null !== $this->eventDispatcher) {
$this->eventDispatcher->notify(new Event($this, 'security.switch_user', array('request' => $request, 'target_user' => $token->getUser())));
}
return $token;
}
@@ -161,6 +168,10 @@ protected function attemptExitUser(Request $request)
throw new AuthenticationCredentialsNotFoundException(sprintf('Could not find original Token object.'));
}
if (null !== $this->eventDispatcher) {
$this->eventDispatcher->notify(new Event($this, 'security.switch_user', array('request' => $request, 'target_user' => $original->getUser())));
}
return $original;
}

0 comments on commit 8ccb8eb

Please sign in to comment.