Add authorizationCustomizer pattern for OAuth2Authorization customization#2294
Open
nikitanagar08 wants to merge 1 commit intospring-projects:mainfrom
Open
Add authorizationCustomizer pattern for OAuth2Authorization customization#2294nikitanagar08 wants to merge 1 commit intospring-projects:mainfrom
nikitanagar08 wants to merge 1 commit intospring-projects:mainfrom
Conversation
2f9b48a to
6d2ecda
Compare
Replaced the narrow OAuth2AuthorizedScopesMapper with a more general authorizationCustomizer pattern as requested by @jgrandja. Changes: - Deleted OAuth2AuthorizedScopesMapper and OAuth2AuthorizedScopesContext - Added authorizationCustomizer field and setter to: * OAuth2AuthorizationCodeRequestAuthenticationProvider * OAuth2AuthorizationConsentAuthenticationProvider * OAuth2ClientCredentialsAuthenticationProvider - Added getAuthorizationBuilder() method to authentication contexts - Customizer receives context with OAuth2Authorization.Builder for flexible customization of scopes, attributes, metadata, etc. - Updated tests for all three providers This allows broader use cases beyond scope filtering: - Role-based scope transformation - Adding custom metadata to authorization - Integrating with external authz servers - Any other authorization customization needs Fixes spring-projectsgh-1504 Signed-off-by: Nikita Nagar <permanayan84@gmail.com>
2bbde2d to
517ed1e
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Based on maintainer feedback from @jgrandja, this PR replaces the narrow
OAuth2AuthorizedScopesMapperwith a more general authorizationCustomizer pattern.The new design uses
Consumer<OAuth2XXX_AuthenticationContext>to customize theOAuth2Authorization.Builderbefore building, providing:Changes
Authentication Providers Updated
OAuth2AuthorizationCodeRequestAuthenticationProvider
setAuthorizationCustomizer(Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext>)OAuth2AuthorizationConsentAuthenticationProvider
setAuthorizationCustomizer(Consumer<OAuth2AuthorizationConsentAuthenticationContext>)OAuth2ClientCredentialsAuthenticationProvider
setAuthorizedScopesMapper()withsetAuthorizationCustomizer()Context Enhancements
Added
getAuthorizationBuilder()andauthorizationBuilder()methods to:OAuth2AuthorizationCodeRequestAuthenticationContextOAuth2AuthorizationConsentAuthenticationContextOAuth2ClientCredentialsAuthenticationContextFiles Changed
Deleted:
OAuth2AuthorizedScopesMapper.java(narrow scope)OAuth2AuthorizedScopesContext.java(narrow scope)Modified:
Usage Example
Motivation
This addresses issue #1504 by providing a general-purpose extension point for customizing
OAuth2Authorizationbefore persistence, enabling use cases such as:Test plan
setAuthorizationCustomizerWhenNullThenThrowIllegalArgumentException- verifies null checkauthenticateWhenCustomAuthorizationCustomizerThenUsed- verifies customizer is invokedFixes gh-1504
Signed-off-by: Nikita Nagar permanayan84@gmail.com