アノテーションインターフェース AuthenticationPrincipal


@TargetSE({PARAMETERSE,ANNOTATION_TYPESE}) @RetentionSE(RUNTIMESE) @DocumentedSE public @interface AuthenticationPrincipal
Authentication.getPrincipal() をメソッド引数に解決するために使用されるアノテーション。
導入:
4.0 参照先: AuthenticationPrincipalArgumentResolver
  • 要素の詳細

    • errorOnInvalidType

      boolean errorOnInvalidType
      現在の Authentication.getPrincipal() が正しくない型である場合に ClassCastExceptionSE をスローする必要がある場合は true。デフォルトは false です。
      戻り値:
      デフォルト:
      false
    • expression

      StringSE expression
      指定されている場合、提供された SpEL 式を使用してプリンシパルを解決します。これは、ユーザーが結果を変換する必要がある場合に便利です。

      例: おそらくユーザーは、最終で UserDetailsService を活用している CustomUser オブジェクトを解決したいと考えています。これは、次のようなオブジェクトを返すことで処理できます。

       public class CustomUserUserDetails extends User {
           // ...
           public CustomUser getCustomUser() {
               return customUser;
           }
       }
       
      次に、ユーザーは次のようなアノテーションを指定できます。
       @AuthenticationPrincipal(expression = "customUser")
       
      戻り値:
      使用する式。
      デフォルト:
      ""