diff --git a/core/src/main/java/org/acegisecurity/userdetails/memory/UserAttribute.java b/core/src/main/java/org/acegisecurity/userdetails/memory/UserAttribute.java index 55c3465915..4709b1c57c 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/memory/UserAttribute.java +++ b/core/src/main/java/org/acegisecurity/userdetails/memory/UserAttribute.java @@ -18,6 +18,8 @@ package org.acegisecurity.userdetails.memory; import org.acegisecurity.GrantedAuthority; import org.acegisecurity.GrantedAuthorityImpl; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Vector; @@ -63,6 +65,22 @@ public class UserAttribute { this.authorities = authorities; } + /** + * Set all authorities for this user from String values. + * It will create the necessary {@link GrantedAuthority} objects. + * + * @param authoritiesAsString {@link List} <{@link String}> + * @since 1.1 + */ + public void setAuthoritiesAsString(List authoritiesAsString) { + setAuthorities(new ArrayList(authoritiesAsString.size())); + Iterator it = authoritiesAsString.iterator(); + while (it.hasNext()) { + GrantedAuthority grantedAuthority = new GrantedAuthorityImpl((String) it.next()); + addAuthority(grantedAuthority); + } + } + public String getPassword() { return password; } diff --git a/core/src/main/java/org/acegisecurity/userdetails/memory/UserAttributeEditor.java b/core/src/main/java/org/acegisecurity/userdetails/memory/UserAttributeEditor.java index 80d7d8bacc..02856851dd 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/memory/UserAttributeEditor.java +++ b/core/src/main/java/org/acegisecurity/userdetails/memory/UserAttributeEditor.java @@ -15,13 +15,12 @@ package org.acegisecurity.userdetails.memory; -import org.acegisecurity.GrantedAuthorityImpl; +import java.beans.PropertyEditorSupport; +import java.util.ArrayList; +import java.util.List; import org.springframework.util.StringUtils; -import java.beans.PropertyEditorSupport; - - /** * Property editor that creates a {@link UserAttribute} from a comma separated list of values. * @@ -35,6 +34,8 @@ public class UserAttributeEditor extends PropertyEditorSupport { if (StringUtils.hasText(s)) { String[] tokens = StringUtils.commaDelimitedListToStringArray(s); UserAttribute userAttrib = new UserAttribute(); + + List authoritiesAsString = new ArrayList(); for (int i = 0; i < tokens.length; i++) { String currentToken = tokens[i].trim(); @@ -47,10 +48,11 @@ public class UserAttributeEditor extends PropertyEditorSupport { } else if (currentToken.toLowerCase().equals("disabled")) { userAttrib.setEnabled(false); } else { - userAttrib.addAuthority(new GrantedAuthorityImpl(currentToken)); + authoritiesAsString.add(currentToken); } } } + userAttrib.setAuthoritiesAsString(authoritiesAsString); if (userAttrib.isValid()) { setValue(userAttrib);