Browse Source

Refactor AbstractFilterInvocationDefinitionSource to use a standard URL String in its lookup method, rather than a full FilterInvocation. This will make it easier for views (taglibs etc) to access URI security details without needing to construct a MockFilterInvocation.

Ben Alex 21 years ago
parent
commit
82ed7253d4

+ 21 - 10
core/src/main/java/org/acegisecurity/intercept/web/AbstractFilterInvocationDefinitionSource.java

@@ -42,15 +42,9 @@ public abstract class AbstractFilterInvocationDefinitionSource
                 "Object must be a FilterInvocation");
         }
 
-        return this.lookupAttributes((FilterInvocation) object);
-    }
+        String url = ((FilterInvocation) object).getRequestUrl();
 
-    public boolean supports(Class clazz) {
-        if (FilterInvocation.class.isAssignableFrom(clazz)) {
-            return true;
-        } else {
-            return false;
-        }
+        return this.lookupAttributes(url);
     }
 
     /**
@@ -62,10 +56,27 @@ public abstract class AbstractFilterInvocationDefinitionSource
      * Provided so subclasses need only to provide one basic method to properly
      * interface with the <code>FilterInvocationDefinitionSource</code>.
      * </p>
+     * 
+     * <P>
+     * Public visiblity so that tablibs or other view helper classes can access
+     * the <code>ConfigAttributeDefinition</code> applying to a given URI
+     * pattern without needing to construct a mock
+     * <code>FilterInvocation</code> and retrieving the attibutes via the
+     * {@link #getAttributes(Object)} method.
+     * </p>
+     *
+     * @param url the URI to retrieve configuration attributes for
      *
      * @return the <code>ConfigAttributeDefinition</code> that applies to the
      *         specified <code>FilterInvocation</code>
      */
-    protected abstract ConfigAttributeDefinition lookupAttributes(
-        FilterInvocation filterInvocation);
+    public abstract ConfigAttributeDefinition lookupAttributes(String url);
+
+    public boolean supports(Class clazz) {
+        if (FilterInvocation.class.isAssignableFrom(clazz)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
 }

+ 3 - 6
core/src/main/java/org/acegisecurity/intercept/web/PathBasedFilterInvocationDefinitionMap.java

@@ -99,18 +99,15 @@ public class PathBasedFilterInvocationDefinitionMap
         }
     }
 
-    protected ConfigAttributeDefinition lookupAttributes(
-        FilterInvocation filterInvocation) {
+    public ConfigAttributeDefinition lookupAttributes(String url) {
         Iterator iter = requestMap.iterator();
 
-        String url = filterInvocation.getRequestUrl();
-
         if (convertUrlToLowercaseBeforeComparison) {
             url = url.toLowerCase();
 
             if (logger.isDebugEnabled()) {
-                logger.debug("Converted URL to lowercase, from: '"
-                    + filterInvocation.getRequest() + "'; to: '" + url + "'");
+                logger.debug("Converted URL to lowercase, from: '" + url
+                    + "'; to: '" + url + "'");
             }
         }
 

+ 3 - 6
core/src/main/java/org/acegisecurity/intercept/web/RegExpBasedFilterInvocationDefinitionMap.java

@@ -117,20 +117,17 @@ public class RegExpBasedFilterInvocationDefinitionMap
         }
     }
 
-    protected ConfigAttributeDefinition lookupAttributes(
-        FilterInvocation filterInvocation) {
+    public ConfigAttributeDefinition lookupAttributes(String url) {
         PatternMatcher matcher = new Perl5Matcher();
 
         Iterator iter = requestMap.iterator();
 
-        String url = filterInvocation.getRequestUrl();
-
         if (convertUrlToLowercaseBeforeComparison) {
             url = url.toLowerCase();
 
             if (logger.isDebugEnabled()) {
-                logger.debug("Converted URL to lowercase, from: '"
-                    + filterInvocation.getRequest() + "'; to: '" + url + "'");
+                logger.debug("Converted URL to lowercase, from: '" + url
+                    + "'; to: '" + url + "'");
             }
         }
 

+ 1 - 2
core/src/test/java/org/acegisecurity/intercept/web/MockFilterInvocationDefinitionSource.java

@@ -81,8 +81,7 @@ public class MockFilterInvocationDefinitionSource
         }
     }
 
