クラス AuthenticationPrincipalArgumentResolver

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

    public final class AuthenticationPrincipalArgumentResolver
    extends java.lang.Object
    implements org.springframework.web.method.support.HandlerMethodArgumentResolver
    AuthenticationPrincipal アノテーションを使用して Authentication.getPrincipal() を解決できます。例: 次の Controller:
     @Controller
     public class MyController {
         @MessageMapping("/im")
         public void im(@AuthenticationPrincipal CustomUser customUser) {
             // do something with CustomUser
         }
     }
     

    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 {
         @MessageMapping("/im")
         public void im(@CurrentUser CustomUser customUser) {
             // do something with CustomUser
         }
     }
     
    導入:
    4.0
    • メソッドのサマリー

      すべてのメソッド   インスタンスメソッド   具象メソッド  
      修飾子と型 メソッド 説明
      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)
      voidsetBeanResolver​(org.springframework.expression.BeanResolver beanResolver)
      式で使用する BeanResolver を設定します
      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 
      • setBeanResolver

        public void setBeanResolver​(org.springframework.expression.BeanResolver beanResolver)
        式で使用する BeanResolver を設定します
        パラメーター:
        beanResolver - 使用する BeanResolver