15 changed files with 94 additions and 610 deletions
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
/* Copyright 2006 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.security.intercept.web; |
||||
|
||||
/** |
||||
* Interface to join {@link FilterInvocationDefinitionMap} and |
||||
* {@link FilterInvocationDefinitionSource}. |
||||
* |
||||
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> |
||||
* @version $Id$ |
||||
* @since 1.1 |
||||
*/ |
||||
public interface FilterInvocationDefinition extends FilterInvocationDefinitionMap, FilterInvocationDefinitionSource { |
||||
} |
||||
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.security.intercept.web; |
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition; |
||||
|
||||
|
||||
/** |
||||
* Exposes methods required so that a property editor can populate the relevant |
||||
* {@link FilterInvocationDefinitionSource}. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public interface FilterInvocationDefinitionMap { |
||||
//~ Methods ========================================================================================================
|
||||
|
||||
void addSecureUrl(String expression, ConfigAttributeDefinition attr); |
||||
|
||||
boolean isConvertUrlToLowercaseBeforeComparison(); |
||||
|
||||
void setConvertUrlToLowercaseBeforeComparison(boolean convertUrlToLowercaseBeforeComparison); |
||||
} |
||||
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.security.intercept.web; |
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition; |
||||
import org.springframework.security.util.AntUrlPathMatcher; |
||||
|
||||
/** |
||||
* Extends DefaultFilterInvocationDefinitionSource, configuring it with a {@link AntUrlPathMatcher} to match URLs |
||||
* using Apache Ant path-based patterns. |
||||
* <p> |
||||
* Apache Ant path expressions are used to match a HTTP request URL against a <code>ConfigAttributeDefinition</code>. |
||||
* <p> |
||||
* The order of registering the Ant paths using the {@link #addSecureUrl(String,ConfigAttributeDefinition)} is |
||||
* very important. The system will identify the <b>first</b> matching path for a given HTTP URL. It will not proceed |
||||
* to evaluate later paths if a match has already been found. Accordingly, the most specific paths should be |
||||
* registered first, with the most general paths registered last. |
||||
* <p> |
||||
* If no registered paths match the HTTP URL, <code>null</code> is returned. |
||||
* <p> |
||||
* Note that as of 2.0, lower case URL comparisons are made by default, as this is the default strategy for |
||||
* <tt>AntUrlPathMatcher</tt>. |
||||
* |
||||
* @author Ben Alex |
||||
* @author Luke taylor |
||||
* @deprecated DefaultFilterInvocationDefinitionSource should now be used with an AntUrlPathMatcher instead. |
||||
* @version $Id$ |
||||
*/ |
||||
public class PathBasedFilterInvocationDefinitionMap extends DefaultFilterInvocationDefinitionSource |
||||
implements FilterInvocationDefinition { |
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public PathBasedFilterInvocationDefinitionMap() { |
||||
super(new AntUrlPathMatcher()); |
||||
setStripQueryStringFromUrls(true); |
||||
} |
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void addSecureUrl(String antPath, String method, ConfigAttributeDefinition attr) { |
||||
// SEC-501: If using lower case comparison, we should convert the paths to lower case
|
||||
// as any upper case characters included by mistake will prevent the URL from ever being matched.
|
||||
// This shouldn't be needed anymore. The property editor complains if there is upper case text in the URL
|
||||
// and the namespace implementation does the conversion itself, so it is safe to use the parent class
|
||||
// directly.
|
||||
if (getUrlMatcher().requiresLowerCaseUrl()) { |
||||
antPath = antPath.toLowerCase(); |
||||
} |
||||
|
||||
super.addSecureUrl(antPath, method, attr); |
||||
} |
||||
|
||||
public void setConvertUrlToLowercaseBeforeComparison(boolean bool) { |
||||
((AntUrlPathMatcher)getUrlMatcher()).setRequiresLowerCaseUrl(bool); |
||||
} |
||||
} |
||||
@ -1,42 +0,0 @@
@@ -1,42 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.security.intercept.web; |
||||
|
||||
import org.springframework.security.util.RegexUrlPathMatcher; |
||||
|
||||
|
||||
/** |
||||
* Configures an {@link DefaultFilterInvocationDefinitionSource} with a regular expression URL matching strategy |
||||
* {@link RegexUrlPathMatcher}. |
||||
* |
||||
* @author Ben Alex |
||||
* @author Luke Taylor |
||||
* @deprecated |
||||
* @version $Id$ |
||||
*/ |
||||
public class RegExpBasedFilterInvocationDefinitionMap extends DefaultFilterInvocationDefinitionSource |
||||
implements FilterInvocationDefinition { |
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public RegExpBasedFilterInvocationDefinitionMap() { |
||||
super(new RegexUrlPathMatcher()); |
||||
} |
||||
|
||||
public void setConvertUrlToLowercaseBeforeComparison(boolean bool) { |
||||
((RegexUrlPathMatcher)getUrlMatcher()).setRequiresLowerCaseUrl(bool); |
||||
} |
||||
} |
||||
@ -1,197 +0,0 @@
@@ -1,197 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.security.intercept.web; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition; |
||||
import org.springframework.security.MockFilterChain; |
||||
import org.springframework.security.SecurityConfig; |
||||
import org.springframework.security.util.AntUrlPathMatcher; |
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
import org.springframework.mock.web.MockHttpServletResponse; |
||||
|
||||
import java.util.Iterator; |
||||
|
||||
|
||||
/** |
||||
* Tests {@link FilterInvocationDefinitionSourceEditor} and its associated {@link |
||||
* PathBasedFilterInvocationDefinitionMap}. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class FilterInvocationDefinitionSourceEditorWithPathsTests extends TestCase { |
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public FilterInvocationDefinitionSourceEditorWithPathsTests() { |
||||
super(); |
||||
} |
||||
|
||||
public FilterInvocationDefinitionSourceEditorWithPathsTests(String arg0) { |
||||
super(arg0); |
||||
} |
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testAntPathDirectiveIsDetected() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText( |
||||
"PATTERN_TYPE_APACHE_ANT\r\n/secure/super/*=ROLE_WE_DONT_HAVE\r\n/secure/*=ROLE_SUPERVISOR,ROLE_TELLER"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
assertTrue(map.getUrlMatcher() instanceof AntUrlPathMatcher); |
||||
} |
||||
|
||||
public void testConvertUrlToLowercaseDefaultSettingUnchangedByEditor() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText( |
||||
"PATTERN_TYPE_APACHE_ANT\r\n/secure/super/*=ROLE_WE_DONT_HAVE\r\n/secure/*=ROLE_SUPERVISOR,ROLE_TELLER"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
assertFalse(map.getUrlMatcher().requiresLowerCaseUrl()); |
||||
} |
||||
|
||||
public void testConvertUrlToLowercaseSettingApplied() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText( |
||||
"CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON\r\nPATTERN_TYPE_APACHE_ANT\r\n/secure/super/*=ROLE_WE_DONT_HAVE\r\n/secure/*=ROLE_SUPERVISOR,ROLE_TELLER"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
assertTrue(map.getUrlMatcher().requiresLowerCaseUrl()); |
||||
} |
||||
|
||||
public void testInvalidNameValueFailsToParse() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
|
||||
try { |
||||
// Use a "==" instead of an "="
|
||||
editor.setAsText(" PATTERN_TYPE_APACHE_ANT\r\n /secure/*==ROLE_SUPERVISOR,ROLE_TELLER \r\n"); |
||||
fail("Shouldn't be able to use '==' for config attribute."); |
||||
} catch (IllegalArgumentException expected) {} |
||||
} |
||||
|
||||
public void testIterator() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText( |
||||
"PATTERN_TYPE_APACHE_ANT\r\n/secure/super/*=ROLE_WE_DONT_HAVE\r\n/secure/*=ROLE_SUPERVISOR,ROLE_TELLER"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
Iterator iter = map.getConfigAttributeDefinitions(); |
||||
int counter = 0; |
||||
|
||||
while (iter.hasNext()) { |
||||
iter.next(); |
||||
counter++; |
||||
} |
||||
|
||||
assertEquals(2, counter); |
||||
} |
||||
|
||||
public void testMapReturnsNullWhenNoMatchFound() throws Exception { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText("PATTERN_TYPE_APACHE_ANT\r\n/secure/super/*=ROLE_WE_DONT_HAVE"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
|
||||
MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null); |
||||
httpRequest.setServletPath("/totally/different/path/index.html"); |
||||
|
||||
ConfigAttributeDefinition returned = map.getAttributes(new FilterInvocation(httpRequest, |
||||
new MockHttpServletResponse(), new MockFilterChain())); |
||||
|
||||
assertEquals(null, returned); |
||||
} |
||||
|
||||
public void testMultiUrlParsing() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText( |
||||
"PATTERN_TYPE_APACHE_ANT\r\n/secure/super/*=ROLE_WE_DONT_HAVE\r\n/secure/*=ROLE_SUPERVISOR,ROLE_TELLER"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
assertEquals(2, map.getMapSize()); |
||||
} |
||||
|
||||
public void testOrderOfEntriesIsPreservedOrderA() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText( |
||||
"PATTERN_TYPE_APACHE_ANT\r\n/secure/super/**=ROLE_WE_DONT_HAVE,ANOTHER_ROLE\r\n/secure/**=ROLE_SUPERVISOR,ROLE_TELLER"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
|
||||
// Test ensures we match the first entry, not the second
|
||||
MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null); |
||||
httpRequest.setServletPath("/secure/super/very_secret.html"); |
||||
|
||||
ConfigAttributeDefinition returned = map.getAttributes(new FilterInvocation(httpRequest, |
||||
new MockHttpServletResponse(), new MockFilterChain())); |
||||
|
||||
ConfigAttributeDefinition expected = new ConfigAttributeDefinition(); |
||||
expected.addConfigAttribute(new SecurityConfig("ROLE_WE_DONT_HAVE")); |
||||
expected.addConfigAttribute(new SecurityConfig("ANOTHER_ROLE")); |
||||
|
||||
assertEquals(expected, returned); |
||||
} |
||||
|
||||
public void testOrderOfEntriesIsPreservedOrderB() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText( |
||||
"PATTERN_TYPE_APACHE_ANT\r\n/secure/**=ROLE_SUPERVISOR,ROLE_TELLER\r\n/secure/super/**=ROLE_WE_DONT_HAVE"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
|
||||
MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null); |
||||
httpRequest.setServletPath("/secure/super/very_secret.html"); |
||||
|
||||
ConfigAttributeDefinition returned = map.getAttributes(new FilterInvocation(httpRequest, |
||||
new MockHttpServletResponse(), new MockFilterChain())); |
||||
|
||||
ConfigAttributeDefinition expected = new ConfigAttributeDefinition(); |
||||
expected.addConfigAttribute(new SecurityConfig("ROLE_SUPERVISOR")); |
||||
expected.addConfigAttribute(new SecurityConfig("ROLE_TELLER")); |
||||
|
||||
assertEquals(expected, returned); |
||||
} |
||||
|
||||
public void testSingleUrlParsing() throws Exception { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText("PATTERN_TYPE_APACHE_ANT\r\n/secure/super/*=ROLE_WE_DONT_HAVE,ANOTHER_ROLE"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
|
||||
MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null); |
||||
httpRequest.setServletPath("/secure/super/very_secret.html"); |
||||
|
||||
ConfigAttributeDefinition returned = map.getAttributes(new FilterInvocation(httpRequest, |
||||
new MockHttpServletResponse(), new MockFilterChain())); |
||||
|
||||
ConfigAttributeDefinition expected = new ConfigAttributeDefinition(); |
||||
expected.addConfigAttribute(new SecurityConfig("ROLE_WE_DONT_HAVE")); |
||||
expected.addConfigAttribute(new SecurityConfig("ANOTHER_ROLE")); |
||||
|
||||
assertEquals(expected, returned); |
||||
} |
||||
|
||||
public void testWhitespaceAndCommentsAndLinesWithoutEqualsSignsAreIgnored() { |
||||
FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor(); |
||||
editor.setAsText( |
||||
" PATTERN_TYPE_APACHE_ANT\r\n /secure/super/*=ROLE_WE_DONT_HAVE\r\n /secure/*=ROLE_SUPERVISOR,ROLE_TELLER \r\n \r\n \r\n // comment line \r\n \r\n"); |
||||
|
||||
DefaultFilterInvocationDefinitionSource map = (DefaultFilterInvocationDefinitionSource) editor.getValue(); |
||||
assertEquals(2, map.getMapSize()); |
||||
} |
||||
} |
||||
@ -1,64 +0,0 @@
@@ -1,64 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.security.intercept.web; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Iterator; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition; |
||||
|
||||
/** |
||||
* Mock for {@link FilterInvocationDefinitionMap} |
||||
* |
||||
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> |
||||
* @version $Id: MockFilterInvocationDefinitionSource.java 1496 2006-05-23 |
||||
* 13:38:33Z benalex $ |
||||
*/ |
||||
public class MockFilterInvocationDefinition implements FilterInvocationDefinition { |
||||
|
||||
private Map secureUrls = new HashMap(); |
||||
|
||||
private boolean convertUrlToLowercaseBeforeComparison = false; |
||||
|
||||
public void addSecureUrl(String expression, ConfigAttributeDefinition attr) { |
||||
secureUrls.put(expression, attr); |
||||
} |
||||
|
||||
public boolean isConvertUrlToLowercaseBeforeComparison() { |
||||
return convertUrlToLowercaseBeforeComparison; |
||||
} |
||||
|
||||
public void setConvertUrlToLowercaseBeforeComparison(boolean convertUrlToLowercaseBeforeComparison) { |
||||
this.convertUrlToLowercaseBeforeComparison = convertUrlToLowercaseBeforeComparison; |
||||
} |
||||
|
||||
public ConfigAttributeDefinition getSecureUrl(String expression) { |
||||
return (ConfigAttributeDefinition) secureUrls.get(expression); |
||||
} |
||||
|
||||
public ConfigAttributeDefinition getAttributes(Object object) throws IllegalArgumentException { |
||||
return (ConfigAttributeDefinition) secureUrls.get(object); |
||||
} |
||||
|
||||
public Iterator getConfigAttributeDefinitions() { |
||||
return secureUrls.values().iterator(); |
||||
} |
||||
|
||||
public boolean supports(Class clazz) { |
||||
return true; |
||||
} |
||||
} |
||||
@ -1,121 +0,0 @@
@@ -1,121 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.security.intercept.web; |
||||
|
||||
import junit.framework.TestCase; |
||||
|
||||
import org.springframework.security.ConfigAttributeDefinition; |
||||
import org.springframework.security.MockFilterChain; |
||||
import org.springframework.security.SecurityConfig; |
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
import org.springframework.mock.web.MockHttpServletResponse; |
||||
|
||||
|
||||
/** |
||||
* Tests parts of {@link RegExpBasedFilterInvocationDefinitionMap} not tested by {@link |
||||
* FilterInvocationDefinitionSourceEditorTests}. |
||||
* |
||||
* @author Ben Alex |
||||
* @version $Id$ |
||||
*/ |
||||
public class RegExpBasedFilterDefinitionMapTests extends TestCase { |
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public RegExpBasedFilterDefinitionMapTests() { |
||||
} |
||||
|
||||
public RegExpBasedFilterDefinitionMapTests(String arg0) { |
||||
super(arg0); |
||||
} |
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testConvertUrlToLowercaseIsFalseByDefault() { |
||||
RegExpBasedFilterInvocationDefinitionMap map = new RegExpBasedFilterInvocationDefinitionMap(); |
||||
assertFalse(map.isConvertUrlToLowercaseBeforeComparison()); |
||||
} |
||||
|
||||
public void testConvertUrlToLowercaseSetterRespected() { |
||||
RegExpBasedFilterInvocationDefinitionMap map = new RegExpBasedFilterInvocationDefinitionMap(); |
||||
map.setConvertUrlToLowercaseBeforeComparison(true); |
||||
assertTrue(map.isConvertUrlToLowercaseBeforeComparison()); |
||||
} |
||||
|
||||
public void testLookupNotRequiringExactMatchSuccessIfNotMatching() { |
||||
RegExpBasedFilterInvocationDefinitionMap map = new RegExpBasedFilterInvocationDefinitionMap(); |
||||
map.setConvertUrlToLowercaseBeforeComparison(true); |
||||
assertTrue(map.isConvertUrlToLowercaseBeforeComparison()); |
||||
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition(); |
||||
def.addConfigAttribute(new SecurityConfig("ROLE_ONE")); |
||||
map.addSecureUrl("\\A/secure/super.*\\Z", def); |
||||
|
||||
// Build a HTTP request
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setRequestURI(null); |
||||
|
||||
MockHttpServletRequest req = request; |
||||
req.setServletPath("/SeCuRE/super/somefile.html"); |
||||
|
||||
FilterInvocation fi = new FilterInvocation(req, new MockHttpServletResponse(), new MockFilterChain()); |
||||
|
||||
ConfigAttributeDefinition response = map.lookupAttributes(fi.getRequestUrl()); |
||||
assertEquals(def, response); |
||||
} |
||||
|
||||
public void testLookupRequiringExactMatchFailsIfNotMatching() { |
||||
RegExpBasedFilterInvocationDefinitionMap map = new RegExpBasedFilterInvocationDefinitionMap(); |
||||
assertFalse(map.isConvertUrlToLowercaseBeforeComparison()); |
||||
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition(); |
||||
def.addConfigAttribute(new SecurityConfig("ROLE_ONE")); |
||||
map.addSecureUrl("\\A/secure/super.*\\Z", def); |
||||
|
||||
// Build a HTTP request
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setRequestURI(null); |
||||
|
||||
MockHttpServletRequest req = request; |
||||
req.setServletPath("/SeCuRE/super/somefile.html"); |
||||
|
||||
FilterInvocation fi = new FilterInvocation(req, new MockHttpServletResponse(), new MockFilterChain()); |
||||
|
||||
ConfigAttributeDefinition response = map.lookupAttributes(fi.getRequestUrl()); |
||||
assertEquals(null, response); |
||||
} |
||||
|
||||
public void testLookupRequiringExactMatchIsSuccessful() { |
||||
RegExpBasedFilterInvocationDefinitionMap map = new RegExpBasedFilterInvocationDefinitionMap(); |
||||
assertFalse(map.isConvertUrlToLowercaseBeforeComparison()); |
||||
|
||||
ConfigAttributeDefinition def = new ConfigAttributeDefinition(); |
||||
def.addConfigAttribute(new SecurityConfig("ROLE_ONE")); |
||||
map.addSecureUrl("\\A/secure/super.*\\Z", def); |
||||
|
||||
// Build a HTTP request
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(); |
||||
request.setRequestURI(null); |
||||
|
||||
MockHttpServletRequest req = request; |
||||
req.setServletPath("/secure/super/somefile.html"); |
||||
|
||||
FilterInvocation fi = new FilterInvocation(req, new MockHttpServletResponse(), new MockFilterChain()); |
||||
|
||||
ConfigAttributeDefinition response = map.lookupAttributes(fi.getRequestUrl()); |
||||
assertEquals(def, response); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue