KickJava   Java API By Example, From Geeks To Geeks.

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


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.PermissionSet;
24 import org.apache.turbine.util.security.TurbineSecurityException;
25
26 /**
27  * This class represents a role played by the User associated with the
28  * current Session.
29  *
30  * @author <a HREF="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
31  * @author <a HREF="mailto:john.mcnally@clearink.com">John D. McNally</a>
32  * @author <a HREF="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
33  * @version $Id: TurbineRole.java,v 1.6.2.2 2004/05/20 03:05:17 seade Exp $
34  */

35 public class TurbineRole extends SecurityObject implements Role
36 {
37     /**
38      * Constructs a new Role
39      */

40     public TurbineRole()
41     {
42         super();
43     }
44
45     /**
46      * Constructs a new Role with the sepcified name.
47      *
48      * @param name The name of the new object.
49      */

50     public TurbineRole(String JavaDoc name)
51     {
52         super(name);
53     }
54
55     /** The permissions for this role. */
56     private PermissionSet permissionSet = null;
57
58     /**
59      * Returns the set of Permissions associated with this Role.
60      *
61      * @return A PermissionSet.
62      * @exception Exception a generic exception.
63      */

64     public PermissionSet getPermissions()
65             throws Exception JavaDoc
66     {
67         return permissionSet;
68     }
69
70     /**
71      * Sets the Permissions associated with this Role.
72      *
73      * @param permissionSet A PermissionSet.
74      */

75     public void setPermissions(PermissionSet permissionSet)
76     {
77         this.permissionSet = permissionSet;
78     }
79
80     // These following methods are wrappers around TurbineSecurity
81

82     /**
83      * Creates a new Role in the system.
84      *
85      * @param name The name of the new Role.
86      * @return An object representing the new Role.
87      * @throws TurbineSecurityException if the Role could not be created.
88      */

89     public Role create(String JavaDoc name)
90             throws TurbineSecurityException
91     {
92         //Role role = new Role(name);
93
Role role = new TurbineRole(name);
94         TurbineSecurity.addRole(role);
95         return role;
96     }
97
98     /**
99      * Makes changes made to the Role attributes permanent.
100      *
101      * @throws TurbineSecurityException if there is a problem while
102      * saving data.
103      */

104     public void save()
105             throws TurbineSecurityException
106     {
107         TurbineSecurity.saveRole(this);
108     }
109
110     /**
111      * not implemented
112      *
113      * @param conn
114      * @throws Exception
115      */

116     public void save(Connection JavaDoc conn) throws Exception JavaDoc
117     {
118         throw new Exception JavaDoc("not implemented");
119     }
120
121     /**
122      * not implemented
123      *
124      * @param dbname
125      * @throws Exception
126      */

127     public void save(String JavaDoc dbname) throws Exception JavaDoc
128     {
129         throw new Exception JavaDoc("not implemented");
130     }
131
132     /**
133      * Removes a role from the system.
134      *
135      * @throws TurbineSecurityException if the Role could not be removed.
136      */

137     public void remove()
138             throws TurbineSecurityException
139     {
140         TurbineSecurity.removeRole(this);
141     }
142
143     /**
144      * Renames the role.
145      *
146      * @param name The new Role name.
147      * @throws TurbineSecurityException if the Role could not be renamed.
148      */

149     public void rename(String JavaDoc name)
150             throws TurbineSecurityException
151     {
152         TurbineSecurity.renameRole(this, name);
153     }
154
155     /**
156      * Grants a Permission to this Role.
157      *
158      * @param permission A Permission.
159      * @throws TurbineSecurityException if there is a problem while assigning
160      * the Permission.
161      */

162     public void grant(Permission permission)
163             throws TurbineSecurityException
164     {
165         TurbineSecurity.grant(this, permission);
166     }
167
168     /**
169      * Grants Permissions from a PermissionSet to this Role.
170      *
171      * @param permissionSet A PermissionSet.
172      * @throws TurbineSecurityException if there is a problem while assigning
173      * the Permissions.
174      */

175     public void grant(PermissionSet permissionSet)
176             throws TurbineSecurityException
177     {
178         for (Iterator JavaDoc permissions = permissionSet.iterator(); permissions.hasNext();)
179         {
180             TurbineSecurity.grant(this, (Permission) permissions.next());
181         }
182     }
183
184     /**
185      * Revokes a Permission from this Role.
186      *
187      * @param permission A Permission.
188      * @throws TurbineSecurityException if there is a problem while unassigning
189      * the Permission.
190      */

191     public void revoke(Permission permission)
192             throws TurbineSecurityException
193     {
194         TurbineSecurity.revoke(this, permission);
195     }
196
197     /**
198      * Revokes Permissions from a PermissionSet from this Role.
199      *
200      * @param permissionSet A PermissionSet.
201      * @throws TurbineSecurityException if there is a problem while unassigning
202      * the Permissions.
203      */

204     public void revoke(PermissionSet permissionSet)
205             throws TurbineSecurityException
206     {
207         for (Iterator JavaDoc permissions = permissionSet.iterator(); permissions.hasNext();)
208         {
209             TurbineSecurity.revoke(this, (Permission) permissions.next());
210         }
211     }
212 }
213
Popular Tags