Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TurbineRole |
|
| 1.2857142857142858;1,286 |
1 | package org.apache.turbine.om.security; | |
2 | ||
3 | ||
4 | /* | |
5 | * Licensed to the Apache Software Foundation (ASF) under one | |
6 | * or more contributor license agreements. See the NOTICE file | |
7 | * distributed with this work for additional information | |
8 | * regarding copyright ownership. The ASF licenses this file | |
9 | * to you under the Apache License, Version 2.0 (the | |
10 | * "License"); you may not use this file except in compliance | |
11 | * with the License. You may obtain a copy of the License at | |
12 | * | |
13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
14 | * | |
15 | * Unless required by applicable law or agreed to in writing, | |
16 | * software distributed under the License is distributed on an | |
17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
18 | * KIND, either express or implied. See the License for the | |
19 | * specific language governing permissions and limitations | |
20 | * under the License. | |
21 | */ | |
22 | ||
23 | ||
24 | import java.sql.Connection; | |
25 | import java.util.Iterator; | |
26 | ||
27 | import org.apache.turbine.services.security.TurbineSecurity; | |
28 | import org.apache.turbine.util.security.PermissionSet; | |
29 | import org.apache.turbine.util.security.TurbineSecurityException; | |
30 | ||
31 | /** | |
32 | * This class represents a role played by the User associated with the | |
33 | * current Session. | |
34 | * | |
35 | * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a> | |
36 | * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> | |
37 | * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> | |
38 | * @version $Id: TurbineRole.java 1078552 2011-03-06 19:58:46Z tv $ | |
39 | */ | |
40 | public class TurbineRole extends SecurityObject<Role> implements Role | |
41 | { | |
42 | /** Serial version */ | |
43 | private static final long serialVersionUID = -1354408789347969126L; | |
44 | ||
45 | /** | |
46 | * Constructs a new Role | |
47 | */ | |
48 | public TurbineRole() | |
49 | { | |
50 | 0 | super(); |
51 | 0 | } |
52 | ||
53 | /** | |
54 | * Constructs a new Role with the sepcified name. | |
55 | * | |
56 | * @param name The name of the new object. | |
57 | */ | |
58 | public TurbineRole(String name) | |
59 | { | |
60 | 0 | super(name); |
61 | 0 | } |
62 | ||
63 | /** The permissions for this role. */ | |
64 | 0 | private PermissionSet permissionSet = null; |
65 | ||
66 | /** | |
67 | * Returns the set of Permissions associated with this Role. | |
68 | * | |
69 | * @return A PermissionSet. | |
70 | * @exception Exception a generic exception. | |
71 | */ | |
72 | public PermissionSet getPermissions() | |
73 | throws Exception | |
74 | { | |
75 | 0 | return permissionSet; |
76 | } | |
77 | ||
78 | /** | |
79 | * Sets the Permissions associated with this Role. | |
80 | * | |
81 | * @param permissionSet A PermissionSet. | |
82 | */ | |
83 | public void setPermissions(PermissionSet permissionSet) | |
84 | { | |
85 | 0 | this.permissionSet = permissionSet; |
86 | 0 | } |
87 | ||
88 | // These following methods are wrappers around TurbineSecurity | |
89 | ||
90 | /** | |
91 | * Creates a new Role in the system. | |
92 | * | |
93 | * @param name The name of the new Role. | |
94 | * @return An object representing the new Role. | |
95 | * @throws TurbineSecurityException if the Role could not be created. | |
96 | */ | |
97 | public Role create(String name) | |
98 | throws TurbineSecurityException | |
99 | { | |
100 | //Role role = new Role(name); | |
101 | 0 | Role role = new TurbineRole(name); |
102 | 0 | TurbineSecurity.addRole(role); |
103 | 0 | return role; |
104 | } | |
105 | ||
106 | /** | |
107 | * Makes changes made to the Role attributes permanent. | |
108 | * | |
109 | * @throws TurbineSecurityException if there is a problem while | |
110 | * saving data. | |
111 | */ | |
112 | public void save() | |
113 | throws TurbineSecurityException | |
114 | { | |
115 | 0 | TurbineSecurity.saveRole(this); |
116 | 0 | } |
117 | ||
118 | /** | |
119 | * not implemented | |
120 | * | |
121 | * @param conn | |
122 | * @throws Exception | |
123 | */ | |
124 | public void save(Connection conn) throws Exception | |
125 | { | |
126 | 0 | throw new Exception("not implemented"); |
127 | } | |
128 | ||
129 | /** | |
130 | * not implemented | |
131 | * | |
132 | * @param dbname | |
133 | * @throws Exception | |
134 | */ | |
135 | public void save(String dbname) throws Exception | |
136 | { | |
137 | 0 | throw new Exception("not implemented"); |
138 | } | |
139 | ||
140 | /** | |
141 | * Removes a role from the system. | |
142 | * | |
143 | * @throws TurbineSecurityException if the Role could not be removed. | |
144 | */ | |
145 | public void remove() | |
146 | throws TurbineSecurityException | |
147 | { | |
148 | 0 | TurbineSecurity.removeRole(this); |
149 | 0 | } |
150 | ||
151 | /** | |
152 | * Renames the role. | |
153 | * | |
154 | * @param name The new Role name. | |
155 | * @throws TurbineSecurityException if the Role could not be renamed. | |
156 | */ | |
157 | public void rename(String name) | |
158 | throws TurbineSecurityException | |
159 | { | |
160 | 0 | TurbineSecurity.renameRole(this, name); |
161 | 0 | } |
162 | ||
163 | /** | |
164 | * Grants a Permission to this Role. | |
165 | * | |
166 | * @param permission A Permission. | |
167 | * @throws TurbineSecurityException if there is a problem while assigning | |
168 | * the Permission. | |
169 | */ | |
170 | public void grant(Permission permission) | |
171 | throws TurbineSecurityException | |
172 | { | |
173 | 0 | TurbineSecurity.grant(this, permission); |
174 | 0 | } |
175 | ||
176 | /** | |
177 | * Grants Permissions from a PermissionSet to this Role. | |
178 | * | |
179 | * @param permissionSet A PermissionSet. | |
180 | * @throws TurbineSecurityException if there is a problem while assigning | |
181 | * the Permissions. | |
182 | */ | |
183 | public void grant(PermissionSet permissionSet) | |
184 | throws TurbineSecurityException | |
185 | { | |
186 | 0 | for (Iterator permissions = permissionSet.iterator(); permissions.hasNext();) |
187 | { | |
188 | 0 | TurbineSecurity.grant(this, (Permission) permissions.next()); |
189 | } | |
190 | 0 | } |
191 | ||
192 | /** | |
193 | * Revokes a Permission from this Role. | |
194 | * | |
195 | * @param permission A Permission. | |
196 | * @throws TurbineSecurityException if there is a problem while unassigning | |
197 | * the Permission. | |
198 | */ | |
199 | public void revoke(Permission permission) | |
200 | throws TurbineSecurityException | |
201 | { | |
202 | 0 | TurbineSecurity.revoke(this, permission); |
203 | 0 | } |
204 | ||
205 | /** | |
206 | * Revokes Permissions from a PermissionSet from this Role. | |
207 | * | |
208 | * @param permissionSet A PermissionSet. | |
209 | * @throws TurbineSecurityException if there is a problem while unassigning | |
210 | * the Permissions. | |
211 | */ | |
212 | public void revoke(PermissionSet permissionSet) | |
213 | throws TurbineSecurityException | |
214 | { | |
215 | 0 | for (Iterator permissions = permissionSet.iterator(); permissions.hasNext();) |
216 | { | |
217 | 0 | TurbineSecurity.revoke(this, (Permission) permissions.next()); |
218 | } | |
219 | 0 | } |
220 | } |