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.HandlerMethodArgumentResolverAllows resolving theSecurityContextusing theCurrentSecurityContextannotation. 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
SecurityContextargument usingSecurityContextHolder.getContext()from theSecurityContextHolder. If theSecurityContextisnull, it will returnnull. If the types do not match,nullwill be returned unlessCurrentSecurityContext.errorOnInvalidType()istruein which case aClassCastExceptionwill 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.ObjectresolveArgument(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 expressionsbooleansupportsParameter(org.springframework.core.MethodParameter parameter)
-
-
-
Method Detail
-
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
- Specified by:
supportsParameterin 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:
resolveArgumentin interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver
-
setBeanResolver
public void setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
Set theBeanResolverto be used on the expressions- Parameters:
beanResolver- theBeanResolverto use
-
-