From 5cd65887d533ebaac44cb4679638e972857ed565 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Wed, 25 Aug 2004 21:43:00 +0000 Subject: [PATCH] Improved ConfigAttributeEditor so it trims preceding and trailing spaces. --- changelog.txt | 1 + .../acegisecurity/ConfigAttributeEditor.java | 7 +++++- .../ConfigAttributeEditorTests.java | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 636bc4e8e6..2f98f29ad2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/core/src/main/java/org/acegisecurity/ConfigAttributeEditor.java b/core/src/main/java/org/acegisecurity/ConfigAttributeEditor.java index 9d47385f6a..789840aef5 100644 --- a/core/src/main/java/org/acegisecurity/ConfigAttributeEditor.java +++ b/core/src/main/java/org/acegisecurity/ConfigAttributeEditor.java @@ -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. + * + *

+ * 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. + *

* * @author Ben Alex * @version $Id$ @@ -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); diff --git a/core/src/test/java/org/acegisecurity/ConfigAttributeEditorTests.java b/core/src/test/java/org/acegisecurity/ConfigAttributeEditorTests.java index 5f3c89a492..4eae4fcf22 100644 --- a/core/src/test/java/org/acegisecurity/ConfigAttributeEditorTests.java +++ b/core/src/test/java/org/acegisecurity/ConfigAttributeEditorTests.java @@ -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 { 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");