Skip to content

Support custom OAuth2AuthenticatedPrincipal in Jwt-based authentication flow#17191

Merged
jzheaux merged 3 commits intospring-projects:mainfrom
therepanic:gh-6237
Feb 26, 2026
Merged

Support custom OAuth2AuthenticatedPrincipal in Jwt-based authentication flow#17191
jzheaux merged 3 commits intospring-projects:mainfrom
therepanic:gh-6237

Conversation

@therepanic
Copy link
Copy Markdown
Contributor

This PR implements a simpler approach, as suggested by @jzheaux, to support OAuth2AuthenticatedPrincipal injection into JwtAuthenticationToken

Resolves: #6237

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 1, 2025
@therepanic
Copy link
Copy Markdown
Contributor Author

therepanic commented Jun 1, 2025

I think the current solution can't be merged now since at the very least we don't have tests. I would like to hear feedback if I have understood the solution to the current problem correctly.

Also I guess we can't add a constructor to (Jwt jwt, Object principal, Collection<GrantedAuthority> authorities) as written in #32 because we already have a constructor with 3 arguments (Jwt jwt, Collection<? extends GrantedAuthority> authorities, String name). Because of this we have a build failing now.

@jgrandja jgrandja added type: enhancement A general enhancement in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 11, 2025
@jzheaux jzheaux self-assigned this Jun 17, 2025
Copy link
Copy Markdown
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @therepanic! I've left some feedback inline that I hope will also address your question about the new JwtAuthenticationToken constructor.

After you review my comments, if we are agreed, will you also please add tests that confirm the new setter methods work?

Closes spring-projectsgh-6237

Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
- Replace conditional logic with adapter class
- Added tests

Issue spring-projectsgh-6237

Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
Issue spring-projectsgh-6237

Signed-off-by: Josh Cummings <3627351+jzheaux@users.noreply.github.com>
@jzheaux jzheaux enabled auto-merge (rebase) February 26, 2026 19:18
@jzheaux jzheaux added this to the 7.1.0-M3 milestone Feb 26, 2026
@jzheaux
Copy link
Copy Markdown
Contributor

jzheaux commented Feb 26, 2026

Thanks for getting this PR started, @therepanic! I was able to add the needed tests and documentation. It will merge into main once the build completes.

@jzheaux jzheaux merged commit e30d924 into spring-projects:main Feb 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support UserDetailsService components in OAuth2 Resource Server flows

4 participants