Browse Source

Improved ConfigAttributeEditor so it trims preceding and trailing spaces.

1.0.x
Ben Alex 22 years ago
parent
commit
5cd65887d5
  1. 1
      changelog.txt
  2. 7
      core/src/main/java/org/acegisecurity/ConfigAttributeEditor.java
  3. 22
      core/src/test/java/org/acegisecurity/ConfigAttributeEditorTests.java

1
changelog.txt

@ -4,6 +4,7 @@ Changes in version 0.x (2004-xx-xx) @@ -4,6 +4,7 @@ Changes in version 0.x (2004-xx-xx)
* Added additional DaoAuthenticationProvider event when user not found
* Added Authentication.getDetails() to DaoAuthenticationProvider response
* Extracted removeUserFromCache(String) to UserCache interface
* Improved ConfigAttributeEditor so it trims preceding and trailing spaces
* Fixed EH-CACHE-based caching implementation behaviour when cache exists
* Fixed Ant "release" target not including project.properties
* Fixed GrantedAuthorityEffectiveAclsResolver if null ACLs provided to method

7
core/src/main/java/org/acegisecurity/ConfigAttributeEditor.java

@ -23,6 +23,11 @@ import java.beans.PropertyEditorSupport; @@ -23,6 +23,11 @@ import java.beans.PropertyEditorSupport;
/**
* A property editor that can create a populated {@link
* ConfigAttributeDefinition} from a comma separated list of values.
*
* <P>
* Trims preceding and trailing spaces from presented command separated tokens,
* as this can be a source of hard-to-spot configuration issues for end users.
* </p>
*
* @author Ben Alex
* @version $Id$
@ -39,7 +44,7 @@ public class ConfigAttributeEditor extends PropertyEditorSupport { @@ -39,7 +44,7 @@ public class ConfigAttributeEditor extends PropertyEditorSupport {
for (int i = 0; i < tokens.length; i++) {
configDefinition.addConfigAttribute(new SecurityConfig(
tokens[i]));
tokens[i].trim()));
}
setValue(configDefinition);

22
core/src/test/java/org/acegisecurity/ConfigAttributeEditorTests.java

@ -17,6 +17,7 @@ package net.sf.acegisecurity; @@ -17,6 +17,7 @@ package net.sf.acegisecurity;
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.Iterator;
@ -126,6 +127,27 @@ public class ConfigAttributeEditorTests extends TestCase { @@ -126,6 +127,27 @@ public class ConfigAttributeEditorTests extends TestCase {
assertTrue(result == null);
}
public void testStripsTrailingAndLeadingSpaces() {
ConfigAttributeEditor editor = new ConfigAttributeEditor();
editor.setAsText(" HELLO, DOCTOR,NAME, YESTERDAY ,TOMORROW ");
ConfigAttributeDefinition result = (ConfigAttributeDefinition) editor
.getValue();
Iterator iter = result.getConfigAttributes();
ArrayList list = new ArrayList();
while (iter.hasNext()) {
list.add(iter.next());
}
assertEquals("HELLO", ((ConfigAttribute) list.get(0)).getAttribute());
assertEquals("DOCTOR", ((ConfigAttribute) list.get(1)).getAttribute());
assertEquals("NAME", ((ConfigAttribute) list.get(2)).getAttribute());
assertEquals("YESTERDAY", ((ConfigAttribute) list.get(3)).getAttribute());
assertEquals("TOMORROW", ((ConfigAttribute) list.get(4)).getAttribute());
}
public void testToString() {
ConfigAttributeEditor editor = new ConfigAttributeEditor();
editor.setAsText("KOALA,KANGAROO,EMU,WOMBAT");

Loading…
Cancel
Save