Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bdbac2c

Browse files
Robert Koperafabpot
Robert Kopera
authored andcommitted
[Security] added support for updated \"distinguished name\" format in x509 authentication
1 parent 0797ef2 commit bdbac2c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ protected function getPreAuthenticatedData(Request $request)
4444
$user = null;
4545
if ($request->server->has($this->userKey)) {
4646
$user = $request->server->get($this->userKey);
47-
} elseif ($request->server->has($this->credentialKey) && preg_match('#/emailAddress=(.+\@.+\..+)(/|$)#', $request->server->get($this->credentialKey), $matches)) {
47+
} elseif (
48+
$request->server->has($this->credentialKey)
49+
&& preg_match('#emailAddress=(.+\@.+\.[^,/]+)($|,|/)#', $request->server->get($this->credentialKey), $matches)
50+
) {
4851
$user = $matches[1];
4952
}
5053

src/Symfony/Component/Security/Http/Tests/Firewall/X509AuthenticationListenerTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ public static function dataProviderGetPreAuthenticatedData()
5656
/**
5757
* @dataProvider dataProviderGetPreAuthenticatedDataNoUser
5858
*/
59-
public function testGetPreAuthenticatedDataNoUser($emailAddress)
59+
public function testGetPreAuthenticatedDataNoUser($emailAddress, $credentials)
6060
{
61-
$credentials = 'CN=Sample certificate DN/emailAddress='.$emailAddress;
6261
$request = new Request([], [], [], [], [], ['SSL_CLIENT_S_DN' => $credentials]);
6362

6463
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
@@ -76,10 +75,12 @@ public function testGetPreAuthenticatedDataNoUser($emailAddress)
7675

7776
public static function dataProviderGetPreAuthenticatedDataNoUser()
7877
{
79-
return [
80-
'basicEmailAddress' => ['[email protected]'],
81-
'emailAddressWithPlusSign' => ['[email protected]'],
82-
];
78+
yield ['[email protected]', 'CN=Sample certificate DN/[email protected]'];
79+
yield ['[email protected]', 'CN=Sample certificate DN/[email protected]'];
80+
yield ['[email protected]', 'CN=Sample certificate DN,[email protected]'];
81+
yield ['[email protected]', 'CN=Sample certificate DN,[email protected]'];
82+
yield ['[email protected]', '[email protected],CN=Sample certificate DN'];
83+
8384
}
8485

8586
/**

0 commit comments

Comments
 (0)