Skip to content

Commit d5bc3f8

Browse files
committed
Drop support for legacy security system
1 parent 5695774 commit d5bc3f8

28 files changed

+232
-917
lines changed

docs/basic-setup.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ Options:
9595
9696
## Configuring the Security layer
9797
98-
Add two new firewalls in your security configuration:
98+
Add two new firewalls in your security configuration and enable the authenticator security system:
9999
100100
```yaml
101101
security:
102+
enable_authenticator_manager: true
103+
102104
firewalls:
103105
api_token:
104106
pattern: ^/api/token$

docs/index.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For implementation into Symfony projects, please see [bundle documentation](docs
1313
## Requirements
1414

1515
* [PHP 7.2](http://php.net/releases/7_2_0.php) or greater
16-
* [Symfony 4.4](https://symfony.com/roadmap/4.4) or [Symfony 5.x](https://symfony.com/roadmap/5.0)
16+
* [Symfony 5.2](https://symfony.com/roadmap/5.2) or greater
1717

1818
## Installation
1919

@@ -91,9 +91,6 @@ For implementation into Symfony projects, please see [bundle documentation](docs
9191
entity_manager: default
9292
in_memory: ~
9393
94-
# The priority of the event listener that converts an Exception to a Response
95-
exception_event_listener_priority: 10
96-
9794
# Set a custom prefix that replaces the default 'ROLE_OAUTH2_' role prefix
9895
role_prefix: ROLE_OAUTH2_
9996
```
@@ -110,6 +107,13 @@ For implementation into Symfony projects, please see [bundle documentation](docs
110107
bin/console doctrine:schema:update --force
111108
```
112109

110+
1. Enable the authenticator security system in `config/security.yaml` file:
111+
112+
```yaml
113+
security:
114+
enable_authenticator_manager: true
115+
```
116+
113117
1. Import the routes inside your `config/routes.yaml` file:
114118

115119
```yaml
@@ -121,7 +125,7 @@ You can verify that everything is working by issuing a `POST` request to the `/t
121125

122126
**❮ NOTE ❯** It is recommended to control the access to the authorization endpoint
123127
so that only logged in users can approve authorization requests.
124-
You should review your `security.yml` file. Here is a sample configuration:
128+
You should review your `config/security.yaml` file. Here is a sample configuration:
125129

126130
```yaml
127131
security:

src/DependencyInjection/Configuration.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ public function getConfigTreeBuilder(): TreeBuilder
2626

2727
$rootNode
2828
->children()
29-
->scalarNode('exception_event_listener_priority')
30-
->info('The priority of the event listener that converts an Exception to a Response')
31-
->defaultValue(10)
32-
->end()
3329
->scalarNode('role_prefix')
3430
->info('Set a custom prefix that replaces the default \'ROLE_OAUTH2_\' role prefix')
3531
->defaultValue('ROLE_OAUTH2_')

src/DependencyInjection/LeagueOAuth2ServerExtension.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
use League\Bundle\OAuth2ServerBundle\DBAL\Type\Grant as GrantType;
1010
use League\Bundle\OAuth2ServerBundle\DBAL\Type\RedirectUri as RedirectUriType;
1111
use League\Bundle\OAuth2ServerBundle\DBAL\Type\Scope as ScopeType;
12-
use League\Bundle\OAuth2ServerBundle\EventListener\ConvertExceptionToResponseListener;
1312
use League\Bundle\OAuth2ServerBundle\League\AuthorizationServer\GrantTypeInterface;
1413
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\AccessTokenManager;
1514
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\AuthorizationCodeManager;
1615
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\ClientManager;
1716
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\RefreshTokenManager;
1817
use League\Bundle\OAuth2ServerBundle\Manager\ScopeManagerInterface;
1918
use League\Bundle\OAuth2ServerBundle\Model\Scope as ScopeModel;
20-
use League\Bundle\OAuth2ServerBundle\Security\Authentication\Token\LegacyOAuth2TokenFactory;
2119
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator;
2220
use League\Bundle\OAuth2ServerBundle\Service\CredentialsRevoker\DoctrineCredentialsRevoker;
2321
use League\OAuth2\Server\AuthorizationServer;
@@ -38,7 +36,6 @@
3836
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
3937
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
4038
use Symfony\Component\DependencyInjection\Reference;
41-
use Symfony\Component\HttpKernel\KernelEvents;
4239

4340
final class LeagueOAuth2ServerExtension extends Extension implements PrependExtensionInterface, CompilerPassInterface
4441
{
@@ -61,19 +58,9 @@ public function load(array $configs, ContainerBuilder $container)
6158
$this->configureResourceServer($container, $config['resource_server']);
6259
$this->configureScopes($container, $config['scopes']);
6360

64-
$container->findDefinition(LegacyOAuth2TokenFactory::class)
65-
->setArgument(0, $config['role_prefix']);
66-
6761
$container->findDefinition(OAuth2Authenticator::class)
6862
->setArgument(3, $config['role_prefix']);
6963

70-
$container->findDefinition(ConvertExceptionToResponseListener::class)
71-
->addTag('kernel.event_listener', [
72-
'event' => KernelEvents::EXCEPTION,
73-
'method' => 'onKernelException',
74-
'priority' => $config['exception_event_listener_priority'],
75-
]);
76-
7764
$container->registerForAutoconfiguration(GrantTypeInterface::class)
7865
->addTag('league.oauth2_server.authorization_server.grant');
7966
}

src/DependencyInjection/Security/OAuth2Factory.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44

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

7-
use League\Bundle\OAuth2ServerBundle\Security\Authentication\Provider\OAuth2Provider;
87
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator;
9-
use League\Bundle\OAuth2ServerBundle\Security\EntryPoint\OAuth2EntryPoint;
10-
use League\Bundle\OAuth2ServerBundle\Security\Firewall\OAuth2Listener;
118
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
129
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
1310
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
1411
use Symfony\Component\DependencyInjection\ChildDefinition;
1512
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Reference;
1713

1814
/**
1915
* @author Mathias Arlaud <[email protected]>
@@ -22,18 +18,7 @@ final class OAuth2Factory implements SecurityFactoryInterface, AuthenticatorFact
2218
{
2319
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array
2420
{
25-
$provider = sprintf('security.authentication.provider.oauth2.%s', $id);
26-
$container
27-
->setDefinition($provider, new ChildDefinition(OAuth2Provider::class))
28-
->replaceArgument(0, new Reference($userProvider))
29-
->replaceArgument(3, $id);
30-
31-
$listener = sprintf('security.authentication.listener.oauth2.%s', $id);
32-
$container
33-
->setDefinition($listener, new ChildDefinition(OAuth2Listener::class))
34-
->replaceArgument(4, $id);
35-
36-
return [$provider, $listener, OAuth2EntryPoint::class];
21+
throw new \LogicException('OAuth2 is not supported when "security.enable_authenticator_manager" is not set to true.');
3722
}
3823

3924
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProvider): string

src/EventListener/ConvertExceptionToResponseListener.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Resources/config/services.php

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use League\Bundle\OAuth2ServerBundle\Converter\UserConverterInterface;
1818
use League\Bundle\OAuth2ServerBundle\Event\AuthorizationRequestResolveEventFactory;
1919
use League\Bundle\OAuth2ServerBundle\EventListener\AuthorizationRequestUserResolvingListener;
20-
use League\Bundle\OAuth2ServerBundle\EventListener\ConvertExceptionToResponseListener;
2120
use League\Bundle\OAuth2ServerBundle\League\AuthorizationServer\GrantConfigurator;
2221
use League\Bundle\OAuth2ServerBundle\League\Repository\AccessTokenRepository;
2322
use League\Bundle\OAuth2ServerBundle\League\Repository\AuthCodeRepository;
@@ -32,12 +31,8 @@
3231
use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface;
3332
use League\Bundle\OAuth2ServerBundle\Manager\ScopeManagerInterface;
3433
use League\Bundle\OAuth2ServerBundle\OAuth2Events;
35-
use League\Bundle\OAuth2ServerBundle\Security\Authentication\Provider\OAuth2Provider;
36-
use League\Bundle\OAuth2ServerBundle\Security\Authentication\Token\LegacyOAuth2TokenFactory;
3734
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator;
38-
use League\Bundle\OAuth2ServerBundle\Security\EntryPoint\OAuth2EntryPoint;
39-
use League\Bundle\OAuth2ServerBundle\Security\EventListener\CheckScopesListener;
40-
use League\Bundle\OAuth2ServerBundle\Security\Firewall\OAuth2Listener;
35+
use League\Bundle\OAuth2ServerBundle\Security\EventListener\CheckScopeListener;
4136
use League\OAuth2\Server\AuthorizationServer;
4237
use League\OAuth2\Server\Grant\AuthCodeGrant;
4338
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
@@ -56,8 +51,7 @@
5651
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
5752
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
5853
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
59-
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
60-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
54+
use Symfony\Component\HttpFoundation\RequestStack;
6155
use Symfony\Component\Security\Core\Security;
6256
use Symfony\Component\Security\Core\User\UserProviderInterface;
6357

@@ -127,31 +121,12 @@
127121
])
128122
->alias(OAuth2Authenticator::class, 'league.oauth2_server.authenticator.oauth2')
129123

130-
->set('league.oauth2_server.listener.check_scopes', CheckScopesListener::class)
131-
->tag('kernel.event_subscriber')
132-
->alias(CheckScopesListener::class, 'league.oauth2_server.listener.check_scopes')
133-
134-
->set('league.oauth2_server.provider.oauth2', OAuth2Provider::class)
135-
->args([
136-
service(UserProviderInterface::class),
137-
service(ResourceServer::class),
138-
service(LegacyOAuth2TokenFactory::class),
139-
null,
140-
])
141-
->alias(OAuth2Provider::class, 'league.oauth2_server.provider.oauth2')
142-
143-
->set('league.oauth2_server.security.entrypoint.oauth2', OAuth2EntryPoint::class)
144-
->alias(OAuth2EntryPoint::class, 'league.oauth2_server.security.entrypoint.oauth2')
145-
146-
->set('league.oauth2_server.security.firewall.oauth2_listener', OAuth2Listener::class)
124+
->set('league.oauth2_server.listener.check_scope', CheckScopeListener::class)
147125
->args([
148-
service(TokenStorageInterface::class),
149-
service(AuthenticationManagerInterface::class),
150-
service('league.oauth2_server.factory.psr_http'),
151-
service(LegacyOAuth2TokenFactory::class),
152-
null,
126+
service(RequestStack::class),
153127
])
154-
->alias(OAuth2Listener::class, 'league.oauth2_server.security.firewall.oauth2_listener')
128+
->tag('kernel.event_subscriber')
129+
->alias(CheckScopeListener::class, 'league.oauth2_server.listener.check_scope')
155130

156131
->set('league.oauth2_server.authorization_server.grant_configurator', GrantConfigurator::class)
157132
->args([
@@ -237,9 +212,6 @@
237212
])
238213
->alias(AuthorizationRequestUserResolvingListener::class, 'league.oauth2_server.listener.authorization_request_user_resolving')
239214

240-
->set('league.oauth2_server.listener.convert_exception_to_response', ConvertExceptionToResponseListener::class)
241-
->alias(ConvertExceptionToResponseListener::class, 'league.oauth2_server.listener.convert_exception_to_response')
242-
243215
// Token controller
244216
->set('league.oauth2_server.controller.token', TokenController::class)
245217
->args([
@@ -305,9 +277,6 @@
305277
])
306278
->alias(AuthorizationRequestResolveEventFactory::class, 'league.oauth2_server.factory.authorization_request_resolve_event')
307279

308-
->set('league.oauth2_server.factory.legacy_oauth2_token', LegacyOAuth2TokenFactory::class)
309-
->alias(LegacyOAuth2TokenFactory::class, 'league.oauth2_server.factory.legacy_oauth2_token')
310-
311280
// Storage managers
312281
->set('league.oauth2_server.manager.in_memory.scope', ScopeManager::class)
313282
->args([

src/Security/Authentication/Provider/OAuth2Provider.php

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)