%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.turbine.om.security.TurbineRole |
|
|
1 | package org.apache.turbine.om.security; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 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; |
|
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 | 0 | super(); |
46 | 0 | } |
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 | 0 | super(name); |
56 | 0 | } |
57 | ||
58 | /** The permissions for this role. */ |
|
59 | 0 | 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 | 0 | 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 | 0 | this.permissionSet = permissionSet; |
81 | 0 | } |
82 | ||
83 | // These following methods are wrappers around TurbineSecurity |
|
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 | //Role role = new Role(name); |
|
96 | 0 | Role role = new TurbineRole(name); |
97 | 0 | TurbineSecurity.addRole(role); |
98 | 0 | 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 | 0 | TurbineSecurity.saveRole(this); |
111 | 0 | } |
112 | ||
113 | /** |
|
114 | * not implemented |
|
115 | * |
|
116 | * @param conn |
|
117 | * @throws Exception |
|
118 | */ |
|
119 | public void save(Connection conn) throws Exception |
|
120 | { |
|
121 | 0 | 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 | 0 | 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 | 0 | TurbineSecurity.removeRole(this); |
144 | 0 | } |
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 | 0 | TurbineSecurity.renameRole(this, name); |
156 | 0 | } |
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 | 0 | TurbineSecurity.grant(this, permission); |
169 | 0 | } |
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 | 0 | for (Iterator permissions = permissionSet.iterator(); permissions.hasNext();) |
182 | { |
|
183 | 0 | TurbineSecurity.grant(this, (Permission) permissions.next()); |
184 | } |
|
185 | 0 | } |
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 | 0 | TurbineSecurity.revoke(this, permission); |
198 | 0 | } |
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 | 0 | for (Iterator permissions = permissionSet.iterator(); permissions.hasNext();) |
211 | { |
|
212 | 0 | TurbineSecurity.revoke(this, (Permission) permissions.next()); |
213 | } |
|
214 | 0 | } |
215 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |