de85067bc9e563ea9be6ed827580103561dbdcb2
[utils] / security / src / main / java / org / wamblee / security / authorization / GroupUserCondition.java
1 /*
2  * Copyright 2005 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */ 
16
17 package org.wamblee.security.authorization;
18
19 import org.wamblee.persistence.AbstractPersistent;
20 import org.wamblee.usermgt.User;
21
22 /**
23  * Checks if a user against a specific group. 
24  */
25 public class GroupUserCondition extends AbstractPersistent implements UserCondition {
26     
27     /**
28      * Group the user must be in. 
29      */
30     private String _group; 
31     
32     /**
33      * Constructs the condition. 
34      * @param aGroup Group the user must be in. 
35      */
36     public GroupUserCondition(String aGroup) {
37         _group = aGroup; 
38     }
39     
40     /**
41      * For OR mapping. 
42      *
43      */
44     protected GroupUserCondition() { 
45         _group = null; 
46     }
47
48     /* (non-Javadoc)
49      * @see org.wamblee.security.authorization.UserCondition#matches(org.wamblee.usermgt.UserAccessor)
50      */
51     public boolean matches(User aUser) { 
52         return aUser.isInGroup(_group); 
53     }
54
55     /**
56      * @return Returns the _group.
57      */
58     protected String getGroup() {
59         return _group;
60     }
61
62     /**
63      * @param _group The _group to set.
64      */
65     protected void setGroup(String aGroup) {
66         _group = aGroup;
67     }
68
69     /* (non-Javadoc)
70      * @see java.lang.Object#toString()
71      */
72     @Override
73     public String toString() {
74         return "GroupUserCondition(group=" + _group + ")";
75     }
76     
77 }