added two events "security.interactive_login", and "security.switch_user"
This commit is contained in:
parent
00d3d8c3bc
commit
8ccb8eb8c2
@ -224,7 +224,9 @@ abstract class AbstractAuthenticationListener implements ListenerInterface
|
|||||||
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
|
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
|
||||||
$session->remove(SecurityContext::LAST_USERNAME);
|
$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) {
|
if (null !== $this->successHandler) {
|
||||||
$response = $this->successHandler->onAuthenticationSuccess($request, $token);
|
$response = $this->successHandler->onAuthenticationSuccess($request, $token);
|
||||||
|
@ -33,6 +33,7 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
|
|||||||
protected $authenticationManager;
|
protected $authenticationManager;
|
||||||
protected $providerKey;
|
protected $providerKey;
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
protected $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(SecurityContext $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, LoggerInterface $logger = null)
|
public function __construct(SecurityContext $securityContext, AuthenticationManagerInterface $authenticationManager, $providerKey, LoggerInterface $logger = null)
|
||||||
{
|
{
|
||||||
@ -51,6 +52,8 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
|
|||||||
public function register(EventDispatcherInterface $dispatcher)
|
public function register(EventDispatcherInterface $dispatcher)
|
||||||
{
|
{
|
||||||
$dispatcher->connect('core.security', array($this, 'handle'), 0);
|
$dispatcher->connect('core.security', array($this, 'handle'), 0);
|
||||||
|
|
||||||
|
$this->eventDispatcher = $dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,6 +99,10 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
|
|||||||
$this->logger->debug(sprintf('Authentication success: %s', $token));
|
$this->logger->debug(sprintf('Authentication success: %s', $token));
|
||||||
}
|
}
|
||||||
$this->securityContext->setToken($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) {
|
} catch (AuthenticationException $failed) {
|
||||||
$this->securityContext->setToken(null);
|
$this->securityContext->setToken(null);
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ class RememberMeListener implements ListenerInterface
|
|||||||
protected $authenticationManager;
|
protected $authenticationManager;
|
||||||
protected $logger;
|
protected $logger;
|
||||||
protected $lastState;
|
protected $lastState;
|
||||||
|
protected $eventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -62,6 +63,8 @@ class RememberMeListener implements ListenerInterface
|
|||||||
{
|
{
|
||||||
$dispatcher->connect('core.security', array($this, 'checkCookies'), 0);
|
$dispatcher->connect('core.security', array($this, 'checkCookies'), 0);
|
||||||
$dispatcher->connect('core.response', array($this, 'updateCookies'), 0);
|
$dispatcher->connect('core.response', array($this, 'updateCookies'), 0);
|
||||||
|
|
||||||
|
$this->eventDispatcher = $dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,6 +100,10 @@ class RememberMeListener implements ListenerInterface
|
|||||||
|
|
||||||
$this->securityContext->setToken($token);
|
$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) {
|
if (null !== $this->logger) {
|
||||||
$this->logger->debug('SecurityContext populated with remember-me token.');
|
$this->logger->debug('SecurityContext populated with remember-me token.');
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ class SwitchUserListener implements ListenerInterface
|
|||||||
protected $usernameParameter;
|
protected $usernameParameter;
|
||||||
protected $role;
|
protected $role;
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
protected $eventDispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -71,6 +72,8 @@ class SwitchUserListener implements ListenerInterface
|
|||||||
public function register(EventDispatcherInterface $dispatcher)
|
public function register(EventDispatcherInterface $dispatcher)
|
||||||
{
|
{
|
||||||
$dispatcher->connect('core.security', array($this, 'handle'), 0);
|
$dispatcher->connect('core.security', array($this, 'handle'), 0);
|
||||||
|
|
||||||
|
$this->eventDispatcher = $dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,6 +148,10 @@ class SwitchUserListener implements ListenerInterface
|
|||||||
$token = new UsernamePasswordToken($user, $user->getPassword(), $this->providerKey, $roles);
|
$token = new UsernamePasswordToken($user, $user->getPassword(), $this->providerKey, $roles);
|
||||||
$token->setImmutable(true);
|
$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;
|
return $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +168,10 @@ class SwitchUserListener implements ListenerInterface
|
|||||||
throw new AuthenticationCredentialsNotFoundException(sprintf('Could not find original Token object.'));
|
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;
|
return $original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user