1 package org.apache.turbine.om.security;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import java.sql.Connection;
58 import java.util.Iterator;
59 import org.apache.turbine.services.security.TurbineSecurity;
60 import org.apache.turbine.util.security.RoleSet;
61 import org.apache.turbine.util.security.TurbineSecurityException;
62
63 /***
64 * This class represents a Group of Users in the system that are associated
65 * with specific entity or resource. The users belonging to the Group may have
66 * various Roles. The Permissions to perform actions upon the resource depend
67 * on the Roles in the Group that they are assigned.
68 *
69 * <a name="global">
70 * <p> Certain Roles that the Users may have in the system may are not related
71 * to any specific resource nor entity.
72 * They are assigned within a special group named 'global' that can be
73 * referenced in the code as {@link #GLOBAL_GROUP_NAME}.
74 * <br>
75 *
76 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
77 * @version $Id: TurbineGroup.java,v 1.2 2002/07/11 07:34:30 mpoeschl Exp $
78 */
79 public class TurbineGroup extends SecurityObject implements Group
80 {
81 /***
82 * Constructs a new Group.
83 */
84 public TurbineGroup()
85 {
86 super();
87 }
88
89 /***
90 * Constructs a new Group with the specified name.
91 *
92 * @param name The name of the new object.
93 */
94 public TurbineGroup( String name )
95 {
96 super(name);
97 }
98
99 /***
100 * Provides a reference to the Group object that represents the
101 * <a href="#global">global group</a>.
102 *
103 * @return a Group object that represents the global group.
104 * @deprecated Please use the method in TurbineSecurity now.
105 */
106 public static Group getGlobalGroup()
107 {
108 return TurbineSecurity.getGlobalGroup();
109 }
110
111 /***
112 * Creates a new Group in the system.
113 *
114 * @param name The name of the new Group.
115 * @return An object representing the new Group.
116 * @throws TurbineSecurityException if the Group could not be created.
117 * @deprecated Please use the createGroup method in TurbineSecurity now.
118 */
119 public static Group create( String name )
120 throws TurbineSecurityException
121 {
122 return TurbineSecurity.createGroup(name);
123 }
124
125 // These following methods are wrappers around TurbineSecurity
126
127 /***
128 * Makes changes made to the Group attributes permanent.
129 *
130 * @throws TurbineSecurityException if there is a problem while
131 * saving data.
132 */
133 public void save()
134 throws TurbineSecurityException
135 {
136 TurbineSecurity.saveGroup(this);
137 }
138
139 /***
140 * not implemented
141 *
142 * @param conn
143 * @throws Exception
144 */
145 public void save(Connection conn) throws Exception
146 {
147 throw new Exception("not implemented");
148 }
149
150 /***
151 * not implemented
152 *
153 * @param dbname
154 * @throws Exception
155 */
156 public void save(String dbname) throws Exception
157 {
158 throw new Exception("not implemented");
159 }
160
161 /***
162 * Removes a group from the system.
163 *
164 * @throws TurbineSecurityException if the Group could not be removed.
165 */
166 public void remove()
167 throws TurbineSecurityException
168 {
169 TurbineSecurity.removeGroup(this);
170 }
171
172 /***
173 * Renames the role.
174 *
175 * @param name The new Group name.
176 * @throws TurbineSecurityException if the Group could not be renamed.
177 */
178 public void rename(String name)
179 throws TurbineSecurityException
180 {
181 TurbineSecurity.renameGroup(this, name);
182 }
183
184 /***
185 * Grants a Role in this Group to an User.
186 *
187 * @param user An User.
188 * @param role A Role.
189 * @throws TurbineSecurityException if there is a problem while assigning
190 * the Role.
191 */
192 public void grant(User user, Role role)
193 throws TurbineSecurityException
194 {
195 TurbineSecurity.grant(user, this, role);
196 }
197
198 /***
199 * Grants Roles in this Group to an User.
200 *
201 * @param user An User.
202 * @param roleSet A RoleSet.
203 * @throws TurbineSecurityException if there is a problem while assigning
204 * the Roles.
205 */
206 public void grant(User user, RoleSet roleSet)
207 throws TurbineSecurityException
208 {
209 Iterator roles = roleSet.elements();
210 while(roles.hasNext())
211 {
212 TurbineSecurity.grant(user, this, (Role)roles.next());
213 }
214 }
215
216 /***
217 * Revokes a Role in this Group from an User.
218 *
219 * @param user An User.
220 * @param role A Role.
221 * @throws TurbineSecurityException if there is a problem while unassigning
222 * the Role.
223 */
224 public void revoke(User user, Role role)
225 throws TurbineSecurityException
226 {
227 TurbineSecurity.revoke(user, this, role);
228 }
229
230 /***
231 * Revokes Roles in this group from an User.
232 *
233 * @param user An User.
234 * @param roleSet a RoleSet.
235 * @throws TurbineSecurityException if there is a problem while unassigning
236 * the Roles.
237 */
238 public void revoke(User user, RoleSet roleSet)
239 throws TurbineSecurityException
240 {
241 Iterator roles = roleSet.elements();
242 while(roles.hasNext())
243 {
244 TurbineSecurity.revoke(user, this, (Role)roles.next());
245 }
246 }
247 }
248
This page was automatically generated by Maven