6bfe9269e4a2b8478bccacaf4ab2dfe0ab221a39
[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 package org.wamblee.security.authorization;
17
18 import org.wamblee.persistence.AbstractPersistent;
19
20 import org.wamblee.usermgt.User;
21
22
23 /**
24  * Checks if a user against a specific group.
25  *
26  * @author Erik Brakkee
27  */
28 public class GroupUserCondition extends AbstractPersistent
29     implements UserCondition {
30     /**
31      * Group the user must be in.
32      */
33     private String group;
34
35 /**
36      * Constructs the condition. 
37      * @param aGroup Group the user must be in. 
38      */
39     public GroupUserCondition(String aGroup) {
40         group = aGroup;
41     }
42
43 /**
44      * For OR mapping. 
45      *
46      */
47     protected GroupUserCondition() {
48         group = null;
49     }
50
51     /* (non-Javadoc)
52      * @see org.wamblee.security.authorization.UserCondition#matches(org.wamblee.usermgt.UserAccessor)
53      */
54     /**
55      * DOCUMENT ME!
56      *
57      * @param aUser DOCUMENT ME!
58      *
59      * @return DOCUMENT ME!
60      */
61     public boolean matches(User aUser) {
62         return aUser.isInGroup(group);
63     }
64
65     /**
66      * DOCUMENT ME!
67      *
68      * @return Returns the group.
69      */
70     protected String getGroup() {
71         return group;
72     }
73
74     /**
75      * DOCUMENT ME!
76      *
77      * @param aGroup The group to set.
78      */
79     protected void setGroup(String aGroup) {
80         group = aGroup;
81     }
82
83     /* (non-Javadoc)
84      * @see java.lang.Object#toString()
85      */
86     /**
87      * DOCUMENT ME!
88      *
89      * @return DOCUMENT ME!
90      */
91     @Override
92     public String toString() {
93         return "GroupUserCondition(group=" + group + ")";
94     }
95 }