Simplify configuration of FilterInvocationDefinitionMap

This commit is contained in:
Carlos Sanchez 2006-07-05 20:58:50 +00:00
parent 9d539a13d9
commit 9560636380
3 changed files with 168 additions and 9 deletions

View File

@ -0,0 +1,105 @@
/* 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.Iterator;
import java.util.List;
import org.acegisecurity.ConfigAttributeDefinition;
import org.acegisecurity.SecurityConfig;
/**
* Decorator of {@link FilterInvocationDefinitionMap} for easier configuration,
* using {@link FilterInvocationDefinitionSourceMapping}.
*
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @version $Id$
*/
public class FilterInvocationDefinitionMapDecorator {
private FilterInvocationDefinitionMap decorated;
private List mappings;
public FilterInvocationDefinitionMapDecorator() {
}
public FilterInvocationDefinitionMapDecorator(
FilterInvocationDefinitionMap decorated) {
this.setDecorated(decorated);
}
/**
* Set the decorated object
*
* @param decorated
* the decorated {@link FilterInvocationDefinitionMap}
*/
public void setDecorated(FilterInvocationDefinitionMap decorated) {
this.decorated = decorated;
}
/**
* Get decorated object
*
* @return the decorated {@link FilterInvocationDefinitionMap}
*/
public FilterInvocationDefinitionMap getDecorated() {
return decorated;
}
/**
* Configures the decorated {@link FilterInvocationDefinitionMap} easier,
* using {@link FilterInvocationDefinitionSourceMapping}.
*
* @param mappings
* {@link List} of
* {@link FilterInvocationDefinitionSourceMapping} objects.
*/
public void setMappings(List mappings) {
if (decorated == null) {
throw new IllegalStateException("decorated object has not been set");
}
this.mappings = mappings;
Iterator it = mappings.iterator();
while (it.hasNext()) {
FilterInvocationDefinitionSourceMapping mapping = (FilterInvocationDefinitionSourceMapping) it
.next();
ConfigAttributeDefinition configDefinition = new ConfigAttributeDefinition();
Iterator configAttributesIt = mapping.getConfigAttributes()
.iterator();
while (configAttributesIt.hasNext()) {
String s = (String) configAttributesIt.next();
configDefinition.addConfigAttribute(new SecurityConfig(s));
}
decorated.addSecureUrl(mapping.getUrl(), configDefinition);
}
}
/**
* Get the mappings used for configuration.
*
* @return {@link List} of {@link FilterInvocationDefinitionSourceMapping}
* objects.
*/
public List getMappings() {
return mappings;
}
}

View File

@ -15,9 +15,6 @@
package org.acegisecurity.intercept.web;
import org.acegisecurity.ConfigAttributeDefinition;
import org.acegisecurity.ConfigAttributeEditor;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -27,6 +24,8 @@ import java.beans.PropertyEditorSupport;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
/**
@ -77,6 +76,8 @@ public class FilterInvocationDefinitionSourceEditor extends PropertyEditorSuppor
BufferedReader br = new BufferedReader(new StringReader(s));
int counter = 0;
String line;
List mappings = new ArrayList();
while (true) {
counter++;
@ -153,15 +154,21 @@ public class FilterInvocationDefinitionSourceEditor extends PropertyEditorSuppor
}
}
// Convert value to series of security configuration attributes
ConfigAttributeEditor configAttribEd = new ConfigAttributeEditor();
configAttribEd.setAsText(value);
FilterInvocationDefinitionSourceMapping mapping = new FilterInvocationDefinitionSourceMapping();
mapping.setUrl(name);
ConfigAttributeDefinition attr = (ConfigAttributeDefinition) configAttribEd.getValue();
String[] tokens = org.springframework.util.StringUtils
.commaDelimitedListToStringArray(value);
// Register the regular expression and its attribute
source.addSecureUrl(name, attr);
for (int i = 0; i < tokens.length; i++) {
mapping.addConfigAttribute(tokens[i].trim());
}
mappings.add(mapping);
}
FilterInvocationDefinitionMapDecorator decorator = new FilterInvocationDefinitionMapDecorator(
source);
decorator.setMappings(mappings);
}
setValue(source);

View File

@ -0,0 +1,47 @@
/* 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.List;
public class FilterInvocationDefinitionSourceMapping {
private String url;
private List configAttributes = new ArrayList();
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
public void setConfigAttributes(List roles) {
this.configAttributes = roles;
}
public List getConfigAttributes() {
return configAttributes;
}
public void addConfigAttribute(String configAttribute) {
configAttributes.add(configAttribute);
}
}