1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.mobility.security.authz.expression;
17
18 import org.kuali.mobility.security.user.api.User;
19 import org.kuali.mobility.security.user.entity.UserAttribute;
20
21 import java.util.List;
22
23 public class PersonAttributeExpression implements Expression {
24
25 private static final long serialVersionUID = 4461424607920854636L;
26
27 private String key;
28
29 private String value;
30
31 public PersonAttributeExpression(String key, String value) {
32 this.key = key;
33 this.value = value;
34 }
35
36 public boolean evaluate(User user) {
37 boolean success = false;
38 List<UserAttribute> attributes = user.getAttribute(key);
39 if (attributes != null) {
40 for(UserAttribute attribute : attributes) {
41 if (attribute.getAttributeValue() != null
42 && attribute.getAttributeValue().equalsIgnoreCase(value)) {
43 success = true;
44 break;
45 }
46 }
47 }
48 return success;
49 }
50
51 public String getKey() {
52 return key;
53 }
54
55 public String getValue() {
56 return value;
57 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (obj instanceof PersonAttributeExpression) {
62 PersonAttributeExpression other = (PersonAttributeExpression)obj;
63 return key.equals(other.key) && value.equals(other.value);
64 }
65 return false;
66 }
67
68 }