mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-26 13:53:14 +00:00
SEC-1423: Cache PointcutExpression instances in ProtectPointcutPostProcessor for more efficient startup.
This commit is contained in:
parent
9e751e22c8
commit
317da55cd0
@ -3,6 +3,7 @@ package org.springframework.security.config.method;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -44,7 +45,6 @@ import org.springframework.util.StringUtils;
|
|||||||
*
|
*
|
||||||
* @author Ben Alex
|
* @author Ben Alex
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
final class ProtectPointcutPostProcessor implements BeanPostProcessor {
|
final class ProtectPointcutPostProcessor implements BeanPostProcessor {
|
||||||
|
|
||||||
@ -52,6 +52,7 @@ final class ProtectPointcutPostProcessor implements BeanPostProcessor {
|
|||||||
|
|
||||||
private Map<String,List<ConfigAttribute>> pointcutMap = new LinkedHashMap<String,List<ConfigAttribute>>();
|
private Map<String,List<ConfigAttribute>> pointcutMap = new LinkedHashMap<String,List<ConfigAttribute>>();
|
||||||
private MapBasedMethodSecurityMetadataSource mapBasedMethodSecurityMetadataSource;
|
private MapBasedMethodSecurityMetadataSource mapBasedMethodSecurityMetadataSource;
|
||||||
|
private Set<PointcutExpression> pointCutExpressions = new LinkedHashSet<PointcutExpression>();
|
||||||
private PointcutParser parser;
|
private PointcutParser parser;
|
||||||
|
|
||||||
public ProtectPointcutPostProcessor(MapBasedMethodSecurityMetadataSource mapBasedMethodSecurityMetadataSource) {
|
public ProtectPointcutPostProcessor(MapBasedMethodSecurityMetadataSource mapBasedMethodSecurityMetadataSource) {
|
||||||
@ -88,10 +89,7 @@ final class ProtectPointcutPostProcessor implements BeanPostProcessor {
|
|||||||
|
|
||||||
// Check to see if any of those methods are compatible with our pointcut expressions
|
// Check to see if any of those methods are compatible with our pointcut expressions
|
||||||
for (int i = 0; i < methods.length; i++) {
|
for (int i = 0; i < methods.length; i++) {
|
||||||
for (String ex : pointcutMap.keySet()) {
|
for (PointcutExpression expression : pointCutExpressions) {
|
||||||
// Parse the presented AspectJ pointcut expression
|
|
||||||
PointcutExpression expression = parser.parsePointcutExpression(ex);
|
|
||||||
|
|
||||||
// Try for the bean class directly
|
// Try for the bean class directly
|
||||||
if (attemptMatch(bean.getClass(), methods[i], expression, beanName)) {
|
if (attemptMatch(bean.getClass(), methods[i], expression, beanName)) {
|
||||||
// We've found the first expression that matches this method, so move onto the next method now
|
// We've found the first expression that matches this method, so move onto the next method now
|
||||||
@ -134,6 +132,8 @@ final class ProtectPointcutPostProcessor implements BeanPostProcessor {
|
|||||||
Assert.notNull(definition, "A List of ConfigAttributes is required");
|
Assert.notNull(definition, "A List of ConfigAttributes is required");
|
||||||
pointcutExpression = replaceBooleanOperators(pointcutExpression);
|
pointcutExpression = replaceBooleanOperators(pointcutExpression);
|
||||||
pointcutMap.put(pointcutExpression, definition);
|
pointcutMap.put(pointcutExpression, definition);
|
||||||
|
// Parse the presented AspectJ pointcut expression and add it to the cache
|
||||||
|
pointCutExpressions.add(parser.parsePointcutExpression(pointcutExpression));
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("AspectJ pointcut expression '" + pointcutExpression + "' registered for security configuration attribute '" + definition + "'");
|
logger.debug("AspectJ pointcut expression '" + pointcutExpression + "' registered for security configuration attribute '" + definition + "'");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user