@Target(value={PARAMETER,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface AuthenticationPrincipal
Authentication.getPrincipal()
to a method
argument.Modifier and Type | Optional Element and Description |
---|---|
boolean |
errorOnInvalidType
True if a
ClassCastException should be thrown when the current
Authentication.getPrincipal() is the incorrect type. |
String |
expression
If specified will use the provided SpEL expression to resolve the principal.
|
public abstract boolean errorOnInvalidType
ClassCastException
should be thrown when the current
Authentication.getPrincipal()
is the incorrect type. Default is false.public abstract String expression
For example, perhaps the user wants to resolve a CustomUser object that is final and is leveraging a UserDetailsService. This can be handled by returning an object that looks like:
public class CustomUserUserDetails extends User { // ... public CustomUser getCustomUser() { return customUser; } }Then the user can specify an annotation that looks like:
@AuthenticationPrincipal(expression = "customUser")