-    protected ConfigAttributeDefinition lookupAttributes(
-        FilterInvocation filterInvocation) {
+    public ConfigAttributeDefinition lookupAttributes(String url) {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 }

+ 6 - 3
core/src/test/java/org/acegisecurity/intercept/web/PathBasedFilterDefinitionMapTests.java

@@ -79,7 +79,8 @@ public class PathBasedFilterDefinitionMapTests extends TestCase {
         FilterInvocation fi = new FilterInvocation(req,
                 new MockHttpServletResponse(), new MockFilterChain());
 
-        ConfigAttributeDefinition response = map.lookupAttributes(fi);
+        ConfigAttributeDefinition response = map.lookupAttributes(fi
+                .getRequestUrl());
         assertEquals(def, response);
     }
 
@@ -98,7 +99,8 @@ public class PathBasedFilterDefinitionMapTests extends TestCase {
         FilterInvocation fi = new FilterInvocation(req,
                 new MockHttpServletResponse(), new MockFilterChain());
 
-        ConfigAttributeDefinition response = map.lookupAttributes(fi);
+        ConfigAttributeDefinition response = map.lookupAttributes(fi
+                .getRequestUrl());
         assertEquals(null, response);
     }
 
@@ -117,7 +119,8 @@ public class PathBasedFilterDefinitionMapTests extends TestCase {
         FilterInvocation fi = new FilterInvocation(req,
                 new MockHttpServletResponse(), new MockFilterChain());
 
-        ConfigAttributeDefinition response = map.lookupAttributes(fi);
+        ConfigAttributeDefinition response = map.lookupAttributes(fi
+                .getRequestUrl());
         assertEquals(def, response);
     }
 }

+ 6 - 3
core/src/test/java/org/acegisecurity/intercept/web/RegExpBasedFilterDefinitionMapTests.java

@@ -79,7 +79,8 @@ public class RegExpBasedFilterDefinitionMapTests extends TestCase {
         FilterInvocation fi = new FilterInvocation(req,
                 new MockHttpServletResponse(), new MockFilterChain());
 
-        ConfigAttributeDefinition response = map.lookupAttributes(fi);
+        ConfigAttributeDefinition response = map.lookupAttributes(fi
+                .getRequestUrl());
         assertEquals(def, response);
     }
 
@@ -98,7 +99,8 @@ public class RegExpBasedFilterDefinitionMapTests extends TestCase {
         FilterInvocation fi = new FilterInvocation(req,
                 new MockHttpServletResponse(), new MockFilterChain());
 
-        ConfigAttributeDefinition response = map.lookupAttributes(fi);
+        ConfigAttributeDefinition response = map.lookupAttributes(fi
+                .getRequestUrl());
         assertEquals(null, response);
     }
 
@@ -117,7 +119,8 @@ public class RegExpBasedFilterDefinitionMapTests extends TestCase {
         FilterInvocation fi = new FilterInvocation(req,
                 new MockHttpServletResponse(), new MockFilterChain());
 
-        ConfigAttributeDefinition response = map.lookupAttributes(fi);
+        ConfigAttributeDefinition response = map.lookupAttributes(fi
+                .getRequestUrl());
         assertEquals(def, response);
     }
 }

+ 1 - 0
doc/xdocs/changes.xml

@@ -45,6 +45,7 @@
       <action dev="benalex" type="add">Added AbstractProcessingFilter property to always use defaultTargetUrl</action>
       <action dev="benalex" type="update">Improved BasicAclProvider to only respond to specified ACL object requests</action>
       <action dev="benalex" type="update">Refactored MethodDefinitionSource to work with Method, not MethodInvocation</action>
+      <action dev="benalex" type="update">Refactored AbstractFilterInvocationDefinitionSource to work with URL Strings alone</action>
       <action dev="benalex" type="update">Refactored AbstractSecurityInterceptor to better support other AOP libraries</action>
       <action dev="benalex" type="update">Improved performance of JBoss container adapter (see reference docs)</action>
       <action dev="benalex" type="update">Made DaoAuthenticationProvider detect null in Authentication.principal</action>