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
ConstructorsConstructorDescriptionAuthenticationPrincipalArgumentResolver(BeanResolver beanResolver) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionresolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) Resolve a method parameter to a value.booleansupportsParameter(MethodParameter parameter) Whether this resolver supports the givenMethodParameter.
-
Constructor Details
-
AuthenticationPrincipalArgumentResolver
Creates a new instance.- Parameters:
beanResolver- theBeanResolverused for resolving beans in SpEL expressions. Cannot be null.
-
-
Method Details
-
supportsParameter
Description copied from interface:HandlerMethodArgumentResolverWhether this resolver supports the givenMethodParameter.- Specified by:
supportsParameterin interfaceHandlerMethodArgumentResolver
-
resolveArgument
public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) throws Exception Description copied from interface:HandlerMethodArgumentResolverResolve a method parameter to a value.- Specified by:
resolveArgumentin 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
nullif not resolved; the value may also be aMonoif it requires asynchronous resolution. - Throws:
Exception- in case of errors with the preparation of argument values
-