From f3f778950df3d6cb36ad1f45c13325941da34b61 Mon Sep 17 00:00:00 2001 From: DingHao Date: Mon, 2 Dec 2024 11:42:08 +0800 Subject: [PATCH] Remove the cache since UniqueSecurityAnnotationScanner has cached annotations internally --- .../context/AuthenticationPrincipalArgumentResolver.java | 7 +------ .../reactive/AuthenticationPrincipalArgumentResolver.java | 7 +------ .../reactive/CurrentSecurityContextArgumentResolver.java | 7 +------ .../AuthenticationPrincipalArgumentResolver.java | 7 +------ .../annotation/CurrentSecurityContextArgumentResolver.java | 7 +------ .../AuthenticationPrincipalArgumentResolver.java | 7 +------ .../annotation/CurrentSecurityContextArgumentResolver.java | 7 +------ 7 files changed, 7 insertions(+), 42 deletions(-) diff --git a/messaging/src/main/java/org/springframework/security/messaging/context/AuthenticationPrincipalArgumentResolver.java b/messaging/src/main/java/org/springframework/security/messaging/context/AuthenticationPrincipalArgumentResolver.java index c4e686e9ea9..f3f6f80fbea 100644 --- a/messaging/src/main/java/org/springframework/security/messaging/context/AuthenticationPrincipalArgumentResolver.java +++ b/messaging/src/main/java/org/springframework/security/messaging/context/AuthenticationPrincipalArgumentResolver.java @@ -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 cachedAttributes = new ConcurrentHashMap<>(); - private ExpressionParser parser = new SpelExpressionParser(); private SecurityAnnotationScanner scanner = SecurityAnnotationScanners @@ -164,8 +160,7 @@ public void setTemplateDefaults(AnnotationTemplateExpressionDefaults templateDef */ @SuppressWarnings("unchecked") private T findMethodAnnotation(MethodParameter parameter) { - return (T) this.cachedAttributes.computeIfAbsent(parameter, - (methodParameter) -> this.scanner.scan(methodParameter.getParameter())); + return (T) this.scanner.scan(parameter.getParameter()); } } diff --git a/messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/AuthenticationPrincipalArgumentResolver.java b/messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/AuthenticationPrincipalArgumentResolver.java index 198f40c5327..bb0590a9caa 100644 --- a/messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/AuthenticationPrincipalArgumentResolver.java +++ b/messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/AuthenticationPrincipalArgumentResolver.java @@ -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 @@ */ public class AuthenticationPrincipalArgumentResolver implements HandlerMethodArgumentResolver { - private final Map cachedAttributes = new ConcurrentHashMap<>(); - private ExpressionParser parser = new SpelExpressionParser(); private SecurityAnnotationScanner scanner = SecurityAnnotationScanners @@ -205,8 +201,7 @@ public void setTemplateDefaults(AnnotationTemplateExpressionDefaults templateDef */ @SuppressWarnings("unchecked") private T findMethodAnnotation(MethodParameter parameter) { - return (T) this.cachedAttributes.computeIfAbsent(parameter, - (methodParameter) -> this.scanner.scan(methodParameter.getParameter())); + return (T) this.scanner.scan(parameter.getParameter()); } } diff --git a/messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/CurrentSecurityContextArgumentResolver.java b/messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/CurrentSecurityContextArgumentResolver.java index a66ba6784ca..62f25fefbb1 100644 --- a/messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/CurrentSecurityContextArgumentResolver.java +++ b/messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/CurrentSecurityContextArgumentResolver.java @@ -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 @@ */ public class CurrentSecurityContextArgumentResolver implements HandlerMethodArgumentResolver { - private final Map cachedAttributes = new ConcurrentHashMap<>(); - private ExpressionParser parser = new SpelExpressionParser(); private SecurityAnnotationScanner scanner = SecurityAnnotationScanners @@ -222,8 +218,7 @@ public void setTemplateDefaults(AnnotationTemplateExpressionDefaults templateDef */ @SuppressWarnings("unchecked") private T findMethodAnnotation(MethodParameter parameter) { - return (T) this.cachedAttributes.computeIfAbsent(parameter, - (methodParameter) -> this.scanner.scan(methodParameter.getParameter())); + return (T) this.scanner.scan(parameter.getParameter()); } } diff --git a/web/src/main/java/org/springframework/security/web/method/annotation/AuthenticationPrincipalArgumentResolver.java b/web/src/main/java/org/springframework/security/web/method/annotation/AuthenticationPrincipalArgumentResolver.java index c119cbdc0b3..63a660012d7 100644 --- a/web/src/main/java/org/springframework/security/web/method/annotation/AuthenticationPrincipalArgumentResolver.java +++ b/web/src/main/java/org/springframework/security/web/method/annotation/AuthenticationPrincipalArgumentResolver.java @@ -17,8 +17,6 @@ package org.springframework.security.web.method.annotation; import java.lang.annotation.Annotation; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.MethodParameter; import org.springframework.expression.BeanResolver; @@ -98,8 +96,6 @@ public final class AuthenticationPrincipalArgumentResolver implements HandlerMet private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder .getContextHolderStrategy(); - private final Map cachedAttributes = new ConcurrentHashMap<>(); - private ExpressionParser parser = new SpelExpressionParser(); private SecurityAnnotationScanner scanner = SecurityAnnotationScanners @@ -179,8 +175,7 @@ public void setTemplateDefaults(AnnotationTemplateExpressionDefaults templateDef */ @SuppressWarnings("unchecked") private T findMethodAnnotation(MethodParameter parameter) { - return (T) this.cachedAttributes.computeIfAbsent(parameter, - (methodParameter) -> this.scanner.scan(methodParameter.getParameter())); + return (T) this.scanner.scan(parameter.getParameter()); } } diff --git a/web/src/main/java/org/springframework/security/web/method/annotation/CurrentSecurityContextArgumentResolver.java b/web/src/main/java/org/springframework/security/web/method/annotation/CurrentSecurityContextArgumentResolver.java index f73c5fc7197..600060e78e9 100644 --- a/web/src/main/java/org/springframework/security/web/method/annotation/CurrentSecurityContextArgumentResolver.java +++ b/web/src/main/java/org/springframework/security/web/method/annotation/CurrentSecurityContextArgumentResolver.java @@ -17,8 +17,6 @@ package org.springframework.security.web.method.annotation; import java.lang.annotation.Annotation; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.springframework.core.MethodParameter; import org.springframework.expression.BeanResolver; @@ -84,8 +82,6 @@ public final class CurrentSecurityContextArgumentResolver implements HandlerMeth private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder .getContextHolderStrategy(); - private final Map cachedAttributes = new ConcurrentHashMap<>(); - private ExpressionParser parser = new SpelExpressionParser(); private SecurityAnnotationScanner scanner = SecurityAnnotationScanners @@ -177,8 +173,7 @@ private Object resolveSecurityContextFromAnnotation(MethodParameter parameter, C */ @SuppressWarnings("unchecked") private T findMethodAnnotation(MethodParameter parameter) { - return (T) this.cachedAttributes.computeIfAbsent(parameter, - (methodParameter) -> this.scanner.scan(methodParameter.getParameter())); + return (T) this.scanner.scan(parameter.getParameter()); } } diff --git a/web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/AuthenticationPrincipalArgumentResolver.java b/web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/AuthenticationPrincipalArgumentResolver.java index 1e4cfca6aec..aae0b46be22 100644 --- a/web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/AuthenticationPrincipalArgumentResolver.java +++ b/web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/AuthenticationPrincipalArgumentResolver.java @@ -17,8 +17,6 @@ package org.springframework.security.web.reactive.result.method.annotation; import java.lang.annotation.Annotation; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -53,8 +51,6 @@ */ public class AuthenticationPrincipalArgumentResolver extends HandlerMethodArgumentResolverSupport { - private final Map cachedAttributes = new ConcurrentHashMap<>(); - private ExpressionParser parser = new SpelExpressionParser(); private SecurityAnnotationScanner scanner = SecurityAnnotationScanners @@ -149,8 +145,7 @@ public void setTemplateDefaults(AnnotationTemplateExpressionDefaults templateDef */ @SuppressWarnings("unchecked") private T findMethodAnnotation(MethodParameter parameter) { - return (T) this.cachedAttributes.computeIfAbsent(parameter, - (methodParameter) -> this.scanner.scan(methodParameter.getParameter())); + return (T) this.scanner.scan(parameter.getParameter()); } } diff --git a/web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/CurrentSecurityContextArgumentResolver.java b/web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/CurrentSecurityContextArgumentResolver.java index 038dcac6499..8fd7c724755 100644 --- a/web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/CurrentSecurityContextArgumentResolver.java +++ b/web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/CurrentSecurityContextArgumentResolver.java @@ -17,8 +17,6 @@ package org.springframework.security.web.reactive.result.method.annotation; import java.lang.annotation.Annotation; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -53,8 +51,6 @@ */ public class CurrentSecurityContextArgumentResolver extends HandlerMethodArgumentResolverSupport { - private final Map cachedAttributes = new ConcurrentHashMap<>(); - private ExpressionParser parser = new SpelExpressionParser(); private SecurityAnnotationScanner scanner = SecurityAnnotationScanners @@ -189,8 +185,7 @@ private boolean isInvalidType(MethodParameter parameter, Object reactiveSecurity */ @SuppressWarnings("unchecked") private T findMethodAnnotation(MethodParameter parameter) { - return (T) this.cachedAttributes.computeIfAbsent(parameter, - (methodParameter) -> this.scanner.scan(methodParameter.getParameter())); + return (T) this.scanner.scan(parameter.getParameter()); } }