diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2014-04-22 10:11:23 +0200 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2014-04-22 10:11:23 +0200 |
commit | 3653a49d805f848c154faa8bbbd663670a5297ec (patch) | |
tree | d78e0609597e35cd50b3afac69f120d78453c9cb | |
parent | df77b8aebb4e69fbf9cd862c279d29319713690a (diff) | |
parent | 013e84fe863ea6de2f314ae5b813e9fc51aabe55 (diff) | |
download | symfony-security-3653a49d805f848c154faa8bbbd663670a5297ec.zip symfony-security-3653a49d805f848c154faa8bbbd663670a5297ec.tar.gz symfony-security-3653a49d805f848c154faa8bbbd663670a5297ec.tar.bz2 |
Merge branch '2.4'
* 2.4:
fix docblock
Fixed incompatibility of x509 auth with nginx
[Process] Setting STDIN while running should not be possible
[Validator] slovenian translation updated
[FrameworkBundle] improve English in RouterMatchCommand
[Validator] Updated Hungarian translations
[Doctrine Bridge] simplify session handler by using main connection
[Validator] Fixed typos in German translation
[Validator] Completed French translations
[Validator] Completed German translations
[Validator] Completed Luxembourgish translations
-rw-r--r-- | Http/Firewall/X509AuthenticationListener.php | 13 | ||||
-rw-r--r-- | Http/Tests/Firewall/X509AuthenticationListenerTest.php | 51 |
2 files changed, 43 insertions, 21 deletions
diff --git a/Http/Firewall/X509AuthenticationListener.php b/Http/Firewall/X509AuthenticationListener.php index 5aabf75..9c07be1 100644 --- a/Http/Firewall/X509AuthenticationListener.php +++ b/Http/Firewall/X509AuthenticationListener.php @@ -41,10 +41,17 @@ class X509AuthenticationListener extends AbstractPreAuthenticatedListener */ protected function getPreAuthenticatedData(Request $request) { - if (!$request->server->has($this->userKey)) { - throw new BadCredentialsException(sprintf('SSL key was not found: %s', $this->userKey)); + $user = null; + if ($request->server->has($this->userKey)) { + $user = $request->server->get($this->userKey); + } elseif ($request->server->has($this->credentialKey) && preg_match('#/emailAddress=(.+\@.+\..+)(/|$)#', $request->server->get($this->credentialKey), $matches)) { + $user = $matches[1]; } - return array($request->server->get($this->userKey), $request->server->get($this->credentialKey, '')); + if (null === $user) { + throw new BadCredentialsException(sprintf('SSL credentials not found: %s, %s', $this->userKey, $this->credentialKey)); + } + + return array($user, $request->server->get($this->credentialKey, '')); } } diff --git a/Http/Tests/Firewall/X509AuthenticationListenerTest.php b/Http/Tests/Firewall/X509AuthenticationListenerTest.php index 7725f4b..7eefb30 100644 --- a/Http/Tests/Firewall/X509AuthenticationListenerTest.php +++ b/Http/Tests/Firewall/X509AuthenticationListenerTest.php @@ -35,11 +35,7 @@ class X509AuthenticationListenerTest extends \PHPUnit_Framework_TestCase $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'); - $listener = new X509AuthenticationListener( - $context, - $authenticationManager, - 'TheProviderKey' - ); + $listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey'); $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); $method->setAccessible(true); @@ -57,9 +53,38 @@ class X509AuthenticationListenerTest extends \PHPUnit_Framework_TestCase } /** + * @dataProvider dataProviderGetPreAuthenticatedDataNoUser + */ + public function testGetPreAuthenticatedDataNoUser($emailAddress) + { + $credentials = 'CN=Sample certificate DN/emailAddress='.$emailAddress; + $request = new Request(array(), array(), array(), array(), array(), array('SSL_CLIENT_S_DN' => $credentials)); + + $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); + + $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'); + + $listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey'); + + $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); + $method->setAccessible(true); + + $result = $method->invokeArgs($listener, array($request)); + $this->assertSame($result, array($emailAddress, $credentials)); + } + + public static function dataProviderGetPreAuthenticatedDataNoUser() + { + return array( + 'basicEmailAddress' => array('cert@example.com'), + 'emailAddressWithPlusSign' => array('cert+something@example.com'), + ); + } + + /** * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException */ - public function testGetPreAuthenticatedDataNoUser() + public function testGetPreAuthenticatedDataNoData() { $request = new Request(array(), array(), array(), array(), array(), array()); @@ -67,11 +92,7 @@ class X509AuthenticationListenerTest extends \PHPUnit_Framework_TestCase $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'); - $listener = new X509AuthenticationListener( - $context, - $authenticationManager, - 'TheProviderKey' - ); + $listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey'); $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); $method->setAccessible(true); @@ -91,13 +112,7 @@ class X509AuthenticationListenerTest extends \PHPUnit_Framework_TestCase $authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface'); - $listener = new X509AuthenticationListener( - $context, - $authenticationManager, - 'TheProviderKey', - 'TheUserKey', - 'TheCredentialsKey' - ); + $listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey', 'TheUserKey', 'TheCredentialsKey'); $method = new \ReflectionMethod($listener, 'getPreAuthenticatedData'); $method->setAccessible(true); |