KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > om > security > TurbineGroup


1 package org.apache.turbine.om.security;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.sql.Connection JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import org.apache.turbine.services.security.TurbineSecurity;
23 import org.apache.turbine.util.security.RoleSet;
24 import org.apache.turbine.util.security.TurbineSecurityException;
25
26 /**
27  * This class represents a Group of Users in the system that are associated
28  * with specific entity or resource. The users belonging to the Group may have
29  * various Roles. The Permissions to perform actions upon the resource depend
30  * on the Roles in the Group that they are assigned.
31  *
32  * <a name="global">
33  * <p> Certain Roles that the Users may have in the system may are not related
34  * to any specific resource nor entity.
35  * They are assigned within a special group named 'global' that can be
36  * referenced in the code as {@link #GLOBAL_GROUP_NAME}.
37  * <br>
38  *
39  * @author <a HREF="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
40  * @version $Id: TurbineGroup.java,v 1.6.2.2 2004/05/20 03:05:17 seade Exp $
41  */

42 public class TurbineGroup extends SecurityObject implements Group
43 {
44     /**
45      * Constructs a new Group.
46      */

47     public TurbineGroup()
48     {
49         super();
50     }
51
52     /**
53      * Constructs a new Group with the specified name.
54      *
55      * @param name The name of the new object.
56      */

57     public TurbineGroup(String JavaDoc name)
58     {
59         super(name);
60     }
61
62     // These following methods are wrappers around TurbineSecurity
63

64     /**
65      * Makes changes made to the Group attributes permanent.
66      *
67      * @throws TurbineSecurityException if there is a problem while saving data.
68      */

69     public void save() throws TurbineSecurityException
70     {
71         TurbineSecurity.saveGroup(this);
72     }
73
74     /**
75      * not implemented
76      *
77      * @param conn
78      * @throws Exception
79      */

80     public void save(Connection JavaDoc conn) throws Exception JavaDoc
81     {
82         throw new Exception JavaDoc("not implemented");
83     }
84
85     /**
86      * not implemented
87      *
88      * @param dbname
89      * @throws Exception
90      */

91     public void save(String JavaDoc dbname) throws Exception JavaDoc
92     {
93         throw new Exception JavaDoc("not implemented");
94     }
95
96     /**
97      * Removes a group from the system.
98      *
99      * @throws TurbineSecurityException if the Group could not be removed.
100      */

101     public void remove() throws TurbineSecurityException
102     {
103         TurbineSecurity.removeGroup(this);
104     }
105
106     /**
107      * Renames the role.
108      *
109      * @param name The new Group name.
110      * @throws TurbineSecurityException if the Group could not be renamed.
111      */

112     public void rename(String JavaDoc name) throws TurbineSecurityException
113     {
114         TurbineSecurity.renameGroup(this, name);
115     }
116
117     /**
118      * Grants a Role in this Group to an User.
119      *
120      * @param user An User.
121      * @param role A Role.
122      * @throws TurbineSecurityException if there is a problem while assigning
123      * the Role.
124      */

125     public void grant(User user, Role role) throws TurbineSecurityException
126     {
127         TurbineSecurity.grant(user, this, role);
128     }
129
130     /**
131      * Grants Roles in this Group to an User.
132      *
133      * @param user An User.
134      * @param roleSet A RoleSet.
135      * @throws TurbineSecurityException if there is a problem while assigning
136      * the Roles.
137      */

138     public void grant(User user, RoleSet roleSet)
139             throws TurbineSecurityException
140     {
141         for (Iterator JavaDoc roles = roleSet.iterator(); roles.hasNext();)
142         {
143             TurbineSecurity.grant(user, this, (Role) roles.next());
144         }
145     }
146
147     /**
148      * Revokes a Role in this Group from an User.
149      *
150      * @param user An User.
151      * @param role A Role.
152      * @throws TurbineSecurityException if there is a problem while unassigning
153      * the Role.
154      */

155     public void revoke(User user, Role role) throws TurbineSecurityException
156     {
157         TurbineSecurity.revoke(user, this, role);
158     }
159
160     /**
161      * Revokes Roles in this group from an User.
162      *
163      * @param user An User.
164      * @param roleSet a RoleSet.
165      * @throws TurbineSecurityException if there is a problem while unassigning
166      * the Roles.
167      */

168     public void revoke(User user, RoleSet roleSet)
169             throws TurbineSecurityException
170     {
171         for (Iterator JavaDoc roles = roleSet.iterator(); roles.hasNext();)
172         {
173             TurbineSecurity.revoke(user, this, (Role) roles.next());
174         }
175     }
176 }
177
Popular Tags