001 package org.apache.turbine.test;
002
003
004 /*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements. See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership. The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License. You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied. See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024 import java.util.HashMap;
025 import java.util.List;
026
027 import org.apache.turbine.om.security.Group;
028 import org.apache.turbine.om.security.Permission;
029 import org.apache.turbine.om.security.Role;
030 import org.apache.turbine.om.security.User;
031 import org.apache.turbine.services.security.BaseSecurityService;
032 import org.apache.turbine.util.security.AccessControlList;
033 import org.apache.turbine.util.security.DataBackendException;
034 import org.apache.turbine.util.security.EntityExistsException;
035 import org.apache.turbine.util.security.GroupSet;
036 import org.apache.turbine.util.security.PermissionSet;
037 import org.apache.turbine.util.security.RoleSet;
038 import org.apache.turbine.util.security.UnknownEntityException;
039
040 /**
041 * An Mock implementation of SecurityService. Basically replacing existing
042 * database methods as needed for a test case.
043 *
044 * @author <a href="mailto:epugh@opensourceconnections.com">Eric Pugh</a>
045 * @version $Id: MockSecurityService.java 615328 2008-01-25 20:25:05Z tv $
046 */
047 public class MockSecurityService extends BaseSecurityService
048 {
049
050 /**
051 * The key within services's properties for user implementation
052 * classname (user.class) - Leandro
053 */
054 public static final String USER_PEER_CLASS_KEY = "userPeer.class";
055
056 /**
057 * The default implementation of User interface
058 * (org.apache.turbine.om.security.DBUser)
059 */
060 public static final String USER_PEER_CLASS_DEFAULT =
061 "org.apache.turbine.om.security.peer.TurbineUserPeer";
062
063 /*-----------------------------------------------------------------------
064 Creation of AccessControlLists
065 -----------------------------------------------------------------------*/
066
067 /**
068 * Constructs an AccessControlList for a specific user.
069 *
070 * This method creates a snapshot of the state of security information
071 * concerning this user, at the moment of invocation and stores it
072 * into an AccessControlList object.
073 *
074 * @param user the user for whom the AccessControlList are to be retrieved
075 * @return A new AccessControlList object.
076 * @throws DataBackendException if there was an error accessing the data
077 * backend.
078 * @throws UnknownEntityException if user account is not present.
079 */
080 public AccessControlList getACL(User user)
081 throws DataBackendException, UnknownEntityException
082 {
083 return getAclInstance(new HashMap(), new HashMap());
084 }
085
086 /*-----------------------------------------------------------------------
087 Security management
088 -----------------------------------------------------------------------*/
089
090 /**
091 * Grant an User a Role in a Group.
092 *
093 * @param user the user.
094 * @param group the group.
095 * @param role the role.
096 * @throws DataBackendException if there was an error accessing the data
097 * backend.
098 * @throws UnknownEntityException if user account, group or role is not
099 * present.
100 */
101 public synchronized void grant(User user, Group group, Role role)
102 throws DataBackendException, UnknownEntityException
103 {
104
105 }
106
107 /**
108 * Revoke a Role in a Group from an User.
109 *
110 * @param user the user.
111 * @param group the group.
112 * @param role the role.
113 * @throws DataBackendException if there was an error accessing the data
114 * backend.
115 * @throws UnknownEntityException if user account, group or role is not
116 * present.
117 */
118 public synchronized void revoke(User user, Group group, Role role)
119 throws DataBackendException, UnknownEntityException
120 {
121
122 }
123
124 /**
125 * Revokes all roles from an User.
126 *
127 * This method is used when deleting an account.
128 *
129 * @param user the User.
130 * @throws DataBackendException if there was an error accessing the data
131 * backend.
132 * @throws UnknownEntityException if the account is not present.
133 */
134 public synchronized void revokeAll(User user)
135 throws DataBackendException, UnknownEntityException
136 {
137
138 }
139
140 /**
141 * Grants a Role a Permission
142 *
143 * @param role the Role.
144 * @param permission the Permission.
145 * @throws DataBackendException if there was an error accessing the data
146 * backend.
147 * @throws UnknownEntityException if role or permission is not present.
148 */
149 public synchronized void grant(Role role, Permission permission)
150 throws DataBackendException, UnknownEntityException
151 {
152
153 }
154
155 /**
156 * Revokes a Permission from a Role.
157 *
158 * @param role the Role.
159 * @param permission the Permission.
160 * @throws DataBackendException if there was an error accessing the data
161 * backend.
162 * @throws UnknownEntityException if role or permission is not present.
163 */
164 public synchronized void revoke(Role role, Permission permission)
165 throws DataBackendException, UnknownEntityException
166 {
167
168 }
169
170 /**
171 * Revokes all permissions from a Role.
172 *
173 * This method is user when deleting a Role.
174 *
175 * @param role the Role
176 * @throws DataBackendException if there was an error accessing the data
177 * backend.
178 * @throws UnknownEntityException if the Role is not present.
179 */
180 public synchronized void revokeAll(Role role)
181 throws DataBackendException, UnknownEntityException
182 {
183
184 }
185
186 /*-----------------------------------------------------------------------
187 Group/Role/Permission management
188 -----------------------------------------------------------------------*/
189
190 /**
191 * Retrieve a set of Groups that meet the specified Criteria.
192 *
193 * @param criteria A Criteria of Group selection.
194 * @return a set of Groups that meet the specified Criteria.
195 * @throws DataBackendException if there was an error accessing the data
196 * backend.
197 */
198 public GroupSet getGroups(Object criteria) throws DataBackendException
199 {
200
201 return new GroupSet();
202 }
203
204 /**
205 * Retrieve a set of Roles that meet the specified Criteria.
206 *
207 * @param criteria A Criteria of Roles selection.
208 * @return a set of Roles that meet the specified Criteria.
209 * @throws DataBackendException if there was an error accessing the data
210 * backend.
211 */
212 public RoleSet getRoles(Object criteria) throws DataBackendException
213 {
214
215 return new RoleSet();
216 }
217
218 /**
219 * Retrieve a set of Permissions that meet the specified Criteria.
220 *
221 * @param criteria A Criteria of Permissions selection.
222 * @return a set of Permissions that meet the specified Criteria.
223 * @throws DataBackendException if there was an error accessing the data
224 * backend.
225 */
226 public PermissionSet getPermissions(Object criteria)
227 throws DataBackendException
228 {
229
230 return new PermissionSet();
231 }
232
233 /**
234 * Retrieves all permissions associated with a role.
235 *
236 * @param role the role name, for which the permissions are to be retrieved.
237 * @return A Permission set for the Role.
238 * @throws DataBackendException if there was an error accessing the data
239 * backend.
240 * @throws UnknownEntityException if the role is not present.
241 */
242 public PermissionSet getPermissions(Role role)
243 throws DataBackendException, UnknownEntityException
244 {
245 return null;
246 }
247
248 /**
249 * Stores Group's attributes. The Groups is required to exist in the system.
250 *
251 * @param group The Group to be stored.
252 * @throws DataBackendException if there was an error accessing the data
253 * backend.
254 * @throws UnknownEntityException if the group does not exist.
255 */
256 public void saveGroup(Group group)
257 throws DataBackendException, UnknownEntityException
258 {
259
260 }
261
262 /**
263 * Stores Role's attributes. The Roles is required to exist in the system.
264 *
265 * @param role The Role to be stored.
266 * @throws DataBackendException if there was an error accessing the data
267 * backend.
268 * @throws UnknownEntityException if the role does not exist.
269 */
270 public void saveRole(Role role)
271 throws DataBackendException, UnknownEntityException
272 {
273
274 }
275
276 /**
277 * Stores Permission's attributes. The Permissions is required to exist in
278 * the system.
279 *
280 * @param permission The Permission to be stored.
281 * @throws DataBackendException if there was an error accessing the data
282 * backend.
283 * @throws UnknownEntityException if the permission does not exist.
284 */
285 public void savePermission(Permission permission)
286 throws DataBackendException, UnknownEntityException
287 {
288
289 }
290
291 /**
292 * Creates a new group with specified attributes.
293 *
294 * @param group the object describing the group to be created.
295 * @return a new Group object that has id set up properly.
296 * @throws DataBackendException if there was an error accessing the data
297 * backend.
298 * @throws EntityExistsException if the group already exists.
299 */
300 public synchronized Group addGroup(Group group)
301 throws DataBackendException, EntityExistsException
302 {
303 return null;
304 }
305
306 /**
307 * Creates a new role with specified attributes.
308 *
309 * @param role the object describing the role to be created.
310 * @return a new Role object that has id set up properly.
311 * @throws DataBackendException if there was an error accessing the data
312 * backend.
313 * @throws EntityExistsException if the role already exists.
314 */
315 public synchronized Role addRole(Role role)
316 throws DataBackendException, EntityExistsException
317 {
318 return null;
319 }
320
321 /**
322 * Creates a new permission with specified attributes.
323 *
324 * @param permission the object describing the permission to be created.
325 * @return a new Permission object that has id set up properly.
326 * @throws DataBackendException if there was an error accessing the data
327 * backend.
328 * @throws EntityExistsException if the permission already exists.
329 */
330 public synchronized Permission addPermission(Permission permission)
331 throws DataBackendException, EntityExistsException
332 {
333 return null;
334 }
335
336 /**
337 * Removes a Group from the system.
338 *
339 * @param group The object describing the group to be removed.
340 * @throws DataBackendException if there was an error accessing the data
341 * backend.
342 * @throws UnknownEntityException if the group does not exist.
343 */
344 public synchronized void removeGroup(Group group)
345 throws DataBackendException, UnknownEntityException
346 {
347
348 }
349
350 /**
351 * Removes a Role from the system.
352 *
353 * @param role The object describing the role to be removed.
354 * @throws DataBackendException if there was an error accessing the data
355 * backend.
356 * @throws UnknownEntityException if the role does not exist.
357 */
358 public synchronized void removeRole(Role role)
359 throws DataBackendException, UnknownEntityException
360 {
361
362 }
363
364 /**
365 * Removes a Permission from the system.
366 *
367 * @param permission The object describing the permission to be removed.
368 * @throws DataBackendException if there was an error accessing the data
369 * backend.
370 * @throws UnknownEntityException if the permission does not exist.
371 */
372 public synchronized void removePermission(Permission permission)
373 throws DataBackendException, UnknownEntityException
374 {
375
376 }
377
378 /**
379 * Renames an existing Group.
380 *
381 * @param group The object describing the group to be renamed.
382 * @param name the new name for the group.
383 * @throws DataBackendException if there was an error accessing the data
384 * backend.
385 * @throws UnknownEntityException if the group does not exist.
386 */
387 public synchronized void renameGroup(Group group, String name)
388 throws DataBackendException, UnknownEntityException
389 {
390
391 }
392
393 /**
394 * Renames an existing Role.
395 *
396 * @param role The object describing the role to be renamed.
397 * @param name the new name for the role.
398 * @throws DataBackendException if there was an error accessing the data
399 * backend.
400 * @throws UnknownEntityException if the role does not exist.
401 */
402 public synchronized void renameRole(Role role, String name)
403 throws DataBackendException, UnknownEntityException
404 {
405
406 }
407
408 /**
409 * Renames an existing Permission.
410 *
411 * @param permission The object describing the permission to be renamed.
412 * @param name the new name for the permission.
413 * @throws DataBackendException if there was an error accessing the data
414 * backend.
415 * @throws UnknownEntityException if the permission does not exist.
416 */
417 public synchronized void renamePermission(
418 Permission permission,
419 String name)
420 throws DataBackendException, UnknownEntityException
421 {
422 }
423
424 public GroupSet getAllGroups() throws DataBackendException {
425 return null;
426 }
427 public PermissionSet getAllPermissions() throws DataBackendException {
428 return null;
429 }
430 public RoleSet getAllRoles() throws DataBackendException {
431 return null;
432 }
433 public List getUserList(Object criteria) throws DataBackendException {
434 return null;
435 }
436 }