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 278822 2005-09-05 19:53:05Z henning $
34 */
35 public class TurbineRole extends SecurityObject implements Role
36 {
37 /*** Serial Version UID */
38 private static final long serialVersionUID = -1354408789347969126L;
39
40 /***
41 * Constructs a new Role
42 */
43 public TurbineRole()
44 {
45 super();
46 }
47
48 /***
49 * Constructs a new Role with the sepcified name.
50 *
51 * @param name The name of the new object.
52 */
53 public TurbineRole(String name)
54 {
55 super(name);
56 }
57
58 /*** The permissions for this role. */
59 private PermissionSet permissionSet = null;
60
61 /***
62 * Returns the set of Permissions associated with this Role.
63 *
64 * @return A PermissionSet.
65 * @exception Exception a generic exception.
66 */
67 public PermissionSet getPermissions()
68 throws Exception
69 {
70 return permissionSet;
71 }
72
73 /***
74 * Sets the Permissions associated with this Role.
75 *
76 * @param permissionSet A PermissionSet.
77 */
78 public void setPermissions(PermissionSet permissionSet)
79 {
80 this.permissionSet = permissionSet;
81 }
82
83
84
85 /***
86 * Creates a new Role in the system.
87 *
88 * @param name The name of the new Role.
89 * @return An object representing the new Role.
90 * @throws TurbineSecurityException if the Role could not be created.
91 */
92 public Role create(String name)
93 throws TurbineSecurityException
94 {
95
96 Role role = new TurbineRole(name);
97 TurbineSecurity.addRole(role);
98 return role;
99 }
100
101 /***
102 * Makes changes made to the Role attributes permanent.
103 *
104 * @throws TurbineSecurityException if there is a problem while
105 * saving data.
106 */
107 public void save()
108 throws TurbineSecurityException
109 {
110 TurbineSecurity.saveRole(this);
111 }
112
113 /***
114 * not implemented
115 *
116 * @param conn
117 * @throws Exception
118 */
119 public void save(Connection conn) throws Exception
120 {
121 throw new Exception("not implemented");
122 }
123
124 /***
125 * not implemented
126 *
127 * @param dbname
128 * @throws Exception
129 */
130 public void save(String dbname) throws Exception
131 {
132 throw new Exception("not implemented");
133 }
134
135 /***
136 * Removes a role from the system.
137 *
138 * @throws TurbineSecurityException if the Role could not be removed.
139 */
140 public void remove()
141 throws TurbineSecurityException
142 {
143 TurbineSecurity.removeRole(this);
144 }
145
146 /***
147 * Renames the role.
148 *
149 * @param name The new Role name.
150 * @throws TurbineSecurityException if the Role could not be renamed.
151 */
152 public void rename(String name)
153 throws TurbineSecurityException
154 {
155 TurbineSecurity.renameRole(this, name);
156 }
157
158 /***
159 * Grants a Permission to this Role.
160 *
161 * @param permission A Permission.
162 * @throws TurbineSecurityException if there is a problem while assigning
163 * the Permission.
164 */
165 public void grant(Permission permission)
166 throws TurbineSecurityException
167 {
168 TurbineSecurity.grant(this, permission);
169 }
170
171 /***
172 * Grants Permissions from a PermissionSet to this Role.
173 *
174 * @param permissionSet A PermissionSet.
175 * @throws TurbineSecurityException if there is a problem while assigning
176 * the Permissions.
177 */
178 public void grant(PermissionSet permissionSet)
179 throws TurbineSecurityException
180 {
181 for (Iterator permissions = permissionSet.iterator(); permissions.hasNext();)
182 {
183 TurbineSecurity.grant(this, (Permission) permissions.next());
184 }
185 }
186
187 /***
188 * Revokes a Permission from this Role.
189 *
190 * @param permission A Permission.
191 * @throws TurbineSecurityException if there is a problem while unassigning
192 * the Permission.
193 */
194 public void revoke(Permission permission)
195 throws TurbineSecurityException
196 {
197 TurbineSecurity.revoke(this, permission);
198 }
199
200 /***
201 * Revokes Permissions from a PermissionSet from this Role.
202 *
203 * @param permissionSet A PermissionSet.
204 * @throws TurbineSecurityException if there is a problem while unassigning
205 * the Permissions.
206 */
207 public void revoke(PermissionSet permissionSet)
208 throws TurbineSecurityException
209 {
210 for (Iterator permissions = permissionSet.iterator(); permissions.hasNext();)
211 {
212 TurbineSecurity.revoke(this, (Permission) permissions.next());
213 }
214 }
215 }