1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 package org.astrogrid.community.common.policy.manager ;
43
44 import org.apache.commons.logging.Log ;
45 import org.apache.commons.logging.LogFactory ;
46
47 import java.rmi.RemoteException ;
48
49 import org.astrogrid.community.common.policy.data.AccountData ;
50 import org.astrogrid.community.common.policy.data.GroupData ;
51 import org.astrogrid.community.common.policy.data.ResourceData ;
52 import org.astrogrid.community.common.policy.data.PolicyPermission ;
53 import org.astrogrid.community.common.policy.data.GroupMemberData ;
54
55 import org.astrogrid.community.common.service.CommunityServiceMock ;
56
57 import org.astrogrid.community.common.exception.CommunityPolicyException ;
58 import org.astrogrid.community.common.exception.CommunityServiceException ;
59 import org.astrogrid.community.common.exception.CommunityResourceException ;
60 import org.astrogrid.community.common.exception.CommunityIdentifierException ;
61
62 /***
63 * Mock implementation of our PolicyManager service.
64 *
65 */
66 public class PolicyManagerMock
67 extends CommunityServiceMock
68 implements PolicyManager
69 {
70 /***
71 * Our debug logger.
72 *
73 */
74 private static Log log = LogFactory.getLog(PolicyManagerMock.class);
75
76 /***
77 * Public constructor.
78 *
79 */
80 public PolicyManagerMock()
81 {
82 super() ;
83 log.debug("") ;
84 log.debug("----\"----") ;
85 log.debug("PolicyManagerMock()") ;
86 }
87
88 /***
89 * Our AccountManager.
90 *
91 */
92 private AccountManagerMock accountManager = new AccountManagerMock() ;
93
94 /***
95 * Add a new Account, given the Account ident.
96 * @param ident The Account identifier.
97 * @return An AccountData for the Account.
98 * @throws CommunityIdentifierException If the identifier is not valid.
99 * @throws CommunityPolicyException If the identifier is already in the database.
100 *
101 */
102 public AccountData addAccount(String ident)
103 throws CommunityIdentifierException, CommunityPolicyException
104 {
105 return accountManager.addAccount(ident) ;
106 }
107
108 /***
109 * Add a new Account, given the Account data.
110 * @param account The AccountData to add.
111 * @return A new AccountData for the Account.
112 * @throws CommunityIdentifierException If the identifier is not valid.
113 * @throws CommunityPolicyException If the identifier is already in the database.
114 *
115 */
116 public AccountData addAccount(AccountData account)
117 throws CommunityIdentifierException, CommunityPolicyException
118 {
119 return accountManager.addAccount(account) ;
120 }
121
122 /***
123 * Request an Account details, given the Account ident.
124 * @param ident The Account identifier.
125 * @return An AccountData for the Account.
126 * @throws CommunityIdentifierException If the identifier is not valid.
127 * @throws CommunityPolicyException If the identifier is not in the database.
128 *
129 */
130 public AccountData getAccount(String ident)
131 throws CommunityIdentifierException, CommunityPolicyException
132 {
133 return accountManager.getAccount(ident) ;
134 }
135
136 /***
137 * Update an Account.
138 * @param update The new Account data to update.
139 * @return A new AccountData for the Account.
140 * @throws CommunityIdentifierException If the identifier is not valid.
141 * @throws CommunityPolicyException If the identifier is not in the database.
142 *
143 */
144 public AccountData setAccount(AccountData update)
145 throws CommunityIdentifierException, CommunityPolicyException
146 {
147 return accountManager.setAccount(update) ;
148 }
149
150 /***
151 * Delete an Account.
152 * @param ident The Account identifier.
153 * @return The AccountData for the old Account.
154 * @throws CommunityIdentifierException If the identifier is not valid.
155 * @throws CommunityPolicyException If the identifier is not in the database.
156 *
157 */
158 public AccountData delAccount(String ident)
159 throws CommunityIdentifierException, CommunityPolicyException
160 {
161 return accountManager.delAccount(ident) ;
162 }
163
164 /***
165 * Request a list of local Accounts.
166 * @return An array of AccountData objects.
167 *
168 */
169 public Object[] getLocalAccounts()
170 {
171 return accountManager.getLocalAccounts() ;
172 }
173
174
175 /***
176 * Our GroupManager.
177 *
178 */
179 private GroupManagerMock groupManager = new GroupManagerMock() ;
180
181 /***
182 * Add a new Group, given the Group ident.
183 * @param ident The Group identifier.
184 * @return An GroupData for the Group.
185 * @throws CommunityIdentifierException If the identifier is not valid.
186 * @throws CommunityPolicyException If the identifier is already in the database.
187 *
188 */
189 public GroupData addGroup(String ident)
190 throws CommunityIdentifierException, CommunityPolicyException
191 {
192 return groupManager.addGroup(ident) ;
193 }
194
195 /***
196 * Add a new Group, given the Group data.
197 * @param data The GroupData to add.
198 * @return A new GroupData for the Group.
199 * @throws CommunityIdentifierException If the identifier is not valid.
200 * @throws CommunityPolicyException If the identifier is already in the database.
201 *
202 */
203 public GroupData addGroup(GroupData group)
204 throws CommunityIdentifierException, CommunityPolicyException
205 {
206 return groupManager.addGroup(group) ;
207 }
208
209 /***
210 * Request a Group details, given the Group ident.
211 * @param ident The Group identifier.
212 * @return An GroupData for the Group.
213 * @throws CommunityIdentifierException If the identifier is not valid.
214 * @throws CommunityPolicyException If the identifier is not in the database.
215 *
216 */
217 public GroupData getGroup(String ident)
218 throws CommunityIdentifierException, CommunityPolicyException
219 {
220 return groupManager.getGroup(ident) ;
221 }
222
223 /***
224 * Update a Group.
225 * @param update The new Group data to update.
226 * @return A new GroupData for the Group.
227 * @throws CommunityIdentifierException If the identifier is not valid.
228 * @throws CommunityPolicyException If the identifier is not in the database.
229 *
230 */
231 public GroupData setGroup(GroupData update)
232 throws CommunityIdentifierException, CommunityPolicyException
233 {
234 return groupManager.setGroup(update) ;
235 }
236
237 /***
238 * Delete a Group.
239 * @param ident The Group identifier.
240 * @return The GroupData for the old Group.
241 * @throws CommunityIdentifierException If the identifier is not valid.
242 * @throws CommunityPolicyException If the identifier is not in the database.
243 *
244 */
245 public GroupData delGroup(String ident)
246 throws CommunityIdentifierException, CommunityPolicyException
247 {
248 return groupManager.delGroup(ident) ;
249 }
250
251 /***
252 * Request a list of local Groups.
253 * @return An array of GroupData objects.
254 *
255 */
256 public Object[] getLocalGroups()
257 {
258 return groupManager.getLocalGroups() ;
259 }
260
261 /***
262 * Get a list of local Groups that an Account belongs to.
263 * @return An array of GroupData objects.
264 *
265 */
266 public Object[] getLocalAccountGroups(String account)
267 {
268 return groupManager.getLocalAccountGroups(account) ;
269 }
270
271
272 /***
273 * Our ResourceManager.
274 *
275 */
276 private ResourceManagerMock resourceManager = new ResourceManagerMock() ;
277
278 /***
279 * Register a new Resource.
280 * @return A new ResourceData object to represent the resource.
281 * @throws CommunityServiceException If there is an internal error in the service.
282 *
283 */
284 public ResourceData addResource()
285 throws CommunityServiceException
286 {
287 return resourceManager.addResource() ;
288 }
289
290 /***
291 * Request a Resource details.
292 * @param The resource identifier.
293 * @return The requested ResourceData object.
294 * @throws CommunityIdentifierException If the identifier is not valid.
295 * @throws CommunityResourceException If unable to locate the resource.
296 * @throws CommunityServiceException If there is an internal error in the service.
297 *
298 */
299 public ResourceData getResource(String ident)
300 throws CommunityIdentifierException, CommunityResourceException, CommunityServiceException
301 {
302 return resourceManager.getResource(ident) ;
303 }
304
305 /***
306 * Request a Resource details.
307 * @return The requested ResourceData object.
308 * @throws CommunityIdentifierException If the identifier is not valid.
309 * @throws CommunityResourceException If unable to locate the resource.
310 * @throws CommunityServiceException If there is an internal error in the service.
311 *
312 */
313 public Object[] getResources()
314 {
315 return resourceManager.getResources() ;
316 }
317
318
319 /***
320 * Update a Resource details.
321 * @param The ResourceData to update.
322 * @return The updated ResourceData.
323 * @throws CommunityIdentifierException If the resource identifier is not valid.
324 * @throws CommunityResourceException If unable to locate the resource.
325 * @throws CommunityServiceException If there is an internal error in the service.
326 *
327 */
328 public ResourceData setResource(ResourceData resource)
329 throws CommunityIdentifierException, CommunityResourceException, CommunityServiceException
330 {
331 return resourceManager.setResource(resource) ;
332 }
333
334 /***
335 * Delete a Resource object.
336 * @param The resource identifier.
337 * @return The original ResourceData.
338 * @throws CommunityIdentifierException If the resource identifier is not valid.
339 * @throws CommunityResourceException If unable to locate the resource.
340 * @throws CommunityServiceException If there is an internal error in the service.
341 *
342 */
343 public ResourceData delResource(String ident)
344 throws CommunityIdentifierException, CommunityResourceException, CommunityServiceException
345 {
346 return resourceManager.delResource(ident) ;
347 }
348
349 private GroupMemberManagerMock groupMemberManager = new GroupMemberManagerMock();
350
351 public GroupMemberData addGroupMember(String account, String group)
352 throws CommunityIdentifierException, CommunityPolicyException, CommunityServiceException
353 {
354 return groupMemberManager.addGroupMember(account,group);
355 }
356
357 public GroupMemberData delGroupMember(String account, String group)
358 throws CommunityIdentifierException, CommunityPolicyException, CommunityServiceException
359 {
360 return groupMemberManager.delGroupMember(account,group);
361 }
362
363 public Object[] getGroupMembers(String group)
364 throws CommunityIdentifierException, CommunityPolicyException, CommunityServiceException
365 {
366 return groupMemberManager.getGroupMembers(group);
367 }
368
369 public GroupMemberData getGroupMember(String account, String group)
370 throws CommunityIdentifierException, CommunityPolicyException, CommunityServiceException
371 {
372 return groupMemberManager.getGroupMember(account,group);
373 }
374
375 public Object[] getGroupMembers()
376 throws CommunityIdentifierException, CommunityPolicyException, CommunityServiceException
377 {
378 return groupMemberManager.getGroupMembers();
379 }
380
381
382 /***
383 * Our PermissionManager.
384 *
385 */
386 private PermissionManagerMock permissionManager = new PermissionManagerMock() ;
387
388 /***
389 * Create a new PolicyPermission.
390 *
391 */
392 public PolicyPermission addPermission(String resource, String group, String action)
393 throws RemoteException
394 {
395 return permissionManager.addPermission(resource, group, action) ;
396 }
397
398 /***
399 * Request a PolicyPermission.
400 *
401 */
402 public PolicyPermission getPermission(String resource, String group, String action)
403 throws RemoteException
404 {
405 return permissionManager.getPermission(resource, group, action) ;
406 }
407
408 /***
409 * Request a PolicyPermission.
410 *
411 */
412 public Object[] getPermissions()
413 throws RemoteException
414 {
415 return permissionManager.getPermissions();
416 }
417
418
419 /***
420 * Update a PolicyPermission.
421 *
422 */
423 public PolicyPermission setPermission(PolicyPermission permission)
424 {
425 return permissionManager.setPermission(permission) ;
426 }
427
428 /***
429 * Delete a PolicyPermission.
430 *
431 */
432 public boolean delPermission(String resource, String group, String action)
433 throws RemoteException
434 {
435 return permissionManager.delPermission(resource, group, action) ;
436 }
437
438
439 }