[Security][SecurityBundle] Add access_token.default_roles option that allows overwriting user's default roles
#62373
+749
−21
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.
This pull request allows to overwrite the default roles provided to a user as part of the Access Token Authentication regardless of the token handler used (currently
cas,oauth2,oidc, andoidc_user_info).Thanks to the addition of the
access_token.default_rolesoption, a developer will be able to quickly customize these roles without complexity:In this example, we could allow a GitLab CI/CD pipeline to access the application in order to do specific tasks.
My apologies for the size of this pull request but I think it was necessary to handle this feature for all protocols (and not one after another). Besides, I did not find a way to enforce properly the
access_token.default_rolesonly for specific protocols.Important changes
TokenHandlerFactoryInterface$defaultRolesargument was added to thecreatemethod.AccessTokenFactorycreateTokenHandlermethod had an unused$userProviderId.I replaced it by an optional
$defaultRolesone.CompleteConfigurationTestCaseI skipped the tests for this format.
CasUserAccessTokenAuthenticator::authenticatemethod to return a passport holding a user containing the default roles in the case of the CAS protocol.This class could be a breaking change since the
Cas2Handlerreturns a differentUserBadgefrom this point forward.The opened pull request #59951 will conflict with this one.
Cas2HandlerTestCasUseris not known yet by Symfony.Let me know if I need to remove the
markTestSkippedcalls.Also, I modified the
testWithValidTicketmethod because comparing (assertEquals) two objects containing a closure seems to not be possible with PHP.I am open for an explanation for this one.
Questions
AccessTokenAuthenticatorTestfile?Cas2Handlerservice registration from the factory to thesecurity_authenticator_access_token.phpconfiguration file as it was done for the others protocols?