AuthenticationPrincipalArgumentResolver not used when argument class implements Principal #4151
Labels
for: external-project
For an external project and not something we can fix
type: enhancement
A general enhancement
Uh oh!
There was an error while loading. Please reload this page.
Summary
putting an @AuthenticationPrincipal annotation on a Controller parameter, where the parameter's type implements Principal causes the servlet to throw an IllegalArgumentException
Actual Behavior
Basically, since ServletRequestMethodArgumentResolver supports Principal objects, it gets used, and it populates the parameter with an Authentication object, causeing a casting exception when the resolving AuthenticationObject is forced into my UserDetails object
Expected Behavior
AuthenticationPrincipalArgumentResolver should be defaulted to resolve AuthenticationPrincipal arguments, which will do the correct resolution.
The workaround is not having my UserDetails object inherit Principal, or use the actual UserDetails class in the parameter, and then cast it to my subclass, but this is silly. It makes perfect sense that a UserDetails object is also a Princial, and it is in fact retrieved via Authentication Principal
Fix
The fix would be forcing ServletRequestMethodArgumentResolver to be lower priority in argument resolution than AuthenticationPrincipalArgumentResolver
Version
All
The text was updated successfully, but these errors were encountered: