-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Require entry_point to be configured with multiple authenticators #36575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
* @author Fabien Potencier <[email protected]> | ||
* @author Lukas Kahwe Smith <[email protected]> | ||
* @author Johannes M. Schmitt <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
abstract class AbstractFactory implements SecurityFactoryInterface | ||
{ | ||
|
@@ -65,7 +67,7 @@ public function create(ContainerBuilder $container, string $id, array $config, s | |
} | ||
|
||
// create entry point if applicable (optional) | ||
$entryPointId = $this->createEntryPoint($container, $id, $config, $defaultEntryPointId); | ||
$entryPointId = $this->createDefaultEntryPoint($container, $id, $config, $defaultEntryPointId); | ||
|
||
return [$authProviderId, $listenerId, $entryPointId]; | ||
} | ||
|
@@ -126,7 +128,7 @@ abstract protected function getListenerId(); | |
* | ||
* @return string|null the entry point id | ||
*/ | ||
protected function createEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPointId) | ||
protected function createDefaultEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPointId) | ||
{ | ||
return $defaultEntryPointId; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
|
||
/** | ||
* @author Wouter de Jong <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class AnonymousFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,12 @@ | |
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* @author Wouter de Jong <[email protected]> | ||
* | ||
* @internal | ||
* @experimental in Symfony 5.1 | ||
*/ | ||
class CustomAuthenticatorFactory implements AuthenticatorFactoryInterface, SecurityFactoryInterface | ||
{ | ||
public function create(ContainerBuilder $container, string $id, array $config, string $userProvider, ?string $defaultEntryPoint) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Johannes M. Schmitt <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class FormLoginFactory extends AbstractFactory implements AuthenticatorFactoryInterface, EntryPointFactoryInterface | ||
{ | ||
|
@@ -90,7 +92,12 @@ protected function createListener(ContainerBuilder $container, string $id, array | |
return $listenerId; | ||
} | ||
|
||
public function createEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPoint): string | ||
protected function createDefaultEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPointId) | ||
{ | ||
return $this->createEntryPoint($container, $id, $config); | ||
} | ||
|
||
public function createEntryPoint(ContainerBuilder $container, string $id, array $config): string | ||
{ | ||
$entryPointId = 'security.authentication.form_entry_point.'.$id; | ||
$container | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
* | ||
* @author Grégoire Pineau <[email protected]> | ||
* @author Charles Sarrazin <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class FormLoginLdapFactory extends FormLoginFactory | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
* Configures the "guard" authentication provider key under a firewall. | ||
* | ||
* @author Ryan Weaver <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class GuardAuthenticationFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface, EntryPointFactoryInterface | ||
{ | ||
|
@@ -111,9 +113,15 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal | |
return $authenticatorIds; | ||
} | ||
|
||
public function createEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPointId): string | ||
public function createEntryPoint(ContainerBuilder $container, string $id, array $config): ?string | ||
{ | ||
return $this->determineEntryPoint($defaultEntryPointId, $config); | ||
try { | ||
return $this->determineEntryPoint(null, $config); | ||
} catch (\LogicException $e) { | ||
// ignore the exception, the new system prefers setting "entry_point" over "guard.entry_point" | ||
} | ||
|
||
return null; | ||
} | ||
wouterj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private function determineEntryPoint(?string $defaultEntryPointId, array $config): string | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,10 @@ | |
* HttpBasicFactory creates services for HTTP basic authentication. | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class HttpBasicFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface | ||
class HttpBasicFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface, EntryPointFactoryInterface | ||
{ | ||
public function create(ContainerBuilder $container, string $id, array $config, string $userProvider, ?string $defaultEntryPoint) | ||
{ | ||
|
@@ -34,7 +36,10 @@ public function create(ContainerBuilder $container, string $id, array $config, s | |
; | ||
|
||
// entry point | ||
$entryPointId = $this->createEntryPoint($container, $id, $config, $defaultEntryPoint); | ||
$entryPointId = $defaultEntryPoint; | ||
if (null === $entryPointId) { | ||
$entryPointId = $this->createEntryPoint($container, $id, $config); | ||
} | ||
|
||
// listener | ||
$listenerId = 'security.authentication.listener.basic.'.$id; | ||
|
@@ -77,12 +82,8 @@ public function addConfiguration(NodeDefinition $node) | |
; | ||
} | ||
|
||
protected function createEntryPoint(ContainerBuilder $container, string $id, array $config, ?string $defaultEntryPoint) | ||
public function createEntryPoint(ContainerBuilder $container, string $id, array $config): string | ||
{ | ||
if (null !== $defaultEntryPoint) { | ||
return $defaultEntryPoint; | ||
} | ||
|
||
$entryPointId = 'security.authentication.basic_entry_point.'.$id; | ||
$container | ||
->setDefinition($entryPointId, new ChildDefinition('security.authentication.basic_entry_point')) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
* @author Fabien Potencier <[email protected]> | ||
* @author Grégoire Pineau <[email protected]> | ||
* @author Charles Sarrazin <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class HttpBasicLdapFactory extends HttpBasicFactory | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
* JsonLoginFactory creates services for JSON login authentication. | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class JsonLoginFactory extends AbstractFactory implements AuthenticatorFactoryInterface | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
* @author Maxime Douailin <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class RemoteUserFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
* X509Factory creates services for X509 certificate authentication. | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class X509Factory implements SecurityFactoryInterface, AuthenticatorFactoryInterface | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the BC break that makes my code fail now.
AbstractFactory
is what we use in Connect Bundle: https://github.com/symfonycorp/connect-bundle/blob/master/src/DependencyInjection/Security/Factory/ConnectFactory.php/cc @wouterj
So, even if I can probably fix it in Connect, I fear that we won't be alone by this problem. Anyone not using Guard is probably extending
AbstractFactory
. That means that we cannot markAbstractFactory
as@internal
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for debugging!
That also means we have to find another method name for the
EntryPointInterface
interface, to not conflict with the abstract method in this class.I'll do a PR later this evening.See #36661