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 Object
implements org.springframework.web.method.support.HandlerMethodArgumentResolver
Allows resolving the
SecurityContext using the CurrentSecurityContext
annotation. For example, the following Controller:
@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 using
SecurityContextHolder.getContext() from the SecurityContextHolder. If
the SecurityContext is null, it will return null. If the types
do not match, null will be returned unless
CurrentSecurityContext.errorOnInvalidType() is true in which case a
ClassCastException will be thrown.
- Since:
- 5.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionresolveArgument(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) voidsetBeanResolver(org.springframework.expression.BeanResolver beanResolver) Set theBeanResolverto be used on the expressionsvoidsetSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use.voidsetTemplateDefaults(AnnotationTemplateExpressionDefaults templateDefaults) Configure CurrentSecurityContext template resolutionbooleansupportsParameter(org.springframework.core.MethodParameter parameter)
-
Constructor Details
-
CurrentSecurityContextArgumentResolver
public CurrentSecurityContextArgumentResolver()
-
-
Method Details
-
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter) - Specified by:
supportsParameterin interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver
-
resolveArgument
public 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:
resolveArgumentin interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver
-
setSecurityContextHolderStrategy
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) Sets theSecurityContextHolderStrategyto use. The default action is to use theSecurityContextHolderStrategystored inSecurityContextHolder.- Since:
- 5.8
-
setBeanResolver
public void setBeanResolver(org.springframework.expression.BeanResolver beanResolver) Set theBeanResolverto be used on the expressions- Parameters:
beanResolver- theBeanResolverto use
-
setTemplateDefaults
Configure CurrentSecurityContext template resolutionBy default, this value is
null, which indicates that templates should not be resolved.- Parameters:
templateDefaults- - whether to resolve CurrentSecurityContext templates parameters- Since:
- 6.4
-