From 82ed7253d49a55bcd903cb00ab8ed566c16e288f Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Sun, 5 Dec 2004 05:04:52 +0000 Subject: [PATCH] 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. --- ...tractFilterInvocationDefinitionSource.java | 31 +++++++++++++------ ...athBasedFilterInvocationDefinitionMap.java | 9 ++---- ...ExpBasedFilterInvocationDefinitionMap.java | 9 ++---- .../MockFilterInvocationDefinitionSource.java | 3 +- .../PathBasedFilterDefinitionMapTests.java | 9 ++++-- .../RegExpBasedFilterDefinitionMapTests.java | 9 ++++-- doc/xdocs/changes.xml | 1 + 7 files changed, 41 insertions(+), 30 deletions(-) diff --git a/core/src/main/java/org/acegisecurity/intercept/web/AbstractFilterInvocationDefinitionSource.java b/core/src/main/java/org/acegisecurity/intercept/web/AbstractFilterInvocationDefinitionSource.java index cf552e0f89..f8761e2ebc 100644 --- a/core/src/main/java/org/acegisecurity/intercept/web/AbstractFilterInvocationDefinitionSource.java +++ b/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 FilterInvocationDefinitionSource. *

+ * + *

+ * Public visiblity so that tablibs or other view helper classes can access + * the ConfigAttributeDefinition applying to a given URI + * pattern without needing to construct a mock + * FilterInvocation and retrieving the attibutes via the + * {@link #getAttributes(Object)} method. + *

+ * + * @param url the URI to retrieve configuration attributes for * * @return the ConfigAttributeDefinition that applies to the * specified FilterInvocation */ - 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; + } + } } diff --git a/core/src/main/java/org/acegisecurity/intercept/web/PathBasedFilterInvocationDefinitionMap.java b/core/src/main/java/org/acegisecurity/intercept/web/PathBasedFilterInvocationDefinitionMap.java index e26d604175..e9959e9582 100644 --- a/core/src/main/java/org/acegisecurity/intercept/web/PathBasedFilterInvocationDefinitionMap.java +++ b/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 + "'"); } } diff --git a/core/src/main/java/org/acegisecurity/intercept/web/RegExpBasedFilterInvocationDefinitionMap.java b/core/src/main/java/org/acegisecurity/intercept/web/RegExpBasedFilterInvocationDefinitionMap.java index 801870b523..73d0c344b1 100644 --- a/core/src/main/java/org/acegisecurity/intercept/web/RegExpBasedFilterInvocationDefinitionMap.java +++ b/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 + "'"); } } diff --git a/core/src/test/java/org/acegisecurity/intercept/web/MockFilterInvocationDefinitionSource.java b/core/src/test/java/org/acegisecurity/intercept/web/MockFilterInvocationDefinitionSource.java index 2d0372eea7..414661170b 100644 --- a/core/src/test/java/org/acegisecurity/intercept/web/MockFilterInvocationDefinitionSource.java +++ b/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"); } } diff --git a/core/src/test/java/org/acegisecurity/intercept/web/PathBasedFilterDefinitionMapTests.java b/core/src/test/java/org/acegisecurity/intercept/web/PathBasedFilterDefinitionMapTests.java index 3ca571a7e1..b4de8f40c2 100644 --- a/core/src/test/java/org/acegisecurity/intercept/web/PathBasedFilterDefinitionMapTests.java +++ b/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); } } diff --git a/core/src/test/java/org/acegisecurity/intercept/web/RegExpBasedFilterDefinitionMapTests.java b/core/src/test/java/org/acegisecurity/intercept/web/RegExpBasedFilterDefinitionMapTests.java index 3c3c819c3b..7645abf822 100644 --- a/core/src/test/java/org/acegisecurity/intercept/web/RegExpBasedFilterDefinitionMapTests.java +++ b/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); } } diff --git a/doc/xdocs/changes.xml b/doc/xdocs/changes.xml index 1efccf8e2f..7bff6a930f 100644 --- a/doc/xdocs/changes.xml +++ b/doc/xdocs/changes.xml @@ -45,6 +45,7 @@ Added AbstractProcessingFilter property to always use defaultTargetUrl Improved BasicAclProvider to only respond to specified ACL object requests Refactored MethodDefinitionSource to work with Method, not MethodInvocation + Refactored AbstractFilterInvocationDefinitionSource to work with URL Strings alone Refactored AbstractSecurityInterceptor to better support other AOP libraries Improved performance of JBoss container adapter (see reference docs) Made DaoAuthenticationProvider detect null in Authentication.principal