1 /**
2 * Copyright 2011-2013 The Kuali Foundation Licensed under the
3 * Educational Community License, Version 2.0 (the "License"); you may
4 * not use this file except in compliance with the License. You may
5 * obtain a copy of the License at
6 *
7 * http://www.osedu.org/licenses/ECL-2.0
8 *
9 * Unless required by applicable law or agreed to in writing,
10 * software distributed under the License is distributed on an "AS IS"
11 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 package org.kuali.mobility.security.authz.expression;
17
18 import org.kuali.mobility.security.user.api.User;
19
20 /**
21 * An expression to check if a user is a member of a group.
22 * @author Kuali Mobility Team (mobility.collab@kuali.org)
23 */
24 public class GroupExpression implements Expression {
25
26 private static final long serialVersionUID = 8899577797440033748L;
27
28 /**
29 * Key if the group to check
30 */
31 private String key;
32
33 /**
34 * Creates a new instance of a <code>GroupExpression</code>
35 * @param key
36 */
37 public GroupExpression(String key) {
38 this.key = key;
39 }
40
41 /**
42 *
43 * @param user User to test the expression against.
44 * @return
45 */
46 public boolean evaluate(User user) {
47 return (user != null && user.getGroups() != null && user.isMember(key.toUpperCase()));
48 }
49
50 /**
51 * Gets the key of this <code>GroupExpression</code>
52 * @return
53 */
54 public String getKey() {
55 return key;
56 }
57
58 @Override
59 public boolean equals(Object obj) {
60 if (obj instanceof GroupExpression) {
61 GroupExpression other = (GroupExpression)obj;
62 return key.equals(other.key);
63 }
64 return false;
65 }
66
67 }