Skip to content
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

Add information about changed behaviour for resolving @AuthenticationPrincipal annotation #26791

Closed
wimdeblauwe opened this issue Apr 12, 2021 · 2 comments
Assignees
Labels
type: documentation A documentation task
Milestone

Comments

@wimdeblauwe
Copy link

I just spend a few hours trying to figure out why my upgrade from Spring Boot 2.3.4 to 2.4.4 was not working.

I am using Keycloak for authentication and my rest controller use this construct:

public ... methodName(@AuthenticationPrincipal KeycloakAuthenticationToken principal) {

This works in Spring Boot 2.3.4, but not in Spring Boot 2.4.4. The reason for this is that in Spring 5.3.1 a bug on ServletRequestMethodArgumentResolver was fixed.

Before the fix, the KeycloakAuthenticationToken was injected in the controller method via the ServletRequestMethodArgumentResolver. After the fix, the injection is supposed to be done by the AuthenticationPrincipalArgumentResolver, but that resolver always taken the principal of the authentication object. It does not check if the authentication object itself is also a principal as in the case of Keycloak.

The workaround is to remove the @AuthenticationPrincipal annotation (which I find a pity, the annotation made it clear that this argument was getting injected by the framework).

Maybe a note can be added to the release notes for this as others(1,2) have also had the issue?

@snicoll snicoll transferred this issue from spring-projects/spring-boot Apr 12, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 12, 2021
@wilkinsona
Copy link
Member

I asked @snicoll to transfer this issue from Boot as, IMO, Boot's release notes isn't the best place to document the change. I think that https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-5.x#spring-mvc would be a better place to mention it.

@rstoyanchev rstoyanchev self-assigned this Apr 14, 2021
@rstoyanchev rstoyanchev added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 14, 2021
@rstoyanchev rstoyanchev added this to the 5.3.7 milestone Apr 14, 2021
@rstoyanchev
Copy link
Contributor

Indeed this should be in the release notes but is missing. I will also see about finding a place in the documentation to mention this as it can be confusing indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

4 participants