Skip to content

Commit 6335193

Browse files
committed
feature #218 Drop support for Symfony < 6.4 (ajgarlag)
This PR was merged into the 0.10-dev branch. Discussion ---------- Drop support for Symfony < 6.4 It also removes the related BC layer Commits ------- 4a77ebc Drop Symfony < 6.4 support
2 parents 8d522b2 + 4a77ebc commit 6335193

File tree

18 files changed

+72
-147
lines changed

18 files changed

+72
-147
lines changed

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
php: ['8.1', '8.2', '8.3', '8.4']
18-
symfony: ['5.4.*', '6.4.*', '7.1.*', '7.2.*']
18+
symfony: ['6.4.*', '7.1.*', '7.2.*']
1919
doctrine-orm: ['^2.14', '^3.0']
2020
composer-flags: ['--prefer-stable']
2121
can-fail: [false]
2222
include:
2323
- php: "8.1"
24-
symfony: "5.4.*"
24+
symfony: "6.4.*"
2525
doctrine-orm: "^2.14"
2626
composer-flags: '--prefer-stable --prefer-lowest'
2727
can-fail: false

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
"league/oauth2-server": "^9.2",
2424
"nyholm/psr7": "^1.4",
2525
"psr/http-factory": "^1.0",
26-
"symfony/event-dispatcher": "^5.4|^6.2|^7.0",
27-
"symfony/filesystem": "^5.4|^6.0|^7.0",
28-
"symfony/framework-bundle": "^5.4|^6.2|^7.0",
26+
"symfony/event-dispatcher": "^6.4|^7.0",
27+
"symfony/filesystem": "^6.4|^7.0",
28+
"symfony/framework-bundle": "^6.4|^7.0",
2929
"symfony/polyfill-php81": "^1.22",
30-
"symfony/psr-http-message-bridge": "^2.0|^6|^7",
31-
"symfony/security-bundle": "^5.4|^6.2|^7.0"
30+
"symfony/psr-http-message-bridge": "^6.4|^7",
31+
"symfony/security-bundle": "^6.4|^7.0"
3232
},
3333
"require-dev": {
3434
"ext-pdo": "*",
3535
"ext-pdo_sqlite": "*",
36-
"symfony/browser-kit": "^5.4|^6.2|^7.0",
37-
"symfony/phpunit-bridge": "^5.4|^6.2|^7.0"
36+
"symfony/browser-kit": "^6.4|^7.0",
37+
"symfony/phpunit-bridge": "^7.2"
3838
},
3939
"autoload": {
4040
"psr-4": { "League\\Bundle\\OAuth2ServerBundle\\": "src/" }

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For implementation into Symfony projects, please see [bundle documentation](basi
1313
## Requirements
1414

1515
* [PHP 8.1](http://php.net/releases/8_1_0.php) or greater
16-
* [Symfony 5.4](https://symfony.com/roadmap/5.4) or greater
16+
* [Symfony 6.4](https://symfony.com/roadmap/6.4) or greater
1717

1818
## Installation
1919

src/Converter/UserConverter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ final class UserConverter implements UserConverterInterface
1212
{
1313
/**
1414
* @psalm-suppress ArgumentTypeCoercion
15-
* @psalm-suppress DeprecatedMethod
1615
* @psalm-suppress UndefinedInterfaceMethod
1716
*/
1817
public function toLeague(UserInterface $user): UserEntityInterface
1918
{
2019
$userEntity = new User();
2120

22-
$identifier = method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername();
23-
24-
$userEntity->setIdentifier($identifier);
21+
$userEntity->setIdentifier($user->getUserIdentifier());
2522

2623
return $userEntity;
2724
}

src/DependencyInjection/Security/OAuth2Factory.php

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,53 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\DependencyInjection\Security;
66

7+
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator;
78
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
8-
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
9-
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
10-
11-
if (interface_exists(SecurityFactoryInterface::class) && !interface_exists(AuthenticatorFactoryInterface::class)) {
12-
/**
13-
* Wires the "oauth" authenticator from user configuration.
14-
*
15-
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
16-
*/
17-
class OAuth2Factory implements SecurityFactoryInterface
9+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
10+
use Symfony\Component\DependencyInjection\ChildDefinition;
11+
use Symfony\Component\DependencyInjection\ContainerBuilder;
12+
use Symfony\Component\DependencyInjection\Reference;
13+
14+
/**
15+
* Wires the "oauth" authenticator from user configuration.
16+
*
17+
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
18+
*/
19+
class OAuth2Factory implements AuthenticatorFactoryInterface
20+
{
21+
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array
22+
{
23+
throw new \LogicException('OAuth2 is not supported when "security.enable_authenticator_manager" is not set to true.');
24+
}
25+
26+
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
1827
{
19-
use OAuth2FactoryTrait;
28+
$authenticator = \sprintf('security.authenticator.oauth2.%s', $firewallName);
29+
30+
$definition = new ChildDefinition(OAuth2Authenticator::class);
31+
$definition->replaceArgument(2, new Reference($userProviderId));
32+
33+
$container->setDefinition($authenticator, $definition);
34+
35+
return $authenticator;
2036
}
21-
} elseif (!method_exists(SecurityExtension::class, 'addAuthenticatorFactory')) {
22-
/**
23-
* Wires the "oauth" authenticator from user configuration.
24-
*
25-
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
26-
*/
27-
class OAuth2Factory implements AuthenticatorFactoryInterface, SecurityFactoryInterface
37+
38+
public function getPosition(): string
2839
{
29-
use OAuth2FactoryTrait;
40+
return 'pre_auth';
3041
}
31-
} else {
32-
/**
33-
* Wires the "oauth" authenticator from user configuration.
34-
*
35-
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
36-
*/
37-
class OAuth2Factory implements AuthenticatorFactoryInterface
42+
43+
public function getPriority(): int
44+
{
45+
return -10;
46+
}
47+
48+
public function getKey(): string
49+
{
50+
return 'oauth2';
51+
}
52+
53+
public function addConfiguration(NodeDefinition $builder): void
3854
{
39-
use OAuth2FactoryTrait;
4055
}
4156
}

src/Event/AuthorizationRequestResolveEventFactory.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,15 @@
77
use League\Bundle\OAuth2ServerBundle\Converter\ScopeConverterInterface;
88
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
99
use Symfony\Bundle\SecurityBundle\Security;
10-
use Symfony\Component\Security\Core\Security as LegacySecurity;
1110

12-
if (class_exists(Security::class)) {
13-
final class AuthorizationRequestResolveEventFactory
14-
{
15-
use AuthorizationRequestResolveEventFactoryTrait;
11+
final class AuthorizationRequestResolveEventFactory
12+
{
13+
use AuthorizationRequestResolveEventFactoryTrait;
1614

17-
public function __construct(ScopeConverterInterface $scopeConverter, ClientManagerInterface $clientManager, Security $security)
18-
{
19-
$this->scopeConverter = $scopeConverter;
20-
$this->clientManager = $clientManager;
21-
$this->security = $security;
22-
}
23-
}
24-
} else {
25-
final class AuthorizationRequestResolveEventFactory
15+
public function __construct(ScopeConverterInterface $scopeConverter, ClientManagerInterface $clientManager, Security $security)
2616
{
27-
use AuthorizationRequestResolveEventFactoryTrait;
28-
29-
public function __construct(ScopeConverterInterface $scopeConverter, ClientManagerInterface $clientManager, LegacySecurity $security)
30-
{
31-
$this->scopeConverter = $scopeConverter;
32-
$this->clientManager = $clientManager;
33-
$this->security = $security;
34-
}
17+
$this->scopeConverter = $scopeConverter;
18+
$this->clientManager = $clientManager;
19+
$this->security = $security;
3520
}
3621
}

src/LeagueOAuth2ServerBundle.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,7 @@ private function configureSecurityExtension(ContainerBuilder $container): void
4141
/** @var SecurityExtension $extension */
4242
$extension = $container->getExtension('security');
4343

44-
if (method_exists($extension, 'addAuthenticatorFactory')) {
45-
$extension->addAuthenticatorFactory(new OAuth2Factory());
46-
47-
return;
48-
}
49-
50-
/**
51-
* @psalm-suppress DeprecatedMethod
52-
* @psalm-suppress InvalidArgument
53-
*/
54-
$extension->addSecurityListenerFactory(new OAuth2Factory());
44+
$extension->addAuthenticatorFactory(new OAuth2Factory());
5545
}
5646

5747
private function configureDoctrineExtension(ContainerBuilder $container): void

src/Resources/config/services.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
5959
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
6060
use Symfony\Component\HttpFoundation\RequestStack;
61-
use Symfony\Component\Security\Core\Security as LegacySecurity;
6261

6362
return static function (ContainerConfigurator $container): void {
6463
$container->services()
@@ -281,7 +280,7 @@
281280
->args([
282281
service(ScopeConverterInterface::class),
283282
service(ClientManagerInterface::class),
284-
service(class_exists(Security::class) ? Security::class : LegacySecurity::class),
283+
service(Security::class),
285284
])
286285
->alias(AuthorizationRequestResolveEventFactory::class, 'league.oauth2_server.factory.authorization_request_resolve_event')
287286

src/Security/Authenticator/OAuth2Authenticator.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,6 @@ public function doAuthenticate(Request $request) /* : Passport */
9191
if ('' === $userIdentifier || $oauthClientId === $userIdentifier) {
9292
return new ClientCredentialsUser($oauthClientId);
9393
}
94-
if (!method_exists($this->userProvider, 'loadUserByIdentifier')) {
95-
/**
96-
* @psalm-suppress DeprecatedMethod
97-
* @psalm-suppress MixedReturnStatement
98-
*/
99-
return $this->userProvider->loadUserByUsername($userIdentifier);
100-
}
10194

10295
return $this->userProvider->loadUserByIdentifier($userIdentifier);
10396
};
@@ -150,17 +143,7 @@ public function createToken(Passport $passport, string $firewallName): TokenInte
150143
/** @var string $oauthClientId */
151144
$oauthClientId = $passport->getAttribute('oauthClientId', '');
152145

153-
$token = new OAuth2Token($passport->getUser(), $accessTokenId, $oauthClientId, $scopeBadge->getScopes(), $this->rolePrefix);
154-
if (method_exists(AuthenticatorInterface::class, 'createAuthenticatedToken') && !method_exists(AuthenticatorInterface::class, 'createToken')) {
155-
// symfony 5.4 only
156-
/**
157-
* @psalm-suppress TooManyArguments
158-
* @psalm-suppress UndefinedMethod
159-
*/
160-
$token->setAuthenticated(true, false);
161-
}
162-
163-
return $token;
146+
return new OAuth2Token($passport->getUser(), $accessTokenId, $oauthClientId, $scopeBadge->getScopes(), $this->rolePrefix);
164147
}
165148

166149
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response

src/Security/User/ClientCredentialsUser.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,11 @@ public function __construct(string $clientId)
2323
$this->clientId = $clientId;
2424
}
2525

26-
/**
27-
* @psalm-mutation-free
28-
*/
29-
public function getUsername(): string
30-
{
31-
return $this->getUserIdentifier();
32-
}
33-
3426
public function getUserIdentifier(): string
3527
{
3628
return $this->clientId;
3729
}
3830

39-
/**
40-
* @psalm-mutation-free
41-
*/
42-
public function getPassword(): ?string
43-
{
44-
return null;
45-
}
46-
47-
/**
48-
* @psalm-mutation-free
49-
*/
50-
public function getSalt(): ?string
51-
{
52-
return null;
53-
}
54-
5531
/**
5632
* @psalm-mutation-free
5733
*/

src/Service/CredentialsRevoker/DoctrineCredentialsRevoker.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ public function __construct(EntityManagerInterface $entityManager, ClientManager
3232
}
3333

3434
/**
35-
* @psalm-suppress DeprecatedMethod
3635
* @psalm-suppress UndefinedInterfaceMethod
3736
*/
3837
public function revokeCredentialsForUser(UserInterface $user): void
3938
{
4039
/**
4140
* @psalm-suppress MixedAssignment
4241
*/
43-
$userIdentifier = method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername();
42+
$userIdentifier = $user->getUserIdentifier();
4443

4544
$this->entityManager->createQueryBuilder()
4645
->update(AccessToken::class, 'at')

tests/Acceptance/AuthorizationEndpointTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function setUp(): void
3434
private function loginUser(string $username = FixtureFactory::FIXTURE_USER, string $firewallContext = 'authorization'): void
3535
{
3636
$userProvider = static::getContainer()->get('security.user_providers');
37-
$user = method_exists($userProvider, 'loadUserByIdentifier') ? $userProvider->loadUserByIdentifier($username) : $userProvider->loadUserByUsername($username);
37+
$user = $userProvider->loadUserByIdentifier($username);
3838
$this->client->loginUser($user, $firewallContext);
3939
}
4040

tests/Acceptance/SecurityLayerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testAuthenticatedGuestRequest(): void
4141
$response = $this->client->getResponse();
4242

4343
$this->assertSame(200, $response->getStatusCode());
44-
$this->assertSame('Hello, guest', $response->getContent());
44+
$this->assertSame('Hello, foo', $response->getContent());
4545
}
4646

4747
public function testAuthenticatedGuestScopedRequest(): void

tests/Fixtures/SecurityTestController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\Tests\Fixtures;
66

7-
use League\Bundle\OAuth2ServerBundle\Security\User\ClientCredentialsUser;
87
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
98
use Symfony\Component\HttpFoundation\Response;
109
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
@@ -28,7 +27,7 @@ public function helloAction(): Response
2827
$user = $this->getUser();
2928

3029
return new Response(
31-
\sprintf('Hello, %s', null === $user || $user instanceof ClientCredentialsUser ? 'guest' : (method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername()))
30+
\sprintf('Hello, %s', null === $user || $user instanceof ClientCredentialsUser ? 'guest' : $user->getUserIdentifier())
3231
);
3332
}
3433

tests/Fixtures/User.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ public function getSalt(): ?string
2323
return null;
2424
}
2525

26-
public function getUsername(): string
27-
{
28-
return $this->getUserIdentifier();
29-
}
30-
3126
public function getUserIdentifier(): string
3227
{
3328
return FixtureFactory::FIXTURE_USER;

tests/TestKernel.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use League\Bundle\OAuth2ServerBundle\Tests\Fixtures\FakeRefreshTokenManager;
2020
use League\Bundle\OAuth2ServerBundle\Tests\Fixtures\FixtureFactory;
2121
use League\Bundle\OAuth2ServerBundle\Tests\Fixtures\SecurityTestController;
22-
use Symfony\Bundle\SecurityBundle\Security;
2322
use Symfony\Component\Config\Loader\LoaderInterface;
2423
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
2524
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -147,15 +146,11 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
147146
'access_control' => [
148147
[
149148
'path' => '^/authorize',
150-
'roles' => class_exists(Security::class) ? 'IS_AUTHENTICATED' : 'IS_AUTHENTICATED_REMEMBERED',
149+
'roles' => 'IS_AUTHENTICATED',
151150
],
152151
],
153152
];
154153

155-
if (!class_exists(Security::class)) {
156-
$security['enable_authenticator_manager'] = true;
157-
}
158-
159154
$container->loadFromExtension('security', $security);
160155

161156
$container->loadFromExtension('league_oauth2_server', [

0 commit comments

Comments
 (0)