Annotation Type AuthenticationPrincipal

    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean errorOnInvalidType
      True if a ClassCastException should be thrown when the current Authentication.getPrincipal() is the incorrect type.
      java.lang.String expression
      If specified will use the provided SpEL expression to resolve the principal.
    • Element Detail

      • errorOnInvalidType

        boolean errorOnInvalidType
        True if a ClassCastException should be thrown when the current Authentication.getPrincipal() is the incorrect type. Default is false.
        Returns:
        Default:
        false
      • expression

        java.lang.String expression
        If specified will use the provided SpEL expression to resolve the principal. This is convenient if users need to transform the result.

        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")
         
        Returns:
        the expression to use.
        Default:
        ""