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) |
void |
setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
Set the
BeanResolver to be used on the expressions |
boolean |
supportsParameter(org.springframework.core.MethodParameter parameter) |
public CurrentSecurityContextArgumentResolver()
public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
supportsParameter
in interface org.springframework.web.method.support.HandlerMethodArgumentResolver
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)
resolveArgument
in interface org.springframework.web.method.support.HandlerMethodArgumentResolver
public void setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
BeanResolver
to be used on the expressionsbeanResolver
- the BeanResolver
to use