Class AuthenticationPrincipalArgumentResolver
java.lang.Object
org.springframework.graphql.data.method.annotation.support.AuthenticationPrincipalArgumentResolver
- All Implemented Interfaces:
HandlerMethodArgumentResolver
public class AuthenticationPrincipalArgumentResolver
extends Object
implements HandlerMethodArgumentResolver
Resolver to obtain
Authentication.getPrincipal()
from Spring Security
context via SecurityContext.getAuthentication()
for parameters
annotated with AuthenticationPrincipal
.
The resolver checks both ThreadLocal context via SecurityContextHolder
for Spring MVC applications, and ReactiveSecurityContextHolder
for
Spring WebFlux applications.
- Since:
- 1.0.0
- Author:
- Rob Winch
-
Constructor Summary
ConstructorDescriptionAuthenticationPrincipalArgumentResolver
(BeanResolver beanResolver) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionresolveArgument
(MethodParameter parameter, DataFetchingEnvironment environment) Resolve a method parameter to a value.boolean
supportsParameter
(MethodParameter parameter) Whether this resolver supports the givenMethodParameter
.
-
Constructor Details
-
AuthenticationPrincipalArgumentResolver
Creates a new instance.- Parameters:
beanResolver
- theBeanResolver
used for resolving beans in SpEL expressions. Cannot be null.
-
-
Method Details
-
supportsParameter
Description copied from interface:HandlerMethodArgumentResolver
Whether this resolver supports the givenMethodParameter
.- Specified by:
supportsParameter
in interfaceHandlerMethodArgumentResolver
-
resolveArgument
public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) throws Exception Description copied from interface:HandlerMethodArgumentResolver
Resolve a method parameter to a value.- Specified by:
resolveArgument
in interfaceHandlerMethodArgumentResolver
- Parameters:
parameter
- the method parameter to resolve. This parameter must have previously checked viaHandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter)
.environment
- the environment to use to resolve the value- Returns:
- the resolved value, which may be
null
if not resolved; the value may also be aMono
if it requires asynchronous resolution. - Throws:
Exception
- in case of errors with the preparation of argument values
-