spring-projects / spring-projects/spring-security

Oauth2: add ability to decorate AuthenticationProvider when using OAuth2LoginConfigurer

Open
#17,357 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Expected Behavior

Inside OAuth2LoginConfigurer during init method when postProcess method invoked for OidcAuthorizationCodeAuthenticationProvider do not cast it to OidcAuthorizationCodeAuthenticationProvider but use interface AuthenticationProvider to provide ability to decorate provider inside custom ObjectPostProcessor.

Current Behavior
Inside OAuth2LoginConfigurer during init method when postProcess method invoked for OidcAuthorizationCodeAuthenticationProvider the result object is casted to OidcAuthorizationCodeAuthenticationProvider

Code reference:

OAuth2UserService<OidcUserRequest, OidcUser> oidcUserService = getOidcUserService();
OidcAuthorizationCodeAuthenticationProvider oidcAuthorizationCodeAuthenticationProvider = new OidcAuthorizationCodeAuthenticationProvider(accessTokenResponseClient, oidcUserService);
			.....
oidcAuthorizationCodeAuthenticationProvider = this.postProcess(oidcAuthorizationCodeAuthenticationProvider);
http.authenticationProvider(oidcAuthorizationCodeAuthenticationProvider);

Context

I want to decorate AuthenticationProvider behaviour to invoke some logic before main provider and after.
Alternative is to extend OidcAuthorizationCodeAuthenticationProvider and make a decorator from this class but it looks bad, because i need to inject non null accessTokenResponseClient, oidcUserService parameters (some dummy implementations). Based on code improvement shouldn't be complex.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in OAuth2LoginConfigurer's init method at the ObjectPostProcessor call for OidcAuthorizationCodeAuthenticationProvider. Trace how the resulting AuthenticationProvider is registered with http.authenticationProvider, then verify that a custom ObjectPostProcessor can decorate it without requiring concrete-provider parameters; confirm the relevant OAuth2 login tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authentication, security
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.