KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > security > impl > db > entity > TurbineGroup


1 package org.apache.fulcrum.security.impl.db.entity;
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.util.Iterator JavaDoc;
58 import org.apache.fulcrum.security.TurbineSecurity;
59 import org.apache.fulcrum.security.entity.Group;
60 import org.apache.fulcrum.security.entity.Role;
61 import org.apache.fulcrum.security.entity.User;
62 import org.apache.fulcrum.security.entity.SecurityEntity;
63 import org.apache.fulcrum.security.util.RoleSet;
64 import org.apache.fulcrum.security.util.TurbineSecurityException;
65
66 /**
67  * This class represents a Group of Users in the system that are associated
68  * with specific entity or resource. The users belonging to the Group may have
69  * various Roles. The Permissions to perform actions upon the resource depend
70  * on the Roles in the Group that they are assigned.
71  *
72  * <a name="global">
73  * <p> Certain Roles that the Users may have in the system are not related
74  * to any specific resource nor entity.
75  * They are assigned within a special group named 'global' that can be
76  * referenced in the code as {@link #GLOBAL_GROUP_NAME}.
77  * <br>
78  *
79  * @author <a HREF="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
80  * @author <a HREF="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
81  * @version $Id: TurbineGroup.java,v 1.1 2004/11/12 10:25:43 epugh Exp $
82  */

83 public class TurbineGroup
84     extends org.apache.fulcrum.security.impl.db.entity.BaseTurbineGroup
85     implements Group, Comparable JavaDoc
86 {
87     /**
88      * Constructs a new Group.
89      */

90     public TurbineGroup()
91     {
92     }
93
94     /**
95      * Constructs a new Group with the specified name.
96      *
97      * @param name The name of the new object.
98      */

99     public TurbineGroup(String JavaDoc name)
100     {
101         setName(name);
102     }
103
104     /**
105      * Provides a reference to the Group object that represents the
106      * <a HREF="#global">global group</a>.
107      *
108      * @return a Group object that represents the global group.
109      * @deprecated Please use the method in TurbineSecurity now.
110      */

111     public static Group getGlobalGroup()
112     {
113         return TurbineSecurity.getGlobalGroup();
114     }
115
116     /**
117      * Creates a new Group in the system.
118      *
119      * @param name The name of the new Group.
120      * @return An object representing the new Group.
121      * @throws TurbineSecurityException if the Group could not be created.
122      * @deprecated Please use the createGroup method in TurbineSecurity now.
123      */

124     public static Group create(String JavaDoc name)
125         throws TurbineSecurityException
126     {
127         return TurbineSecurity.createGroup(name);
128     }
129
130     // These following methods are wrappers around TurbineSecurity
131

132     /**
133      * Makes changes made to the Group attributes permanent.
134      *
135      * @throws TurbineSecurityException if there is a problem while
136      * saving data.
137      */

138     public void save()
139         throws TurbineSecurityException
140     {
141         TurbineSecurity.saveGroup(this);
142     }
143
144     /**
145      * Removes a group from the system.
146      *
147      * @throws TurbineSecurityException if the Group could not be removed.
148      */

149     public void remove()
150         throws TurbineSecurityException
151     {
152         TurbineSecurity.removeGroup(this);
153     }
154
155     /**
156      * Renames the role.
157      *
158      * @param name The new Group name.
159      * @throws TurbineSecurityException if the Group could not be renamed.
160      */

161     public void rename(String JavaDoc name)
162         throws TurbineSecurityException
163     {
164         TurbineSecurity.renameGroup(this, name);
165     }
166
167     /**
168      * Grants a Role in this Group to an User.
169      *
170      * @param user An User.
171      * @param role A Role.
172      * @throws TurbineSecurityException if there is a problem while assigning
173      * the Role.
174      */

175     public void grant(User user, Role role)
176         throws TurbineSecurityException
177     {
178         TurbineSecurity.grant(user, this, role);
179     }
180
181     /**
182      * Grants Roles in this Group to an User.
183      *
184      * @param user An User.
185      * @param roleSet A RoleSet.
186      * @throws TurbineSecurityException if there is a problem while assigning
187      * the Roles.
188      */

189     public void grant(User user, RoleSet roleSet)
190         throws TurbineSecurityException
191     {
192         Iterator JavaDoc roles = roleSet.elements();
193         while(roles.hasNext())
194         {
195             TurbineSecurity.grant(user, this, (Role)roles.next());
196         }
197     }
198
199     /**
200      * Revokes a Role in this Group from an User.
201      *
202      * @param user An User.
203      * @param role A Role.
204      * @throws TurbineSecurityException if there is a problem while unassigning
205      * the Role.
206      */

207     public void revoke(User user, Role role)
208         throws TurbineSecurityException
209     {
210         TurbineSecurity.revoke(user, this, role);
211     }
212
213     /**
214      * Revokes Roles in this group from an User.
215      *
216      * @param user An User.
217      * @param roleSet a RoleSet.
218      * @throws TurbineSecurityException if there is a problem while unassigning
219      * the Roles.
220      */

221     public void revoke(User user, RoleSet roleSet)
222         throws TurbineSecurityException
223     {
224         Iterator JavaDoc roles = roleSet.elements();
225         while(roles.hasNext())
226         {
227             TurbineSecurity.revoke(user, this, (Role)roles.next());
228         }
229     }
230
231     /**
232      * Used for ordering SecurityObjects.
233      *
234      * @param obj The Object to compare to.
235      * @return -1 if the name of the other object is lexically greater than this
236      * group, 1 if it is lexically lesser, 0 if they are equal.
237      */

238     public int compareTo(Object JavaDoc obj)
239     {
240         if(this.getClass() != obj.getClass())
241             throw new ClassCastException JavaDoc();
242         String JavaDoc name1 = ((SecurityEntity)obj).getName();
243         String JavaDoc name2 = this.getName();
244         return name2.compareTo(name1);
245     }
246
247 }
248
Popular Tags