-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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?