1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Remove the cache since UniqueSecurityAnnotationScanner has cached annotations internally

This commit is contained in:
DingHao
2024-12-02 11:42:08 +08:00
committed by Josh Cummings
parent 5329030d27
commit dc82a6e97e
7 changed files with 7 additions and 42 deletions
@@ -17,8 +17,6 @@
package org.springframework.security.messaging.context;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.core.MethodParameter;
import org.springframework.expression.Expression;
@@ -95,8 +93,6 @@ public final class AuthenticationPrincipalArgumentResolver implements HandlerMet
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
.getContextHolderStrategy();
private final Map<MethodParameter, Annotation> cachedAttributes = new ConcurrentHashMap<>();
private ExpressionParser parser = new SpelExpressionParser();
private SecurityAnnotationScanner<AuthenticationPrincipal> scanner = SecurityAnnotationScanners
@@ -164,8 +160,7 @@ public final class AuthenticationPrincipalArgumentResolver implements HandlerMet
*/
@SuppressWarnings("unchecked")
private <T extends Annotation> T findMethodAnnotation(MethodParameter parameter) {
return (T) this.cachedAttributes.computeIfAbsent(parameter,
(methodParameter) -> this.scanner.scan(methodParameter.getParameter()));
return (T) this.scanner.scan(parameter.getParameter());
}
}
@@ -17,8 +17,6 @@
package org.springframework.security.messaging.handler.invocation.reactive;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
@@ -99,8 +97,6 @@ import org.springframework.util.StringUtils;
*/
public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArgumentResolver {
private final Map<MethodParameter, Annotation> cachedAttributes = new ConcurrentHashMap<>();
private ExpressionParser parser = new SpelExpressionParser();
private SecurityAnnotationScanner<AuthenticationPrincipal> scanner = SecurityAnnotationScanners
@@ -205,8 +201,7 @@ public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArg
*/
@SuppressWarnings("unchecked")
private <T extends Annotation> T findMethodAnnotation(MethodParameter parameter) {
return (T) this.cachedAttributes.computeIfAbsent(parameter,
(methodParameter) -> this.scanner.scan(methodParameter.getParameter()));
return (T) this.scanner.scan(parameter.getParameter());
}
}
@@ -17,8 +17,6 @@
package org.springframework.security.messaging.handler.invocation.reactive;
import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
@@ -97,8 +95,6 @@ import org.springframework.util.StringUtils;
*/
public class CurrentSecurityContextArgumentResolver implements HandlerMethodArgumentResolver {
private final Map<MethodParameter, Annotation> cachedAttributes = new ConcurrentHashMap<>();
private ExpressionParser parser = new SpelExpressionParser();
private SecurityAnnotationScanner<CurrentSecurityContext> scanner = SecurityAnnotationScanners
@@ -222,8 +218,7 @@ public class CurrentSecurityContextArgumentResolver implements HandlerMethodArgu
*/
@SuppressWarnings("unchecked")
private <T extends Annotation> T findMethodAnnotation(MethodParameter parameter) {
return (T) this.cachedAttributes.computeIfAbsent(parameter,
(methodParameter) -> this.scanner.scan(methodParameter.getParameter()));
return (T) this.scanner.scan(parameter.getParameter());
}
}