@AuthenticationPrincipal
resolver should have precedence over Principal
resolver
#982
Labels
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Hello!
I'm using
spring-graphql
1.2.6 in aspring-boot
3.1.11 app withspring-boot-starter-web
(MVC implementation).I have
@Controller
with a simple@QueryMapping
that fetches data of the logged user.My principal looks like :
Calling
user
query fails to correctly resolves the principal and results in an argument type mismatch error :According to documentation, this annotation should work right out of the box. The problem is that it resolves the
Authentication
object (which in my case is of typeUsernamePasswordAuthenticationToken
) instead of the actualPrincipal
.For instance, this works perfectly :
After some investigations, it seems that the
PrincipalMethodArgumentResolver
is not working as expected :spring-graphql/spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/PrincipalMethodArgumentResolver.java
Line 56 in da473ca
The method
resolveArgument()
returns the resolvedAuthentication
byresolveAuthentication()
method and should instead returns thePrincipal
(something likeAuthentication#getPrincipal()
)PS : Since the
AnnotatedControllerConfigurer
registers the two resolversPrincipalMethodArgumentResolver
andAuthenticationPrincipalArgumentResolver
in this order, and myGraphQlPrincipal
implementsjava.security.Principal
, the first resolver is picked and fails. Removing the implementation ofjava.security.Principal
results in a successful resolution through the second resolverAuthenticationPrincipalArgumentResolver
.Thanks.
The text was updated successfully, but these errors were encountered: