Add setAuthoritiesAsString to UserAttribute
This commit is contained in:
parent
000f9ab7ac
commit
4d070eab25
|
@ -18,6 +18,8 @@ package org.acegisecurity.userdetails.memory;
|
||||||
import org.acegisecurity.GrantedAuthority;
|
import org.acegisecurity.GrantedAuthority;
|
||||||
import org.acegisecurity.GrantedAuthorityImpl;
|
import org.acegisecurity.GrantedAuthorityImpl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
@ -63,6 +65,22 @@ public class UserAttribute {
|
||||||
this.authorities = authorities;
|
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() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,12 @@
|
||||||
|
|
||||||
package org.acegisecurity.userdetails.memory;
|
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 org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.beans.PropertyEditorSupport;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property editor that creates a {@link UserAttribute} from a comma separated list of values.
|
* 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)) {
|
if (StringUtils.hasText(s)) {
|
||||||
String[] tokens = StringUtils.commaDelimitedListToStringArray(s);
|
String[] tokens = StringUtils.commaDelimitedListToStringArray(s);
|
||||||
UserAttribute userAttrib = new UserAttribute();
|
UserAttribute userAttrib = new UserAttribute();
|
||||||
|
|
||||||
|
List authoritiesAsString = new ArrayList();
|
||||||
|
|
||||||
for (int i = 0; i < tokens.length; i++) {
|
for (int i = 0; i < tokens.length; i++) {
|
||||||
String currentToken = tokens[i].trim();
|
String currentToken = tokens[i].trim();
|
||||||
|
@ -47,10 +48,11 @@ public class UserAttributeEditor extends PropertyEditorSupport {
|
||||||
} else if (currentToken.toLowerCase().equals("disabled")) {
|
} else if (currentToken.toLowerCase().equals("disabled")) {
|
||||||
userAttrib.setEnabled(false);
|
userAttrib.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
userAttrib.addAuthority(new GrantedAuthorityImpl(currentToken));
|
authoritiesAsString.add(currentToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userAttrib.setAuthoritiesAsString(authoritiesAsString);
|
||||||
|
|
||||||
if (userAttrib.isValid()) {
|
if (userAttrib.isValid()) {
|
||||||
setValue(userAttrib);
|
setValue(userAttrib);
|
||||||
|
|
Loading…
Reference in New Issue