クラス AuthenticationPrincipalArgumentResolver
- java.lang.Object
-
- org.springframework.security.web.method.annotation.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
コンストラクターのサマリー
コンストラクター コンストラクター 説明 AuthenticationPrincipalArgumentResolver()
メソッドのサマリー
すべてのメソッド インスタンスメソッド 具象メソッド 修飾子と型 メソッド 説明 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)
void
setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
式で使用するBeanResolver
を設定しますboolean
supportsParameter(org.springframework.core.MethodParameter parameter)
メソッドの詳細
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter)
- 次で指定:
- インターフェース
org.springframework.web.method.support.HandlerMethodArgumentResolver
のsupportsParameter
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.HandlerMethodArgumentResolver
のresolveArgument
setBeanResolver
public void setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
式で使用するBeanResolver
を設定します- パラメーター:
beanResolver
- 使用するBeanResolver