1 package org.apache.turbine.om.security;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.sql.Connection;
20 import java.util.Iterator;
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 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
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
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 name)
90 throws TurbineSecurityException
91 {
92
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 conn) throws Exception
117 {
118 throw new Exception("not implemented");
119 }
120
121 /***
122 * not implemented
123 *
124 * @param dbname
125 * @throws Exception
126 */
127 public void save(String dbname) throws Exception
128 {
129 throw new Exception("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 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 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 permissions = permissionSet.iterator(); permissions.hasNext();)
208 {
209 TurbineSecurity.revoke(this, (Permission) permissions.next());
210 }
211 }
212 }