Skip to content

Commit a8d074b

Browse files
committed
Fix compatibility of ldap 6.0 with security 5.x
1 parent 5a2d322 commit a8d074b

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

Security/LdapAuthenticator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
1919
use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface;
2020
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
21+
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
2122
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
2223
use Symfony\Component\Security\Http\EntryPoint\Exception\NotAnEntryPointException;
2324

@@ -64,6 +65,14 @@ public function authenticate(Request $request): Passport
6465
return $passport;
6566
}
6667

68+
/**
69+
* @internal
70+
*/
71+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
72+
{
73+
throw new \BadMethodCallException(sprintf('The "%s()" method cannot be called.', __METHOD__));
74+
}
75+
6776
public function createToken(Passport $passport, string $firewallName): TokenInterface
6877
{
6978
return $this->authenticator->createToken($passport, $firewallName);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Ldap\Tests\Security;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\Ldap\Security\LdapAuthenticator;
17+
use Symfony\Component\Ldap\Security\LdapBadge;
18+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
19+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
20+
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
21+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
22+
23+
class LdapAuthenticatorTest extends TestCase
24+
{
25+
public function testAuthenticate()
26+
{
27+
$decorated = $this->createMock(AuthenticatorInterface::class);
28+
$passport = new Passport(new UserBadge('test'), new PasswordCredentials('s3cret'));
29+
$decorated
30+
->expects($this->once())
31+
->method('authenticate')
32+
->willReturn($passport)
33+
;
34+
35+
$authenticator = new LdapAuthenticator($decorated, 'serviceId');
36+
$request = new Request();
37+
38+
$authenticator->authenticate($request);
39+
40+
/** @var LdapBadge $badge */
41+
$badge = $passport->getBadge(LdapBadge::class);
42+
$this->assertNotNull($badge);
43+
$this->assertSame('serviceId', $badge->getLdapServiceId());
44+
}
45+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"symfony/options-resolver": "^5.4|^6.0"
2222
},
2323
"require-dev": {
24-
"symfony/security-core": "^5.4|^6.0"
24+
"symfony/security-core": "^5.4|^6.0",
25+
"symfony/security-http": "^5.4|^6.0"
2526
},
2627
"conflict": {
2728
"symfony/options-resolver": "<5.4",

0 commit comments

Comments
 (0)