Added FilterInvocationDefinition interface to unify FilterInvocationDefinitionSource and FilterInvocationDefinitionMap
This commit is contained in:
parent
9e87bd6789
commit
46af400466
|
@ -0,0 +1,27 @@
|
||||||
|
/* 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.acegisecurity.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 {
|
||||||
|
}
|
|
@ -22,23 +22,31 @@ import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
import org.acegisecurity.SecurityConfig;
|
import org.acegisecurity.SecurityConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorator of {@link FilterInvocationDefinitionMap} for easier configuration,
|
* <p>
|
||||||
|
* Decorator of {@link FilterInvocationDefinition} for easier configuration,
|
||||||
* using {@link FilterInvocationDefinitionSourceMapping}.
|
* using {@link FilterInvocationDefinitionSourceMapping}.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* Delegates all calls to decorated object set in constructor
|
||||||
|
* {@link #FilterInvocationDefinitionDecorator(FilterInvocationDefinition)} or
|
||||||
|
* by calling {@link #setDecorated(FilterInvocationDefinition)}
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
|
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
public class FilterInvocationDefinitionMapDecorator {
|
public class FilterInvocationDefinitionDecorator implements FilterInvocationDefinition {
|
||||||
|
|
||||||
private FilterInvocationDefinitionMap decorated;
|
private FilterInvocationDefinition decorated;
|
||||||
|
|
||||||
private List mappings;
|
private List mappings;
|
||||||
|
|
||||||
public FilterInvocationDefinitionMapDecorator() {
|
public FilterInvocationDefinitionDecorator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FilterInvocationDefinitionMapDecorator(
|
public FilterInvocationDefinitionDecorator(FilterInvocationDefinition decorated) {
|
||||||
FilterInvocationDefinitionMap decorated) {
|
|
||||||
this.setDecorated(decorated);
|
this.setDecorated(decorated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,18 +54,18 @@ public class FilterInvocationDefinitionMapDecorator {
|
||||||
* Set the decorated object
|
* Set the decorated object
|
||||||
*
|
*
|
||||||
* @param decorated
|
* @param decorated
|
||||||
* the decorated {@link FilterInvocationDefinitionMap}
|
* the decorated {@link FilterInvocationDefinition}
|
||||||
*/
|
*/
|
||||||
public void setDecorated(FilterInvocationDefinitionMap decorated) {
|
public void setDecorated(FilterInvocationDefinition decorated) {
|
||||||
this.decorated = decorated;
|
this.decorated = decorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get decorated object
|
* Get decorated object
|
||||||
*
|
*
|
||||||
* @return the decorated {@link FilterInvocationDefinitionMap}
|
* @return the decorated {@link FilterInvocationDefinition}
|
||||||
*/
|
*/
|
||||||
public FilterInvocationDefinitionMap getDecorated() {
|
public FilterInvocationDefinition getDecorated() {
|
||||||
return decorated;
|
return decorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,12 +86,10 @@ public class FilterInvocationDefinitionMapDecorator {
|
||||||
this.mappings = mappings;
|
this.mappings = mappings;
|
||||||
Iterator it = mappings.iterator();
|
Iterator it = mappings.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
FilterInvocationDefinitionSourceMapping mapping = (FilterInvocationDefinitionSourceMapping) it
|
FilterInvocationDefinitionSourceMapping mapping = (FilterInvocationDefinitionSourceMapping) it.next();
|
||||||
.next();
|
|
||||||
ConfigAttributeDefinition configDefinition = new ConfigAttributeDefinition();
|
ConfigAttributeDefinition configDefinition = new ConfigAttributeDefinition();
|
||||||
|
|
||||||
Iterator configAttributesIt = mapping.getConfigAttributes()
|
Iterator configAttributesIt = mapping.getConfigAttributes().iterator();
|
||||||
.iterator();
|
|
||||||
while (configAttributesIt.hasNext()) {
|
while (configAttributesIt.hasNext()) {
|
||||||
String s = (String) configAttributesIt.next();
|
String s = (String) configAttributesIt.next();
|
||||||
configDefinition.addConfigAttribute(new SecurityConfig(s));
|
configDefinition.addConfigAttribute(new SecurityConfig(s));
|
||||||
|
@ -102,4 +108,46 @@ public class FilterInvocationDefinitionMapDecorator {
|
||||||
public List getMappings() {
|
public List getMappings() {
|
||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate to decorated object
|
||||||
|
*/
|
||||||
|
public void addSecureUrl(String expression, ConfigAttributeDefinition attr) {
|
||||||
|
getDecorated().addSecureUrl(expression, attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate to decorated object
|
||||||
|
*/
|
||||||
|
public boolean isConvertUrlToLowercaseBeforeComparison() {
|
||||||
|
return getDecorated().isConvertUrlToLowercaseBeforeComparison();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate to decorated object
|
||||||
|
*/
|
||||||
|
public void setConvertUrlToLowercaseBeforeComparison(boolean convertUrlToLowercaseBeforeComparison) {
|
||||||
|
getDecorated().setConvertUrlToLowercaseBeforeComparison(convertUrlToLowercaseBeforeComparison);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate to decorated object
|
||||||
|
*/
|
||||||
|
public ConfigAttributeDefinition getAttributes(Object object) throws IllegalArgumentException {
|
||||||
|
return getDecorated().getAttributes(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate to decorated object
|
||||||
|
*/
|
||||||
|
public Iterator getConfigAttributeDefinitions() {
|
||||||
|
return getDecorated().getConfigAttributeDefinitions();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate to decorated object
|
||||||
|
*/
|
||||||
|
public boolean supports(Class clazz) {
|
||||||
|
return getDecorated().supports(clazz);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -49,14 +49,15 @@ public class FilterInvocationDefinitionSourceEditor extends PropertyEditorSuppor
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
public void setAsText(String s) throws IllegalArgumentException {
|
public void setAsText(String s) throws IllegalArgumentException {
|
||||||
FilterInvocationDefinitionMap source = new RegExpBasedFilterInvocationDefinitionMap();
|
FilterInvocationDefinitionDecorator source = new FilterInvocationDefinitionDecorator();
|
||||||
|
source.setDecorated(new RegExpBasedFilterInvocationDefinitionMap());
|
||||||
|
|
||||||
if ((s == null) || "".equals(s)) {
|
if ((s == null) || "".equals(s)) {
|
||||||
// Leave target object empty
|
// Leave target object empty
|
||||||
} else {
|
} else {
|
||||||
// Check if we need to override the default definition map
|
// Check if we need to override the default definition map
|
||||||
if (s.lastIndexOf(DIRECTIVE_PATTERN_TYPE_APACHE_ANT) != -1) {
|
if (s.lastIndexOf(DIRECTIVE_PATTERN_TYPE_APACHE_ANT) != -1) {
|
||||||
source = new PathBasedFilterInvocationDefinitionMap();
|
source.setDecorated(new PathBasedFilterInvocationDefinitionMap());
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(("Detected " + DIRECTIVE_PATTERN_TYPE_APACHE_ANT
|
logger.debug(("Detected " + DIRECTIVE_PATTERN_TYPE_APACHE_ANT
|
||||||
|
@ -139,7 +140,7 @@ public class FilterInvocationDefinitionSourceEditor extends PropertyEditorSuppor
|
||||||
|
|
||||||
// Attempt to detect malformed lines (as per SEC-204)
|
// Attempt to detect malformed lines (as per SEC-204)
|
||||||
if (source.isConvertUrlToLowercaseBeforeComparison()
|
if (source.isConvertUrlToLowercaseBeforeComparison()
|
||||||
&& source instanceof PathBasedFilterInvocationDefinitionMap) {
|
&& source.getDecorated() instanceof PathBasedFilterInvocationDefinitionMap) {
|
||||||
// Should all be lowercase; check each character
|
// Should all be lowercase; check each character
|
||||||
// We only do this for Ant (regexp have control chars)
|
// We only do this for Ant (regexp have control chars)
|
||||||
for (int i = 0; i < name.length(); i++) {
|
for (int i = 0; i < name.length(); i++) {
|
||||||
|
@ -166,9 +167,7 @@ public class FilterInvocationDefinitionSourceEditor extends PropertyEditorSuppor
|
||||||
|
|
||||||
mappings.add(mapping);
|
mappings.add(mapping);
|
||||||
}
|
}
|
||||||
FilterInvocationDefinitionMapDecorator decorator = new FilterInvocationDefinitionMapDecorator(
|
source.setMappings(mappings);
|
||||||
source);
|
|
||||||
decorator.setMappings(mappings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue(source);
|
setValue(source);
|
||||||
|
|
|
@ -44,7 +44,7 @@ import java.util.Vector;
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class PathBasedFilterInvocationDefinitionMap extends AbstractFilterInvocationDefinitionSource
|
public class PathBasedFilterInvocationDefinitionMap extends AbstractFilterInvocationDefinitionSource
|
||||||
implements FilterInvocationDefinitionMap {
|
implements FilterInvocationDefinition {
|
||||||
//~ Static fields/initializers =====================================================================================
|
//~ Static fields/initializers =====================================================================================
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(PathBasedFilterInvocationDefinitionMap.class);
|
private static final Log logger = LogFactory.getLog(PathBasedFilterInvocationDefinitionMap.class);
|
||||||
|
|
|
@ -45,7 +45,7 @@ import java.util.Vector;
|
||||||
* <p>If no registered regular expressions match the HTTP URL, <code>null</code> is returned.</p>
|
* <p>If no registered regular expressions match the HTTP URL, <code>null</code> is returned.</p>
|
||||||
*/
|
*/
|
||||||
public class RegExpBasedFilterInvocationDefinitionMap extends AbstractFilterInvocationDefinitionSource
|
public class RegExpBasedFilterInvocationDefinitionMap extends AbstractFilterInvocationDefinitionSource
|
||||||
implements FilterInvocationDefinitionMap {
|
implements FilterInvocationDefinition {
|
||||||
//~ Static fields/initializers =====================================================================================
|
//~ Static fields/initializers =====================================================================================
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(RegExpBasedFilterInvocationDefinitionMap.class);
|
private static final Log logger = LogFactory.getLog(RegExpBasedFilterInvocationDefinitionMap.class);
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
/* 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.acegisecurity.intercept.web;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.acegisecurity.ConfigAttributeDefinition;
|
||||||
|
import org.acegisecurity.SecurityConfig;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for {@link FilterInvocationDefinitionDecorator}
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class FilterInvocationDefinitionDecoratorTest extends TestCase {
|
||||||
|
|
||||||
|
private FilterInvocationDefinitionDecorator decorator;
|
||||||
|
|
||||||
|
private FilterInvocationDefinition decorated;
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
decorated = new MockFilterInvocationDefinition();
|
||||||
|
decorator = new FilterInvocationDefinitionDecorator(decorated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFilterInvocationDefinitionMapDecorator() {
|
||||||
|
decorator = new FilterInvocationDefinitionDecorator();
|
||||||
|
decorator.setDecorated(decorated);
|
||||||
|
assertEquals(decorated, decorator.getDecorated());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSetMappings() {
|
||||||
|
List roles = new ArrayList();
|
||||||
|
roles.add("ROLE_USER");
|
||||||
|
roles.add("ROLE_ADMIN");
|
||||||
|
|
||||||
|
FilterInvocationDefinitionSourceMapping mapping = new FilterInvocationDefinitionSourceMapping();
|
||||||
|
mapping.setUrl("/secure/**");
|
||||||
|
mapping.setConfigAttributes(roles);
|
||||||
|
|
||||||
|
List mappings = new ArrayList();
|
||||||
|
mappings.add(mapping);
|
||||||
|
|
||||||
|
decorator.setMappings(mappings);
|
||||||
|
|
||||||
|
ConfigAttributeDefinition configDefinition = new ConfigAttributeDefinition();
|
||||||
|
Iterator it = roles.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
String role = (String) it.next();
|
||||||
|
configDefinition.addConfigAttribute(new SecurityConfig(role));
|
||||||
|
}
|
||||||
|
|
||||||
|
it = decorator.getConfigAttributeDefinitions();
|
||||||
|
int i = 0;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
i++;
|
||||||
|
assertEquals(configDefinition, it.next());
|
||||||
|
}
|
||||||
|
assertEquals(1, i);
|
||||||
|
|
||||||
|
assertEquals(mappings, decorator.getMappings());
|
||||||
|
}
|
||||||
|
}
|
|
@ -241,7 +241,7 @@ public class FilterSecurityInterceptorTests extends TestCase {
|
||||||
PathBasedFilterInvocationDefinitionMap filterInvocationDefinitionSource = new PathBasedFilterInvocationDefinitionMap();
|
PathBasedFilterInvocationDefinitionMap filterInvocationDefinitionSource = new PathBasedFilterInvocationDefinitionMap();
|
||||||
filterInvocationDefinitionSource
|
filterInvocationDefinitionSource
|
||||||
.setConvertUrlToLowercaseBeforeComparison(true);
|
.setConvertUrlToLowercaseBeforeComparison(true);
|
||||||
FilterInvocationDefinitionMapDecorator decorator = new FilterInvocationDefinitionMapDecorator(
|
FilterInvocationDefinitionDecorator decorator = new FilterInvocationDefinitionDecorator(
|
||||||
filterInvocationDefinitionSource);
|
filterInvocationDefinitionSource);
|
||||||
decorator.setMappings(mappings);
|
decorator.setMappings(mappings);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/* 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.acegisecurity.intercept.web;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.acegisecurity.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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue