|
@@ -25,6 +25,8 @@ import org.springframework.core.MethodParameter;
|
|
|
import org.springframework.core.ReactiveAdapter;
|
|
|
import org.springframework.core.ReactiveAdapterRegistry;
|
|
|
import org.springframework.core.ResolvableType;
|
|
|
+import org.springframework.core.annotation.AnnotationUtils;
|
|
|
+import org.springframework.core.annotation.MergedAnnotations;
|
|
|
import org.springframework.expression.BeanResolver;
|
|
|
import org.springframework.expression.Expression;
|
|
|
import org.springframework.expression.ExpressionParser;
|
|
@@ -99,8 +101,12 @@ public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArg
|
|
|
|
|
|
private ExpressionParser parser = new SpelExpressionParser();
|
|
|
|
|
|
+ private final Class<AuthenticationPrincipal> annotationType = AuthenticationPrincipal.class;
|
|
|
+
|
|
|
private SecurityAnnotationScanner<AuthenticationPrincipal> scanner = SecurityAnnotationScanners
|
|
|
- .requireUnique(AuthenticationPrincipal.class);
|
|
|
+ .requireUnique(this.annotationType);
|
|
|
+
|
|
|
+ private boolean useAnnotationTemplate = false;
|
|
|
|
|
|
private BeanResolver beanResolver;
|
|
|
|
|
@@ -190,6 +196,7 @@ public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArg
|
|
|
* @since 6.4
|
|
|
*/
|
|
|
public void setTemplateDefaults(AnnotationTemplateExpressionDefaults templateDefaults) {
|
|
|
+ this.useAnnotationTemplate = templateDefaults != null;
|
|
|
this.scanner = SecurityAnnotationScanners.requireUnique(AuthenticationPrincipal.class, templateDefaults);
|
|
|
}
|
|
|
|
|
@@ -199,9 +206,22 @@ public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArg
|
|
|
* @param parameter the {@link MethodParameter} to search for an {@link Annotation}
|
|
|
* @return the {@link Annotation} that was found or null.
|
|
|
*/
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private <T extends Annotation> T findMethodAnnotation(MethodParameter parameter) {
|
|
|
- return (T) this.scanner.scan(parameter.getParameter());
|
|
|
+ private AuthenticationPrincipal findMethodAnnotation(MethodParameter parameter) {
|
|
|
+ if (this.useAnnotationTemplate) {
|
|
|
+ return this.scanner.scan(parameter.getParameter());
|
|
|
+ }
|
|
|
+ AuthenticationPrincipal annotation = parameter.getParameterAnnotation(this.annotationType);
|
|
|
+ if (annotation != null) {
|
|
|
+ return annotation;
|
|
|
+ }
|
|
|
+ Annotation[] annotationsToSearch = parameter.getParameterAnnotations();
|
|
|
+ for (Annotation toSearch : annotationsToSearch) {
|
|
|
+ annotation = AnnotationUtils.findAnnotation(toSearch.annotationType(), this.annotationType);
|
|
|
+ if (annotation != null) {
|
|
|
+ return MergedAnnotations.from(toSearch).get(this.annotationType).synthesize();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
}
|