Will resolve the CustomUser argument using {@link Authentication#getPrincipal()} from the {@link SecurityContextHolder}. If the {@link Authentication} or {@link Authentication#getPrincipal()} isnull, it will return null. If the types do not match, null will be returned unless {@link AuthenticationPrincipal#errorOnInvalidType()} is true in whichcase a {@link ClassCastException} will 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 { "/im") public void im(@CurrentUser CustomUser customUser) { // do something with CustomUser }@author Rob Winch @since 4.0
|
|