Browse Source

Remove the cache since UniqueSecurityAnnotationScanner has cached annotations internally

pull/16216/head
DingHao 1 year ago committed by Josh Cummings
parent
commit
dc82a6e97e
  1. 7
      messaging/src/main/java/org/springframework/security/messaging/context/AuthenticationPrincipalArgumentResolver.java
  2. 7
      messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/AuthenticationPrincipalArgumentResolver.java
  3. 7
      messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/CurrentSecurityContextArgumentResolver.java
  4. 7
      web/src/main/java/org/springframework/security/web/method/annotation/AuthenticationPrincipalArgumentResolver.java
  5. 7
      web/src/main/java/org/springframework/security/web/method/annotation/CurrentSecurityContextArgumentResolver.java
  6. 7
      web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/AuthenticationPrincipalArgumentResolver.java
  7. 7
      web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/CurrentSecurityContextArgumentResolver.java

7
messaging/src/main/java/org/springframework/security/messaging/context/AuthenticationPrincipalArgumentResolver.java

@ -17,8 +17,6 @@ @@ -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 @@ -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 @@ -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());
}
}

7
messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/AuthenticationPrincipalArgumentResolver.java

@ -17,8 +17,6 @@ @@ -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; @@ -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 @@ -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());
}
}

7
messaging/src/main/java/org/springframework/security/messaging/handler/invocation/reactive/CurrentSecurityContextArgumentResolver.java

@ -17,8 +17,6 @@ @@ -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; @@ -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 @@ -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());
}
}

7
web/src/main/java/org/springframework/security/web/method/annotation/AuthenticationPrincipalArgumentResolver.java

@ -17,8 +17,6 @@ @@ -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 @@ -98,8 +96,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
@ -179,8 +175,7 @@ public final class AuthenticationPrincipalArgumentResolver implements HandlerMet @@ -179,8 +175,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());
}
}

7
web/src/main/java/org/springframework/security/web/method/annotation/CurrentSecurityContextArgumentResolver.java

@ -17,8 +17,6 @@ @@ -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 @@ -84,8 +82,6 @@ public final class CurrentSecurityContextArgumentResolver implements HandlerMeth
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
.getContextHolderStrategy();
private final Map<MethodParameter, Annotation> cachedAttributes = new ConcurrentHashMap<>();
private ExpressionParser parser = new SpelExpressionParser();
private SecurityAnnotationScanner<CurrentSecurityContext> scanner = SecurityAnnotationScanners
@ -177,8 +173,7 @@ public final class CurrentSecurityContextArgumentResolver implements HandlerMeth @@ -177,8 +173,7 @@ public final class CurrentSecurityContextArgumentResolver implements HandlerMeth
*/
@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());
}
}

7
web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/AuthenticationPrincipalArgumentResolver.java

@ -17,8 +17,6 @@ @@ -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 @@ import org.springframework.web.server.ServerWebExchange; @@ -53,8 +51,6 @@ import org.springframework.web.server.ServerWebExchange;
*/
public class AuthenticationPrincipalArgumentResolver extends HandlerMethodArgumentResolverSupport {
private final Map<MethodParameter, Annotation> cachedAttributes = new ConcurrentHashMap<>();
private ExpressionParser parser = new SpelExpressionParser();
private SecurityAnnotationScanner<AuthenticationPrincipal> scanner = SecurityAnnotationScanners
@ -149,8 +145,7 @@ public class AuthenticationPrincipalArgumentResolver extends HandlerMethodArgume @@ -149,8 +145,7 @@ public class AuthenticationPrincipalArgumentResolver extends HandlerMethodArgume
*/
@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());
}
}

7
web/src/main/java/org/springframework/security/web/reactive/result/method/annotation/CurrentSecurityContextArgumentResolver.java

@ -17,8 +17,6 @@ @@ -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 @@ import org.springframework.web.server.ServerWebExchange; @@ -53,8 +51,6 @@ import org.springframework.web.server.ServerWebExchange;
*/
public class CurrentSecurityContextArgumentResolver extends HandlerMethodArgumentResolverSupport {
private final Map<MethodParameter, Annotation> cachedAttributes = new ConcurrentHashMap<>();
private ExpressionParser parser = new SpelExpressionParser();
private SecurityAnnotationScanner<CurrentSecurityContext> scanner = SecurityAnnotationScanners
@ -189,8 +185,7 @@ public class CurrentSecurityContextArgumentResolver extends HandlerMethodArgumen @@ -189,8 +185,7 @@ public class CurrentSecurityContextArgumentResolver extends HandlerMethodArgumen
*/
@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());
}
}

Loading…
Cancel
Save