View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/server/src/java/org/astrogrid/community/server/policy/manager/PolicyManagerImpl.java,v $</cvs:source>
3    * <cvs:author>$Author: jdt $</cvs:author>
4    * <cvs:date>$Date: 2004/11/22 13:03:04 $</cvs:date>
5    * <cvs:version>$Revision: 1.14 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: PolicyManagerImpl.java,v $
9    *   Revision 1.14  2004/11/22 13:03:04  jdt
10   *   Merges from Comm_KMB_585
11   *
12   *   Revision 1.13  2004/10/29 15:50:05  jdt
13   *   merges from Community_AdminInterface (bug 579)
14   *
15   *   Revision 1.12.18.1  2004/10/18 22:10:28  KevinBenson
16   *   some bug fixes to the PermissionManager.  Also made it throw some exceptions.
17   *   Made  it and GroupManagerImnpl use the Resolver objects to actually get a group(PermissionManageriMnpl)
18   *   or account (GroupMember) from the other community.  Changed also for it to grab a ResourceData from the
19   *   database to verifity it is in our database.  Add a few of these resolver dependencies as well.
20   *   And last but not least fixed the GroupMemberData object to get rid of a few set methods so Castor
21   *   will now work correctly in Windows
22   *
23   *   Revision 1.12  2004/09/16 23:18:08  dave
24   *   Replaced debug logging in Community.
25   *   Added stream close() to FileStore.
26   *
27   *   Revision 1.11.82.1  2004/09/16 09:58:48  dave
28   *   Replaced debug with commons logging ....
29   *
30   *   Revision 1.11  2004/06/18 13:45:20  dave
31   *   Merged development branch, dave-dev-200406081614, into HEAD
32   *
33   *   Revision 1.10.32.3  2004/06/17 15:24:31  dave
34   *   Removed unused imports (PMD report).
35   *
36   *   Revision 1.10.32.2  2004/06/17 13:38:59  dave
37   *   Tidied up old CVS log entries
38   *
39   * </cvs:log>
40   *
41   */
42  package org.astrogrid.community.server.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.GroupData ;
50  import org.astrogrid.community.common.policy.data.AccountData ;
51  import org.astrogrid.community.common.policy.data.ResourceData;
52  import org.astrogrid.community.common.policy.data.GroupMemberData ;
53  import org.astrogrid.community.common.policy.data.PolicyPermission ;
54  
55  import org.astrogrid.community.common.policy.manager.PolicyManager ;
56  
57  import org.astrogrid.community.server.service.CommunityServiceImpl ;
58  import org.astrogrid.community.server.database.configuration.DatabaseConfiguration ;
59  
60  import org.astrogrid.community.common.exception.CommunityPolicyException     ;
61  import org.astrogrid.community.common.exception.CommunityServiceException    ;
62  import org.astrogrid.community.common.exception.CommunityResourceException ;
63  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
64  
65  /***
66   * Server side implementation of the PolicyManager service.
67   *
68   */
69  public class PolicyManagerImpl
70      extends CommunityServiceImpl
71      implements PolicyManager
72      {
73      /***
74       * Our debug logger.
75       *
76       */
77      private static Log log = LogFactory.getLog(PolicyManagerImpl.class);
78  
79      /***
80       * Public constructor, using default database configuration.
81       *
82       */
83      public PolicyManagerImpl()
84          {
85          super() ;
86          //
87          // Initialise our local managers.
88          initManagers() ;
89          }
90  
91      /***
92       * Public constructor, using specific database configuration.
93       *
94       */
95      public PolicyManagerImpl(DatabaseConfiguration config)
96          {
97          super(config) ;
98          //
99          // Initialise our local managers.
100         initManagers() ;
101         }
102 
103     /***
104      * Public constructor, using a parent service.
105      *
106      */
107     public PolicyManagerImpl(CommunityServiceImpl parent)
108         {
109         super(parent) ;
110         //
111         // Initialise our local managers.
112         initManagers() ;
113         }
114 
115     /***
116      * Initialise our local managers, passing a reference to 'this' as their parent.
117      * @todo Refactor this into default initialiser.
118      *
119      */
120     private void initManagers()
121         {
122         accountManager    = new AccountManagerImpl(this)    ;
123         resourceManager   = new ResourceManagerImpl(this)   ;
124         permissionManager = new PermissionManagerImpl(this) ;
125 
126         /*
127          * The GroupManager needs access to the current AccountManagerImpl because Castor maintains an
128          * in-memory cache of AccountData objects, with read-write locks.
129          */
130         groupManager = new GroupManagerImpl(this, accountManager) ;
131         permissionManager = new PermissionManagerImpl(this,groupManager, resourceManager);
132 
133         }
134 
135     /***
136      * Our GroupManager.
137      *
138      */
139     private GroupManagerImpl groupManager ;
140 
141     /***
142      * Our AccountManager.
143      *
144      */
145     private AccountManagerImpl accountManager ;
146 
147     /***
148      * Our ResourceManager
149      *
150      */
151     private ResourceManagerImpl resourceManager ;
152 
153     /***
154      * Our PermissionManager
155      *
156      */
157     private PermissionManagerImpl permissionManager ;
158 
159     /***
160      * Add a new Account, given the Account ident.
161      * @param  ident The Account identifier.
162      * @return An AccountData for the Account.
163      * @throws CommunityIdentifierException If the identifier is not valid.
164      * @throws CommunityPolicyException If the identifier is already in the database.
165      * @throws CommunityServiceException If there is an internal error in the service.
166      *
167      */
168     public AccountData addAccount(String ident)
169         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
170         {
171         return accountManager.addAccount(ident) ;
172         }
173 
174     /***
175      * Add a new Account, given the Account data.
176      * @param  account The AccountData to add.
177      * @return A new AccountData for the Account.
178      * @throws CommunityIdentifierException If the identifier is not valid.
179      * @throws CommunityPolicyException If the identifier is already in the database.
180      * @throws CommunityServiceException If there is an internal error in the service.
181      *
182      */
183     public AccountData addAccount(AccountData account)
184         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
185         {
186         return accountManager.addAccount(account) ;
187         }
188 
189     /***
190      * Request an Account details, given the Account ident.
191      * @param  ident The Account identifier.
192      * @return An AccountData for the Account.
193      * @throws CommunityIdentifierException If the identifier is not valid.
194      * @throws CommunityPolicyException If the identifier is not in the database.
195      * @throws CommunityServiceException If there is an internal error in the service.
196      *
197      */
198     public AccountData getAccount(String ident)
199         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
200         {
201         return accountManager.getAccount(ident) ;
202         }
203 
204     /***
205      * Update an Account.
206      * @param  account The new AccountData to update.
207      * @return A new AccountData for the Account.
208      * @throws CommunityIdentifierException If the identifier is not valid.
209      * @throws CommunityPolicyException If the identifier is not in the database.
210      * @throws CommunityServiceException If there is an internal error in the service.
211      *
212      */
213     public AccountData setAccount(AccountData account)
214         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
215         {
216         return accountManager.setAccount(account) ;
217         }
218 
219     /***
220      * Delete an Account.
221      * @param  ident The Account identifier.
222      * @return The AccountData for the old Account.
223      * @throws CommunityIdentifierException If the identifier is not valid.
224      * @throws CommunityPolicyException If the identifier is not in the database.
225      * @throws CommunityServiceException If there is an internal error in the service.
226      *
227      */
228     public AccountData delAccount(String ident)
229         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
230         {
231         return accountManager.delAccount(ident) ;
232         }
233 
234     /***
235      * Request a list of local Accounts.
236      * @return An array of AccountData objects.
237      * @throws CommunityServiceException If there is an internal error in the service.
238      *
239      */
240     public Object[] getLocalAccounts()
241         throws CommunityServiceException
242         {
243         return accountManager.getLocalAccounts() ;
244         }
245 
246     /***
247      * Add a new Group.
248      * @param  ident The Group identifier.
249      * @return A GroupData for the Group.
250      * @throws CommunityIdentifierException If the identifier is not valid.
251      * @throws CommunityPolicyException If the identifier is already in the database.
252      * @throws CommunityServiceException If there is an internal error in the service.
253      *
254      */
255     public GroupData addGroup(String ident)
256         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
257         {
258         return groupManager.addGroup(ident) ;
259         }
260 
261     /***
262      * Add a new Group.
263      * @param  group The Group data.
264      * @return A GroupData for the Group.
265      * @throws CommunityIdentifierException If the identifier is not valid.
266      * @throws CommunityPolicyException If the identifier is already in the database.
267      * @throws CommunityServiceException If there is an internal error in the service.
268      *
269      */
270     public GroupData addGroup(GroupData group)
271         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
272         {
273         return groupManager.addGroup(group) ;
274         }
275 
276     /***
277      * Request a Group details.
278      * @param  ident The Group identifier.
279      * @return A GroupData for the Group.
280      * @throws CommunityIdentifierException If the identifier is not valid.
281      * @throws CommunityPolicyException If the identifier is not in the database.
282      * @throws CommunityServiceException If there is an internal error in the service.
283      *
284      */
285     public GroupData getGroup(String ident)
286         throws RemoteException, CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
287         {
288         return groupManager.getGroup(ident) ;
289         }
290 
291     /***
292      * Update a Group.
293      * @param  group The new GroupData to update.
294      * @return A new GroupData for the Group.
295      * @throws CommunityIdentifierException If the identifier is not valid.
296      * @throws CommunityPolicyException If the identifier is not in the database.
297      * @throws CommunityServiceException If there is an internal error in the service.
298      *
299      */
300     public GroupData setGroup(GroupData group)
301         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
302         {
303         return groupManager.setGroup(group) ;
304         }
305 
306     /***
307      * Delete a Group.
308      * @param  ident The Group identifier.
309      * @return The GroupData for the old Group.
310      * @throws CommunityIdentifierException If the identifier is not valid.
311      * @throws CommunityPolicyException If the identifier is not in the database.
312      * @throws CommunityServiceException If there is an internal error in the service.
313      *
314      */
315     public GroupData delGroup(String ident)
316         throws RemoteException, CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
317         {
318         return groupManager.delGroup(ident) ;
319         }
320 
321     /***
322      * Request a list of local Groups.
323      * @return An array of GroupData objects.
324      * @throws CommunityServiceException If there is an internal error in the service.
325      *
326      */
327     public Object[] getLocalGroups()
328         throws CommunityServiceException
329         {
330         return groupManager.getLocalGroups() ;
331         }
332 
333     /***
334      * Add an Account to a Group.
335      * The group must be local, but Account can be local or remote.
336      * @param  account The Account identifier.
337      * @param  group   The Group identifier.
338      * @return A GroupMemberData to confirm the membership.
339      * @throws CommunityIdentifierException If one of the identifiers is not valid.
340      * @throws CommunityPolicyException If one the identifiers is not in the database.
341      * @throws CommunityServiceException If there is an internal error in the service.
342      *
343      */
344     public GroupMemberData addGroupMember(String account, String group)
345         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
346         {
347         return groupManager.addGroupMember(account, group) ;
348         }
349 
350     /***
351      * Remove an Account from a Group.
352      * The group must be local, but Account can be local or remote.
353      * @param  account The Account identifier.
354      * @param  group   The Group identifier.
355      * @return A GroupMemberData to confirm the membership.
356      * @throws CommunityIdentifierException If one of the identifiers is not valid.
357      * @throws CommunityPolicyException If one the identifiers is not in the database.
358      * @throws CommunityPolicyException If the Group is private, for a single Account only.
359      * @throws CommunityServiceException If there is an internal error in the service.
360      *
361      */
362     public GroupMemberData delGroupMember(String account, String group)
363         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
364         {
365         return groupManager.delGroupMember(account, group) ;
366         }
367 
368     /***
369      * Request a list of Group Members.
370      * @param group The Group identifier.
371      * @return An array of GroupMemberData objects.
372      * @throws CommunityIdentifierException If one of the identifiers is not valid.
373      * @throws CommunityPolicyException If the group is not local.
374      * @throws CommunityServiceException If there is an internal error in the service.
375      *
376      */
377     public Object[] getGroupMembers(String group)
378         throws RemoteException, CommunityServiceException, CommunityPolicyException, CommunityIdentifierException
379         {
380         return groupManager.getGroupMembers(group) ;
381         }
382     
383     
384 
385     /***
386      * Request a list of Group Members.
387      * @param group The Group identifier.
388      * @return An array of GroupMemberData objects.
389      * @throws CommunityIdentifierException If one of the identifiers is not valid.
390      * @throws CommunityPolicyException If the group is not local.
391      * @throws CommunityServiceException If there is an internal error in the service.
392      *
393      */
394     public GroupMemberData getGroupMember(String account, String group)
395         throws RemoteException, CommunityServiceException, CommunityPolicyException, CommunityIdentifierException
396         {
397         return groupManager.getGroupMember(account, group) ;
398         }    
399     
400     /***
401      * Request a list of Group Members.
402      * @param group The Group identifier.
403      * @return An array of GroupMemberData objects.
404      * @throws CommunityIdentifierException If one of the identifiers is not valid.
405      * @throws CommunityPolicyException If the group is not local.
406      * @throws CommunityServiceException If there is an internal error in the service.
407      *
408      */
409     public Object[] getGroupMembers()
410         throws RemoteException, CommunityServiceException, CommunityPolicyException, CommunityIdentifierException
411         {
412         return groupManager.getGroupMembers() ;
413         }
414     
415 
416     /***
417      * Request a list of Groups that an Account belongs to.
418      * @param account The Account identifier.
419      * @return An array of GroupMemberData objects.
420      * @throws CommunityIdentifierException If one of the identifiers is not valid.
421      * @throws CommunityServiceException If there is an internal error in the service.
422      *
423      */
424     public Object[] getLocalAccountGroups(String account)
425         throws CommunityServiceException, CommunityIdentifierException
426         {
427         return groupManager.getLocalAccountGroups(account) ;
428         }
429 
430     /***
431      * Register a new Resource.
432      * @return A new ResourceData object to represent the resource.
433      * @throws CommunityServiceException If there is an internal error in the service.
434      * @throws RemoteException If the WebService call fails.
435      *
436      */
437     public ResourceData addResource()
438         throws RemoteException, CommunityServiceException
439         {
440         return resourceManager.addResource();
441         }
442 
443     /***
444      * Request a Resource details.
445      * @param The resource identifier.
446      * @return The requested ResourceData object.
447      * @throws CommunityIdentifierException If the identifier is not valid.
448      * @throws CommunityResourceException If unable to locate the resource.
449      * @throws CommunityServiceException If there is an internal error in the service.
450      * @throws RemoteException If the WebService call fails.
451      *
452      */
453    public ResourceData getResource(String ident)
454         throws RemoteException, CommunityIdentifierException, CommunityResourceException, CommunityServiceException
455         {
456         return resourceManager.getResource(ident);
457         }
458    
459    /***
460     * Request a Resource details.
461     * @return The requested ResourceData object.
462     * @throws CommunityIdentifierException If the identifier is not valid.
463     * @throws CommunityResourceException If unable to locate the resource.
464     * @throws CommunityServiceException If there is an internal error in the service.
465     * @throws RemoteException If the WebService call fails.
466     *
467     */
468   public Object[] getResources() throws RemoteException
469        {
470        return resourceManager.getResources();
471        }
472    
473 
474     /***
475      * Update a Resource details.
476      * @param The ResourceData to update.
477      * @return The updated ResourceData.
478      * @throws CommunityIdentifierException If the resource identifier is not valid.
479      * @throws CommunityResourceException If unable to locate the resource.
480      * @throws CommunityServiceException If there is an internal error in the service.
481      * @throws RemoteException If the WebService call fails.
482      *
483      */
484     public ResourceData setResource(ResourceData resource)
485         throws RemoteException, CommunityIdentifierException, CommunityResourceException, CommunityServiceException
486         {
487         return resourceManager.setResource(resource);
488         }
489 
490     /***
491      * Delete a Resource object.
492      * @param The resource identifier.
493      * @return The original ResourceData.
494      * @throws CommunityIdentifierException If the resource identifier is not valid.
495      * @throws CommunityResourceException If unable to locate the resource.
496      * @throws CommunityServiceException If there is an internal error in the service.
497      * @throws RemoteException If the WebService call fails.
498      *
499      */
500     public ResourceData delResource(String ident)
501         throws RemoteException, CommunityIdentifierException, CommunityResourceException, CommunityServiceException
502         {
503         return resourceManager.delResource(ident);
504         }
505 
506     /***
507      * Create a new PolicyPermission.
508      *
509      */
510     public PolicyPermission addPermission(String resource, String group, String action)
511         throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
512         {
513         return permissionManager.addPermission(resource, group, action) ;
514         }
515 
516     /***
517      * Request a PolicyPermission.
518      *
519      */
520     public PolicyPermission getPermission(String resource, String group, String action)
521     throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
522         {
523         return permissionManager.getPermission(resource, group, action) ;
524         }
525     
526     /***
527      * Request a PolicyPermission.
528      *
529      */
530     public Object[] getPermissions() {
531         return permissionManager.getPermissions() ;
532     }
533     
534 
535     /***
536      * Update a PolicyPermission.
537      *
538      */
539     public PolicyPermission setPermission(PolicyPermission permission)
540     throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException
541         {
542         return permissionManager.setPermission(permission) ;
543         }
544 
545     /***
546      * Delete a PolicyPermission.
547      *
548      */
549     public boolean delPermission(String resource, String group, String action)
550        throws CommunityServiceException, CommunityIdentifierException, CommunityPolicyException    
551         {
552         return permissionManager.delPermission(resource, group, action) ;
553         }
554 
555     }
556 
557 
558