public final class CurrentSecurityContextArgumentResolver
extends java.lang.Object
implements org.springframework.web.method.support.HandlerMethodArgumentResolver
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.
| Constructor and Description |
|---|
CurrentSecurityContextArgumentResolver() |
| Modifier and Type | Method and 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)
resolve the argument to inject into the controller parameter.
|
void |
setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
Sets the
BeanResolver to be used on the expressions |
boolean |
supportsParameter(org.springframework.core.MethodParameter parameter)
check if this argument resolve can support the parameter.
|
public CurrentSecurityContextArgumentResolver()
public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
supportsParameter in interface org.springframework.web.method.support.HandlerMethodArgumentResolverparameter - the method parameter.supportsParameter(org.springframework.core.MethodParameter)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)
throws java.lang.Exception
resolveArgument in interface org.springframework.web.method.support.HandlerMethodArgumentResolverparameter - the method parameter.mavContainer - the model and view container.webRequest - the web request.binderFactory - the web data binder factory.java.lang.ExceptionresolveArgument (org.springframework.core.MethodParameter,
org.springframework.web.method.support.ModelAndViewContainer,
org.springframework.web.context.request.NativeWebRequest,
org.springframework.web.bind.support.WebDataBinderFactory)public void setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
BeanResolver to be used on the expressionsbeanResolver - the BeanResolver to use