From 6a34807a07f131c96a95263a9c30f01e5fc26a44 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Fri, 26 Feb 2010 17:21:25 +0000 Subject: [PATCH] SEC-1423: Cache PointcutExpression instances in ProtectPointcutPostProcessor for more efficient startup. --- .../config/method/ProtectPointcutPostProcessor.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/src/main/java/org/springframework/security/config/method/ProtectPointcutPostProcessor.java b/config/src/main/java/org/springframework/security/config/method/ProtectPointcutPostProcessor.java index 7f8be45289..f498e44c4f 100644 --- a/config/src/main/java/org/springframework/security/config/method/ProtectPointcutPostProcessor.java +++ b/config/src/main/java/org/springframework/security/config/method/ProtectPointcutPostProcessor.java @@ -3,6 +3,7 @@ package org.springframework.security.config.method; import java.lang.reflect.Method; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -44,7 +45,6 @@ import org.springframework.util.StringUtils; * * @author Ben Alex * @since 2.0 - * */ final class ProtectPointcutPostProcessor implements BeanPostProcessor { @@ -52,6 +52,7 @@ final class ProtectPointcutPostProcessor implements BeanPostProcessor { private Map> pointcutMap = new LinkedHashMap>(); private MapBasedMethodSecurityMetadataSource mapBasedMethodSecurityMetadataSource; + private Set pointCutExpressions = new LinkedHashSet(); private PointcutParser parser; 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 for (int i = 0; i < methods.length; i++) { - for (String ex : pointcutMap.keySet()) { - // Parse the presented AspectJ pointcut expression - PointcutExpression expression = parser.parsePointcutExpression(ex); - + for (PointcutExpression expression : pointCutExpressions) { // Try for the bean class directly 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 @@ -134,6 +132,8 @@ final class ProtectPointcutPostProcessor implements BeanPostProcessor { Assert.notNull(definition, "A List of ConfigAttributes is required"); pointcutExpression = replaceBooleanOperators(pointcutExpression); pointcutMap.put(pointcutExpression, definition); + // Parse the presented AspectJ pointcut expression and add it to the cache + pointCutExpressions.add(parser.parsePointcutExpression(pointcutExpression)); if (logger.isDebugEnabled()) { logger.debug("AspectJ pointcut expression '" + pointcutExpression + "' registered for security configuration attribute '" + definition + "'");