Skip to content

Commit 456031a

Browse files
committed
Merge branch '2.3' into 2.4
* 2.3: fix docblock Fixed incompatibility of x509 auth with nginx [Process] Setting STDIN while running should not be possible [FrameworkBundle] improve English in RouterMatchCommand [Doctrine Bridge] simplify session handler by using main connection Conflicts: src/Symfony/Component/Process/Tests/AbstractProcessTest.php
2 parents 9734953 + 690573b commit 456031a

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

Firewall/X509AuthenticationListener.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ public function __construct(SecurityContextInterface $securityContext, Authentic
4141
*/
4242
protected function getPreAuthenticatedData(Request $request)
4343
{
44-
if (!$request->server->has($this->userKey)) {
45-
throw new BadCredentialsException(sprintf('SSL key was not found: %s', $this->userKey));
44+
$user = null;
45+
if ($request->server->has($this->userKey)) {
46+
$user = $request->server->get($this->userKey);
47+
} elseif ($request->server->has($this->credentialKey) && preg_match('#/emailAddress=(.+\@.+\..+)(/|$)#', $request->server->get($this->credentialKey), $matches)) {
48+
$user = $matches[1];
4649
}
4750

48-
return array($request->server->get($this->userKey), $request->server->get($this->credentialKey, ''));
51+
if (null === $user) {
52+
throw new BadCredentialsException(sprintf('SSL credentials not found: %s, %s', $this->userKey, $this->credentialKey));
53+
}
54+
55+
return array($user, $request->server->get($this->credentialKey, ''));
4956
}
5057
}

Tests/Firewall/X509AuthenticationListenerTest.php

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ public function testGetPreAuthenticatedData($user, $credentials)
3535

3636
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
3737

38-
$listener = new X509AuthenticationListener(
39-
$context,
40-
$authenticationManager,
41-
'TheProviderKey'
42-
);
38+
$listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey');
4339

4440
$method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
4541
$method->setAccessible(true);
@@ -56,22 +52,47 @@ public static function dataProviderGetPreAuthenticatedData()
5652
);
5753
}
5854

55+
/**
56+
* @dataProvider dataProviderGetPreAuthenticatedDataNoUser
57+
*/
58+
public function testGetPreAuthenticatedDataNoUser($emailAddress)
59+
{
60+
$credentials = 'CN=Sample certificate DN/emailAddress='.$emailAddress;
61+
$request = new Request(array(), array(), array(), array(), array(), array('SSL_CLIENT_S_DN' => $credentials));
62+
63+
$context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
64+
65+
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
66+
67+
$listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey');
68+
69+
$method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
70+
$method->setAccessible(true);
71+
72+
$result = $method->invokeArgs($listener, array($request));
73+
$this->assertSame($result, array($emailAddress, $credentials));
74+
}
75+
76+
public static function dataProviderGetPreAuthenticatedDataNoUser()
77+
{
78+
return array(
79+
'basicEmailAddress' => array('cert@example.com'),
80+
'emailAddressWithPlusSign' => array('cert+something@example.com'),
81+
);
82+
}
83+
5984
/**
6085
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
6186
*/
62-
public function testGetPreAuthenticatedDataNoUser()
87+
public function testGetPreAuthenticatedDataNoData()
6388
{
6489
$request = new Request(array(), array(), array(), array(), array(), array());
6590

6691
$context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
6792

6893
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
6994

70-
$listener = new X509AuthenticationListener(
71-
$context,
72-
$authenticationManager,
73-
'TheProviderKey'
74-
);
95+
$listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey');
7596

7697
$method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
7798
$method->setAccessible(true);
@@ -91,13 +112,7 @@ public function testGetPreAuthenticatedDataWithDifferentKeys()
91112

92113
$authenticationManager = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
93114

94-
$listener = new X509AuthenticationListener(
95-
$context,
96-
$authenticationManager,
97-
'TheProviderKey',
98-
'TheUserKey',
99-
'TheCredentialsKey'
100-
);
115+
$listener = new X509AuthenticationListener($context, $authenticationManager, 'TheProviderKey', 'TheUserKey', 'TheCredentialsKey');
101116

102117
$method = new \ReflectionMethod($listener, 'getPreAuthenticatedData');
103118
$method->setAccessible(true);

0 commit comments

Comments
 (0)