アノテーション型 AuthenticationPrincipal
@Target({PARAMETER,ANNOTATION_TYPE}) @Retention(RUNTIME) @Documented public @interface AuthenticationPrincipal
Authentication.getPrincipal()
をメソッド引数に解決するために使用されるアノテーション。- 導入:
- 4.0 参照先: AuthenticationPrincipalArgumentResolver
オプション要素のサマリー
オプション要素 修飾子と型 オプションの要素 説明 boolean
errorOnInvalidType
現在のAuthentication.getPrincipal()
が正しくない型である場合にClassCastException
をスローする必要がある場合は true。java.lang.String
expression
指定されている場合、提供された SpEL 式を使用してプリンシパルを解決します。
要素の詳細
errorOnInvalidType
boolean errorOnInvalidType
現在のAuthentication.getPrincipal()
が正しくない型である場合にClassCastException
をスローする必要がある場合は true。デフォルトは false です。- 戻り値:
- デフォルト:
- false
expression
java.lang.String expression
指定されている場合、提供された SpEL 式を使用してプリンシパルを解決します。これは、ユーザーが結果を変換する必要がある場合に便利です。例: おそらくユーザーは、最終で UserDetailsService を活用している CustomUser オブジェクトを解決したいと考えています。これは、次のようなオブジェクトを返すことで処理できます。
public class CustomUserUserDetails extends User { // ... public CustomUser getCustomUser() { return customUser; } }
次に、ユーザーは次のようなアノテーションを指定できます。@AuthenticationPrincipal(expression = "customUser")
- 戻り値:
- 使用する式。
- デフォルト:
- ""