クラス AuthenticationPrincipalArgumentResolver
java.lang.ObjectSE
org.springframework.security.web.bind.support.AuthenticationPrincipalArgumentResolver
- 実装されているすべてのインターフェース:
org.springframework.web.method.support.HandlerMethodArgumentResolver
@DeprecatedSE
public final class AuthenticationPrincipalArgumentResolver
extends ObjectSE
implements org.springframework.web.method.support.HandlerMethodArgumentResolver
使用すべきではありません。
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 が返されます。true の場合は ClassCastExceptionSE がスローされます。
または、ユーザーは以下に示すようにカスタムメタアノテーションを作成できます。
@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
コンストラクターの概要
コンストラクター方法の概要
修飾子と型メソッド説明@Nullable ObjectSEresolveArgument(org.springframework.core.MethodParameter parameter, @Nullable org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, @Nullable org.springframework.web.bind.support.WebDataBinderFactory binderFactory) 使用すべきではありません。booleansupportsParameter(org.springframework.core.MethodParameter parameter) 使用すべきではありません。
コンストラクターの詳細
AuthenticationPrincipalArgumentResolver
public AuthenticationPrincipalArgumentResolver()使用すべきではありません。
メソッドの詳細
supportsParameter
public boolean supportsParameter(org.springframework.core.MethodParameter parameter) 使用すべきではありません。- 次で指定:
- インターフェース
org.springframework.web.method.support.HandlerMethodArgumentResolverのsupportsParameter
resolveArgument
public @Nullable ObjectSE resolveArgument(org.springframework.core.MethodParameter parameter, @Nullable org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest, @Nullable org.springframework.web.bind.support.WebDataBinderFactory binderFactory) 使用すべきではありません。- 次で指定:
- インターフェース
org.springframework.web.method.support.HandlerMethodArgumentResolverのresolveArgument
AuthenticationPrincipalArgumentResolverを使用してください。