From 68d814e0422491e1ed87ea7fb73a9bdcfc17d552 Mon Sep 17 00:00:00 2001 From: DingHao Date: Fri, 20 Sep 2024 16:51:56 +0800 Subject: [PATCH] Polish ExpressionTemplateSecurityAnnotationScanner --- ...pressionTemplateSecurityAnnotationScanner.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/springframework/security/core/annotation/ExpressionTemplateSecurityAnnotationScanner.java b/core/src/main/java/org/springframework/security/core/annotation/ExpressionTemplateSecurityAnnotationScanner.java index d2809673bf..76be084278 100644 --- a/core/src/main/java/org/springframework/security/core/annotation/ExpressionTemplateSecurityAnnotationScanner.java +++ b/core/src/main/java/org/springframework/security/core/annotation/ExpressionTemplateSecurityAnnotationScanner.java @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.springframework.core.MethodClassKey; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; @@ -80,10 +79,6 @@ final class ExpressionTemplateSecurityAnnotationScanner private final AnnotationTemplateExpressionDefaults templateDefaults; - private final Map> uniqueParameterAnnotationCache = new HashMap<>(); - - private final Map> uniqueMethodAnnotationCache = new HashMap<>(); - ExpressionTemplateSecurityAnnotationScanner(Class type, AnnotationTemplateExpressionDefaults templateDefaults) { Assert.notNull(type, "type cannot be null"); Assert.notNull(templateDefaults, "templateDefaults cannot be null"); @@ -95,17 +90,14 @@ final class ExpressionTemplateSecurityAnnotationScanner @Override MergedAnnotation merge(AnnotatedElement element, Class targetClass) { if (element instanceof Parameter parameter) { - MergedAnnotation annotation = this.uniqueParameterAnnotationCache.computeIfAbsent(parameter, - (p) -> this.unique.merge(p, targetClass)); + MergedAnnotation annotation = this.unique.merge(parameter, targetClass); if (annotation == null) { return null; } return resolvePlaceholders(annotation); } if (element instanceof Method method) { - MethodClassKey key = new MethodClassKey(method, targetClass); - MergedAnnotation annotation = this.uniqueMethodAnnotationCache.computeIfAbsent(key, - (k) -> this.unique.merge(method, targetClass)); + MergedAnnotation annotation = this.unique.merge(method, targetClass); if (annotation == null) { return null; } @@ -135,10 +127,9 @@ final class ExpressionTemplateSecurityAnnotationScanner } Map annotationProperties = mergedAnnotation.asMap(); for (Map.Entry annotationProperty : annotationProperties.entrySet()) { - if (!(annotationProperty.getValue() instanceof String)) { + if (!(annotationProperty.getValue() instanceof String expression)) { continue; } - String expression = (String) annotationProperty.getValue(); String value = helper.replacePlaceholders(expression, stringProperties::get); properties.put(annotationProperty.getKey(), value); }