Class CurrentSecurityContextArgumentResolver
- java.lang.Object
-
- org.springframework.security.web.method.annotation.CurrentSecurityContextArgumentResolver
-
- All Implemented Interfaces:
org.springframework.web.method.support.HandlerMethodArgumentResolver
public final class CurrentSecurityContextArgumentResolver extends java.lang.Object implements org.springframework.web.method.support.HandlerMethodArgumentResolver
Allows resolving theSecurityContext
using theCurrentSecurityContext
annotation. For example, the followingController
:@Controller public class MyController { @RequestMapping("/im") public void security(@CurrentSecurityContext SecurityContext context) { // do something with context } }
it can also support the spring SPEL expression to get the value from SecurityContext@Controller public class MyController { @RequestMapping("/im") public void security(@CurrentSecurityContext(expression="authentication") Authentication authentication) { // do something with context } }
Will resolve the
SecurityContext
argument usingSecurityContextHolder.getContext()
from theSecurityContextHolder
. If theSecurityContext
isnull
, it will returnnull
. If the types do not match,null
will be returned unlessCurrentSecurityContext.errorOnInvalidType()
istrue
in which case aClassCastException
will be thrown.- Since:
- 5.2
-
-
Constructor Summary
Constructors Constructor Description CurrentSecurityContextArgumentResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
resolveArgument(org.springframework.core.MethodParameter parameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
void
setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
Set theBeanResolver
to be used on the expressionsvoid
setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
Sets theSecurityContextHolderStrategy
to use.boolean
supportsParameter(org.springframework.core.MethodParameter parameter)
-
-
-
Method Detail
-
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
- Specified by:
supportsParameter
in interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver
-
resolveArgument
public java.lang.Object resolveArgument(org.springframework.core.MethodParameter parameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
- Specified by:
resolveArgument
in interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver
-
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy)
Sets theSecurityContextHolderStrategy
to use. The default action is to use theSecurityContextHolderStrategy
stored inSecurityContextHolder
.- Since:
- 5.8
-
setBeanResolver
public void setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
Set theBeanResolver
to be used on the expressions- Parameters:
beanResolver
- theBeanResolver
to use
-
-