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