Class AuthenticationPrincipalArgumentResolver
- java.lang.Object
-
- org.springframework.security.web.bind.support.AuthenticationPrincipalArgumentResolver
-
- All Implemented Interfaces:
org.springframework.web.method.support.HandlerMethodArgumentResolver
@Deprecated public final class AuthenticationPrincipalArgumentResolver extends java.lang.Object implements org.springframework.web.method.support.HandlerMethodArgumentResolverDeprecated.UseAuthenticationPrincipalArgumentResolverinstead.Allows resolving theAuthentication.getPrincipal()using theAuthenticationPrincipalannotation. For example, the followingController:@Controller public class MyController { @RequestMapping("/user/current/show") public String show(@AuthenticationPrincipal CustomUser customUser) { // do something with CustomUser return "view"; } }Will resolve the CustomUser argument using
Authentication.getPrincipal()from theSecurityContextHolder. If theAuthenticationorAuthentication.getPrincipal()is null, it will return null. If the types do not match, null will be returned unlessAuthenticationPrincipal.errorOnInvalidType()is true in which case aClassCastExceptionwill be thrown.Alternatively, users can create a custom meta annotation as shown below:
@Target({ ElementType.PARAMETER }) @Retention(RetentionPolicy.RUNTIME) @AuthenticationPrincipal public @interface CurrentUser { }The custom annotation can then be used instead. For example:
@Controller public class MyController { @RequestMapping("/user/current/show") public String show(@CurrentUser CustomUser customUser) { // do something with CustomUser return "view"; } }- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor Description AuthenticationPrincipalArgumentResolver()Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated 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)Deprecated.booleansupportsParameter(org.springframework.core.MethodParameter parameter)Deprecated.
-
-
-
Method Detail
-
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
Deprecated.- 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)Deprecated.- Specified by:
resolveArgumentin interfaceorg.springframework.web.method.support.HandlerMethodArgumentResolver
-
-