summaryrefslogtreecommitdiffstats
path: root/Guard
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2015-09-27 12:13:28 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2015-09-27 12:13:28 +0200
commit085fdff5afa56b088fe298d08940afd2900d7d29 (patch)
tree08f3bf408e11a64efa0ed3be8597527a1a2acc97 /Guard
parent1e2b64278942bd318519cac7ec1af58b0fc711bb (diff)
parentae2c4c820d9aca6ad7eac272e9c18f72c15dc04a (diff)
downloadsymfony-security-085fdff5afa56b088fe298d08940afd2900d7d29.zip
symfony-security-085fdff5afa56b088fe298d08940afd2900d7d29.tar.gz
symfony-security-085fdff5afa56b088fe298d08940afd2900d7d29.tar.bz2
Merge branch '2.8'
* 2.8: (28 commits) Detect Mintty for color support on Windows Detect Mintty for color support on Windows [WebProfilerBundle] Fix search button click listener [Form][Type Date/Time] added choice_translation_domain option. Massively simplifying the BC and deprecated-throwing code thanks to suggestions by stof in #15870 Making all "debug" messages use the debug router Making GuardTokenInterface extend TokenInterface Updating behavior to not continue after an authenticator has set the response Add a group for tests of the finder against the FTP server Fix trigger_error calls Fix legacy security tests tweaking message related to configuration edge case that we want to be helpful with Minor tweaks - lowering the required security-http requirement and nulling out a test field Fix license headers Fix license headers Fix license headers Ensure the ClockMock is loaded before using it in the testsuite Allow serializer 3.0 in the PropertyInfo component Add the replace rules for the security-guard component Forbid serializing a Crawler ...
Diffstat (limited to 'Guard')
-rw-r--r--Guard/Firewall/GuardAuthenticationListener.php20
-rw-r--r--Guard/Tests/Firewall/GuardAuthenticationListenerTest.php36
-rw-r--r--Guard/Token/GuardTokenInterface.php4
3 files changed, 51 insertions, 9 deletions
diff --git a/Guard/Firewall/GuardAuthenticationListener.php b/Guard/Firewall/GuardAuthenticationListener.php
index 6140be0..0ac7c12 100644
--- a/Guard/Firewall/GuardAuthenticationListener.php
+++ b/Guard/Firewall/GuardAuthenticationListener.php
@@ -66,7 +66,7 @@ class GuardAuthenticationListener implements ListenerInterface
public function handle(GetResponseEvent $event)
{
if (null !== $this->logger) {
- $this->logger->info('Checking for guard authentication credentials.', array('firewall_key' => $this->providerKey, 'authenticators' => count($this->guardAuthenticators)));
+ $this->logger->debug('Checking for guard authentication credentials.', array('firewall_key' => $this->providerKey, 'authenticators' => count($this->guardAuthenticators)));
}
foreach ($this->guardAuthenticators as $key => $guardAuthenticator) {
@@ -75,6 +75,12 @@ class GuardAuthenticationListener implements ListenerInterface
$uniqueGuardKey = $this->providerKey.'_'.$key;
$this->executeGuardAuthenticator($uniqueGuardKey, $guardAuthenticator, $event);
+
+ if ($event->hasResponse()) {
+ $this->logger->debug(sprintf('The "%s" authenticator set the response. Any later authenticator will not be called', get_class($guardAuthenticator)));
+
+ break;
+ }
}
}
@@ -83,7 +89,7 @@ class GuardAuthenticationListener implements ListenerInterface
$request = $event->getRequest();
try {
if (null !== $this->logger) {
- $this->logger->info('Calling getCredentials on guard configurator.', array('firewall_key' => $this->providerKey, 'authenticator' => get_class($guardAuthenticator)));
+ $this->logger->debug('Calling getCredentials() on guard configurator.', array('firewall_key' => $this->providerKey, 'authenticator' => get_class($guardAuthenticator)));
}
// allow the authenticator to fetch authentication info from the request
@@ -98,7 +104,7 @@ class GuardAuthenticationListener implements ListenerInterface
$token = new PreAuthenticationGuardToken($credentials, $uniqueGuardKey);
if (null !== $this->logger) {
- $this->logger->info('Passing guard token information to the GuardAuthenticationProvider', array('firewall_key' => $this->providerKey, 'authenticator' => get_class($guardAuthenticator)));
+ $this->logger->debug('Passing guard token information to the GuardAuthenticationProvider', array('firewall_key' => $this->providerKey, 'authenticator' => get_class($guardAuthenticator)));
}
// pass the token into the AuthenticationManager system
// this indirectly calls GuardAuthenticationProvider::authenticate()
@@ -130,13 +136,13 @@ class GuardAuthenticationListener implements ListenerInterface
$response = $this->guardHandler->handleAuthenticationSuccess($token, $request, $guardAuthenticator, $this->providerKey);
if ($response instanceof Response) {
if (null !== $this->logger) {
- $this->logger->info('Guard authenticator set success response.', array('response' => $response, 'authenticator' => get_class($guardAuthenticator)));
+ $this->logger->debug('Guard authenticator set success response.', array('response' => $response, 'authenticator' => get_class($guardAuthenticator)));
}
$event->setResponse($response);
} else {
if (null !== $this->logger) {
- $this->logger->info('Guard authenticator set no success response: request continues.', array('authenticator' => get_class($guardAuthenticator)));
+ $this->logger->debug('Guard authenticator set no success response: request continues.', array('authenticator' => get_class($guardAuthenticator)));
}
}
@@ -167,7 +173,7 @@ class GuardAuthenticationListener implements ListenerInterface
{
if (null === $this->rememberMeServices) {
if (null !== $this->logger) {
- $this->logger->info('Remember me skipped: it is not configured for the firewall.', array('authenticator' => get_class($guardAuthenticator)));
+ $this->logger->debug('Remember me skipped: it is not configured for the firewall.', array('authenticator' => get_class($guardAuthenticator)));
}
return;
@@ -175,7 +181,7 @@ class GuardAuthenticationListener implements ListenerInterface
if (!$guardAuthenticator->supportsRememberMe()) {
if (null !== $this->logger) {
- $this->logger->info('Remember me skipped: your authenticator does not support it.', array('authenticator' => get_class($guardAuthenticator)));
+ $this->logger->debug('Remember me skipped: your authenticator does not support it.', array('authenticator' => get_class($guardAuthenticator)));
}
return;
diff --git a/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php b/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php
index 8fab399..3224fee 100644
--- a/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php
+++ b/Guard/Tests/Firewall/GuardAuthenticationListenerTest.php
@@ -79,6 +79,36 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$listener->handle($this->event);
}
+ public function testHandleSuccessStopsAfterResponseIsSet()
+ {
+ $authenticator1 = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
+ $authenticator2 = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
+
+ // mock the first authenticator to fail, and set a Response
+ $authenticator1
+ ->expects($this->once())
+ ->method('getCredentials')
+ ->willThrowException(new AuthenticationException());
+ $this->guardAuthenticatorHandler
+ ->expects($this->once())
+ ->method('handleAuthenticationFailure')
+ ->willReturn(new Response());
+ // the second authenticator should *never* be called
+ $authenticator2
+ ->expects($this->never())
+ ->method('getCredentials');
+
+ $listener = new GuardAuthenticationListener(
+ $this->guardAuthenticatorHandler,
+ $this->authenticationManager,
+ 'my_firewall',
+ array($authenticator1, $authenticator2),
+ $this->logger
+ );
+
+ $listener->handle($this->event);
+ }
+
public function testHandleSuccessWithRememberMe()
{
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
@@ -201,7 +231,10 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$this->request = new Request(array(), array(), array(), array(), array(), array());
- $this->event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
+ $this->event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
+ ->disableOriginalConstructor()
+ ->setMethods(array('getRequest'))
+ ->getMock();
$this->event
->expects($this->any())
->method('getRequest')
@@ -218,5 +251,6 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
$this->event = null;
$this->logger = null;
$this->request = null;
+ $this->rememberMeServices = null;
}
}
diff --git a/Guard/Token/GuardTokenInterface.php b/Guard/Token/GuardTokenInterface.php
index f0db250..063ffd3 100644
--- a/Guard/Token/GuardTokenInterface.php
+++ b/Guard/Token/GuardTokenInterface.php
@@ -11,6 +11,8 @@
namespace Symfony\Component\Security\Guard\Token;
+use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+
/**
* A marker interface that both guard tokens implement.
*
@@ -20,6 +22,6 @@ namespace Symfony\Component\Security\Guard\Token;
*
* @author Ryan Weaver <ryan@knpuniversity.com>
*/
-interface GuardTokenInterface
+interface GuardTokenInterface extends TokenInterface
{
}