1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.userdetails.memory;
17
18 import java.beans.PropertyEditorSupport;
19
20 import org.acegisecurity.GrantedAuthorityImpl;
21 import org.springframework.util.StringUtils;
22
23
24 /***
25 * Property editor that creates a {@link UserAttribute} from a comma separated
26 * list of values.
27 *
28 * @author Ben Alex
29 * @version $Id: UserAttributeEditor.java,v 1.6 2005/11/29 13:10:09 benalex Exp $
30 */
31 public class UserAttributeEditor extends PropertyEditorSupport {
32
33
34 public void setAsText(String s) throws IllegalArgumentException {
35 if (StringUtils.hasText(s)) {
36 String[] tokens = StringUtils.commaDelimitedListToStringArray(s);
37 UserAttribute userAttrib = new UserAttribute();
38
39 for (int i = 0; i < tokens.length; i++) {
40 String currentToken = tokens[i].trim();
41
42 if (i == 0) {
43 userAttrib.setPassword(currentToken);
44 } else {
45 if (currentToken.toLowerCase().equals("enabled")) {
46 userAttrib.setEnabled(true);
47 } else if (currentToken.toLowerCase().equals("disabled")) {
48 userAttrib.setEnabled(false);
49 } else {
50 userAttrib.addAuthority(new GrantedAuthorityImpl(
51 currentToken));
52 }
53 }
54 }
55
56 if (userAttrib.isValid()) {
57 setValue(userAttrib);
58 } else {
59 setValue(null);
60 }
61 } else {
62 setValue(null);
63 }
64 }
65 }