クラス AuthenticationPrincipalArgumentResolver

  • 実装されたすべてのインターフェース:
    org.springframework.web.method.support.HandlerMethodArgumentResolver

    @Deprecated
    public final class AuthenticationPrincipalArgumentResolver
    extends java.lang.Object
    implements org.springframework.web.method.support.HandlerMethodArgumentResolver
    使用すべきではありません。
    代わりに AuthenticationPrincipalArgumentResolver を使用してください。
    AuthenticationPrincipal アノテーションを使用して Authentication.getPrincipal() を解決できます。例: 次の Controller:
     @Controller
     public class MyController {
         @RequestMapping("/user/current/show")
         public String show(@AuthenticationPrincipal CustomUser customUser) {
             // do something with CustomUser
             return "view";
         }
     }
     

    SecurityContextHolder から Authentication.getPrincipal() を使用して CustomUser 引数を解決します。Authentication または Authentication.getPrincipal() が null の場合、null を返します。型が一致しない場合、AuthenticationPrincipal.errorOnInvalidType() が true でない限り null が返され、その場合は ClassCastException がスローされます。

    または、ユーザーは以下に示すようにカスタムメタアノテーションを作成できます。

     @Target({ ElementType.PARAMETER })
     @Retention(RetentionPolicy.RUNTIME)
     @AuthenticationPrincipal
     public @interface CurrentUser {
     }
     

    代わりにカスタムアノテーションを使用できます。例:

     @Controller
     public class MyController {
         @RequestMapping("/user/current/show")
         public String show(@CurrentUser CustomUser customUser) {
             // do something with CustomUser
             return "view";
         }
     }
     
    導入:
    3.2
    • メソッドのサマリー

      すべてのメソッド   インスタンスメソッド   具象メソッド   非推奨のメソッド  
      修飾子と型 メソッド 説明
      java.lang.ObjectresolveArgument​(org.springframework.core.MethodParameter parameter, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
      使用すべきではありません。
      booleansupportsParameter​(org.springframework.core.MethodParameter parameter)
      使用すべきではありません。
      • クラス java.lang.Object から継承されたメソッド

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • コンストラクターの詳細

      • AuthenticationPrincipalArgumentResolver

        public AuthenticationPrincipalArgumentResolver()
        使用すべきではありません。
    • メソッドの詳細

      • supportsParameter

        public boolean supportsParameter​(org.springframework.core.MethodParameter parameter)
        使用すべきではありません。
        次で指定:
        インターフェース org.springframework.web.method.support.HandlerMethodArgumentResolversupportsParameter 
      • resolveArgument

        public java.lang.Object resolveArgument​(org.springframework.core.MethodParameter parameter,
                                                org.springframework.web.method.support.ModelAndViewContainer mavContainer,
                                                org.springframework.web.context.request.NativeWebRequest webRequest,
                                                org.springframework.web.bind.support.WebDataBinderFactory binderFactory)
        使用すべきではありません。
        次で指定:
        インターフェース org.springframework.web.method.support.HandlerMethodArgumentResolverresolveArgument