KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > PolicyDatabase


1 package com.sslexplorer.policyframework;
2
3 import java.util.List JavaDoc;
4
5 import com.sslexplorer.boot.PropertyList;
6 import com.sslexplorer.core.Database;
7 import com.sslexplorer.realms.Realm;
8 import com.sslexplorer.security.SessionInfo;
9 import com.sslexplorer.security.User;
10
11 /**
12  * Implementations of this interface are responsible for all of the persistence
13  * of policy related data as well as performing the logic in checking whether or
14  * not a principal has access to a policy
15  *
16  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
17  */

18 public interface PolicyDatabase extends Database {
19     /**
20      * Register a new resource type.
21      *
22      * @param resourceType resource type to register
23      * @throws Exception on any error
24      */

25     public void registerResourceType(ResourceType resourceType) throws Exception JavaDoc ;
26     
27     /**
28      * De-register an existing resource type
29      *
30      * @param resourceType resource type to de-register
31      * @throws Exception on any error
32      */

33     public void deregisterResourceType(ResourceType resourceType) throws Exception JavaDoc ;
34
35     /**
36      * Get the number of resource types that have been registered.
37      *
38      * @return number of registered resource types
39      */

40     public int getResourceTypeCount();
41     
42
43     /**
44      * Get a {@link List} of all registered {@link ResourceType}s.
45      *
46      * @param permissionClass permission class or <code>null</code> for any
47      * @return list of resource types
48      * @throws Exception
49      */

50     public List JavaDoc getResourceTypes(String JavaDoc permissionClass) throws Exception JavaDoc;
51     
52     /**
53      * Get a {@link Policy} given its ID.
54      *
55      * @param id id of policy
56      * @return policy
57      * @throws Exception on any error
58      */

59     public Policy getPolicy(int id) throws Exception JavaDoc;
60     
61     /**
62      * Update a policy.
63      *
64      * @param policy policy to update
65      * @throws Exception on any error
66      */

67     public void updatePolicy(Policy policy) throws Exception JavaDoc ;
68     
69     /**
70      * Create a new policy. The returned {@link Policy} object will contain the
71      * newly assigned policy ID
72      *
73      * @param name policy name
74      * @param description policy description
75      * @param type policy type
76      * @param realmID
77      * @return Policy created policy object
78      * @throws Exception on any error
79      */

80     public Policy createPolicy(String JavaDoc name, String JavaDoc description, int type, int realmID) throws Exception JavaDoc;
81     
82     /**
83      * Delete a policy. If this policy is a parent of other policies then all
84      * child policies will also be deleted.
85      *
86      * @param id policy to delete
87      * @return deleted policy
88      * @throws Exception on any error
89      */

90     public Policy deletePolicy(int id) throws Exception JavaDoc;
91
92     /**
93      * Return a list of all policies for a given realm
94      * @param realm
95      *
96      * @return list of top level policies
97      * @throws Exception on any error
98      */

99     public List JavaDoc getPolicies(Realm realm) throws Exception JavaDoc;
100
101     /**
102      * Return a list of all policies
103      *
104      * @return list of top level policies
105      * @throws Exception on any error
106      */

107     public List JavaDoc<Policy> getPolicies() throws Exception JavaDoc;
108  
109     /**
110      * Grant a policy to a principal, giving it access to any resources that are
111      * attached to the policy
112      *
113      * @param policy policy to grant
114      * @param principal principal to grant to
115      * @throws Exception on any error
116      */

117     public void grantPolicyToPrincipal(Policy policy, Principal principal) throws Exception JavaDoc;
118
119     /**
120      * Revoke a policy from a principal, removing any access it may have to the
121      * resources that are attached to the policy.
122      *
123      * @param policy policy to revoke
124      * @param principal principal to revoke policy from
125      * @throws Exception on any error
126      */

127     public void revokePolicyFromPrincipal(Policy policy, Principal principal) throws Exception JavaDoc;
128
129     /**
130      * Revoke all policies from a specified principal
131      *
132      * @param principal principal to revoke policies from
133      * @throws Exception on any error
134      */

135     public void revokeAllPoliciesFromPrincipal(Principal principal) throws Exception JavaDoc ;
136     
137     /**
138      * Attach a resource to a policy, giving access to any principals that are
139      * attached the policy.
140      *
141      * @param resource resource to attach to policy
142      * @param policy policy to attach resource to
143      * @param sequence sequence
144      * @param realm
145      * @throws Exception on any error
146      */

147     public void attachResourceToPolicy(Resource resource, Policy policy, int sequence, Realm realm) throws Exception JavaDoc;
148     
149     /**
150      * Detach a resource from a policy, removing access from any principals that
151      * are attached the policy.
152      *
153      * @param resource resource to detach from the policy
154      * @param policy policy to detach resource from
155      * @param realm the realm the user is signon to
156      * @throws Exception on any error
157      */

158     public void detachResourceFromPolicy(Resource resource, Policy policy, Realm realm) throws Exception JavaDoc;
159
160     /**
161      * Determine if the specified resource is attached to the specified policy
162      *
163      * @param resource resource
164      * @param policy policy
165      * @param realm the ream the user is signed on to.
166      * @return attached
167      * @throws Exception
168      */

169     public boolean isResourceAttachedToPolicy(Resource resource, Policy policy, Realm realm) throws Exception JavaDoc;
170
171     /**
172      * Get if the provided {@link com.sslexplorer.policyframework.Principal} is
173      * allowed to access the specified
174      * {@link com.sslexplorer.policyframework.Resource}. If
175      * <code>null</code> is provided as the resource, <code>true</code> will
176      * be returned if the principal is allowed access to <strong>any</strong>
177      * resource.
178      *
179      * @param principal principal to test
180      * @param resource resource to test. <code>null</code> will test for any
181      * resource.
182      * @param includeSuperUser include the super user in the test for allowed
183      * @return allowed
184      * @throws Exception on any error
185      */

186     public boolean isPrincipalAllowed(Principal principal, Resource resource, boolean includeSuperUser) throws Exception JavaDoc;
187
188     /**
189      * Get if the principal is granted access via its policies to any resources
190      * of the given resource type. Supply <code>null</code> as the resource
191      * type to test if the principal is allowed access to any resources of any
192      * type.
193      * <p>
194      * Note that by default the super user will not be granted resources of
195      * the specified type, its up to the caller to treat super user as a
196      * special case.
197      *
198      * @param principal principal (user / role) to test against
199      * @param resourceType resource type to match or <code>null</code> for any resource type
200      * @param resourceTypesToExclude list of {@link ResourceType}s to exclude or null to exclude none
201      * @return allowed
202      * @throws Exception on any error
203      */

204     public boolean isPrincipalGrantedResourcesOfType(Principal principal, ResourceType resourceType, List JavaDoc resourceTypesToExclude) throws Exception JavaDoc;
205
206     /**
207      * Get the resources a principal is granted access via its policies
208      *
209      * @param principal principal
210      * @param resourceType resource type
211      * @return List of {@link Integer} objects containing the ids of the
212      * resources
213      * @throws Exception on any error
214      */

215     public List JavaDoc<Integer JavaDoc> getGrantedResourcesOfType(Principal principal, ResourceType resourceType) throws Exception JavaDoc;
216    
217
218     /**
219      * Get a list of {@link Policy} that are attached to a resource
220      *
221      * @param resource
222      * @param realm the realm of the user.
223      * @return list of policies
224      * @throws Exception on any error
225      */

226     public List JavaDoc<Policy> getPoliciesAttachedToResource(Resource resource, Realm realm) throws Exception JavaDoc;
227
228     /**
229      * Get a list of all {@link Principal}s granted the provided {@link Policy}
230      *
231      * @param policy
232      * @param realm
233      * @return list of principals
234      * @throws Exception
235      */

236     public List JavaDoc<Principal> getPrincipalsGrantedPolicy(Policy policy, Realm realm) throws Exception JavaDoc;
237
238     /**
239      * Revoke all policy from all principals
240      *
241      * @param policy
242      * @param realm
243      * @throws Exception on any error
244      */

245     public void revokePolicyFromAllPrincipals(Policy policy, Realm realm) throws Exception JavaDoc;
246
247     /**
248      * Get a resource type given its id.
249      *
250      * @param resourceTypeId
251      * @return resource type
252      */

253     public ResourceType getResourceType(int resourceTypeId);
254     
255     /**
256      * Get a policy given its name.
257      *
258      * @param name policy name
259      * @param realmID
260      * @return policy object
261      * @throws Exception on any error
262      */

263     public Policy getPolicyByName(String JavaDoc name, int realmID) throws Exception JavaDoc;
264
265     
266     /**
267      * Create a resource permission. The ID will be set upon success. The same
268      * object instance will be returned
269      *
270      * @param accessRights access rights
271      * @return resource
272      * @throws Exception
273      */

274     public AccessRights createAccessRights(AccessRights accessRights) throws Exception JavaDoc;
275
276     /**
277      * Get the complete list of {@link AccessRights} objects
278      *
279      * @return list of resource permissions
280      * @throws Exception on any error
281      */

282     public List JavaDoc<AccessRights> getAccessRights() throws Exception JavaDoc;
283
284     /**
285      * Get the complete list of {@link AccessRights} objects
286      *
287      * @return list of resource permissions
288      * @throws Exception on any error
289      */

290     public List JavaDoc<AccessRights> getAccessRights(int realmID) throws Exception JavaDoc;
291     
292     /**
293      * Get a resource permission given its name.
294      *
295      * @param name resource permission
296      * @param realmID
297      * @return delegation resource object
298      * @throws Exception on any error
299      */

300     public AccessRights getAccessRightsByName(String JavaDoc name, int realmID) throws Exception JavaDoc;
301
302     /**
303      * Get a resource permission given its id
304      *
305      * @param id
306      * @return resource permission
307      * @throws Exception on any error
308      */

309     public AccessRights getAccessRight(int id) throws Exception JavaDoc;
310
311     /**
312      * Determine whether an action can be performed by checking the resource
313      * permission tree.
314      *
315      * @param resourceType resource type to check
316      * @param permissions permissions required
317      * @param user user to check
318      * @param all all permissions are check rather than any if true
319      * @return resource permission is allowed
320      * @throws Exception on any error
321      */

322     public boolean isPermitted(ResourceType resourceType, Permission[] permissions, User user, boolean all)
323         throws Exception JavaDoc;
324
325     /**
326      * Get a list of {@link AccessRights} objects that are valid for user
327      * to view / edit.
328      *
329      * @param resourceType resource type to check or null for any
330      * @param permission permission required or null for any
331      * @param permissionClass class of resource permission or null for any
332      * @param user user to check (may not be null)
333      * @return list of resource permission objects
334      * @throws Exception on any error
335      */

336     public List JavaDoc<AccessRights> getAccessRights(ResourceType resourceType, Permission permission, String JavaDoc permissionClass, User user)
337         throws Exception JavaDoc;
338
339     /**
340      * Get a list of {@link AccessRights} objects that are permit the the
341      * specified user to perform an action.
342      *
343      * @param resourceType resource type to check or null for any
344      * @param permission permission required or null for any
345      * @param permissionClass class of resource permission or null for any
346      * @param user user to check (may not be null)
347      * @return list of resource permission objects
348      * @throws Exception on any error
349      */

350     public List JavaDoc<AccessRights> getPermittingAccessRights(ResourceType resourceType, Permission permission, String JavaDoc permissionClass, User user) throws Exception JavaDoc;
351
352     /**
353      * Determine whether the user can perform <strong>any</strong>
354      * administrative actions using the delegation tree.
355      *
356      * @param user user to check
357      * @param delegation include deletation class
358      * @param system include system class
359      * @param personal include personal class
360      * @return allowed
361      * @throws Exception on any error
362      */

363     public boolean isAnyAccessRightAllowed(User user, boolean delegation, boolean system, boolean personal) throws Exception JavaDoc;
364     
365     /**
366      * Delete a resource permission given its id
367      *
368      * @param id id to remove
369      * @return deleted resource permission
370      * @throws Exception on any error
371      */

372     public AccessRights deleteAccessRights(int id) throws Exception JavaDoc;
373     
374     /**
375      * Update a resource permission
376      *
377      * @param permission permission to update
378      * @throws Exception on any error
379      */

380     public void updateAccessRights(AccessRights permission) throws Exception JavaDoc;
381
382     /**
383      * Load the access rights
384      *
385      * @throws Exception on any error
386      */

387     public void initAccessRights() throws Exception JavaDoc;
388
389     /**
390      * Get a list of {@link Policy} objects that have been delegated ANY
391      * permission to maintain a resource type. A permission class may also be
392      * specified
393      *
394      * @param resourceType resource type
395      * @param permissionClass permission class
396      * @param user user
397      * @return list of policies
398      * @throws Exception on any error
399      */

400     public List JavaDoc<Policy> getPoliciesOfDelegatedAccessRights(ResourceType resourceType, String JavaDoc permissionClass, User user)
401                     throws Exception JavaDoc;
402     
403     /**
404      * Get the Everyone policy for a given realm, there is only one Everyone policy per realm.
405      * @param realm
406      * @return int
407      * @throws Exception
408      */

409     public int getEveryonePolicyIDForRealm(Realm realm)throws Exception JavaDoc;
410     
411     /**
412      * Check to see if the resource is connected to a policy in the defined realm.
413      *
414      * @param resource
415      * @param realm
416      * @return boolean
417      * @throws Exception
418      */

419     public boolean isResourceInRealm(Resource resource, Realm realm) throws Exception JavaDoc;
420
421     /**
422      * Get the granting policy for the user or the attached roles.
423      *
424      * @param user
425      * @param resource
426      * @return Policy
427      * @throws Exception
428      */

429     public Policy getGrantingPolicyForUser(User user, Resource resource) throws Exception JavaDoc;
430
431     /**
432      * Method to verify whether a policy is granted to a user. This checks the policy for both the user and
433      * their allocated groups.
434      *
435      * @param policy
436      * @param user
437      * @return boolean
438      * @throws Exception
439      */

440     public boolean isPolicyGrantedToUser(Policy policy, User user) throws Exception JavaDoc;
441
442     /**
443      * Detach a resource from ALL policies it is attached to
444      *
445      * @param resource resource to detach
446      * @param session originating session
447      * @throws Exception on any error
448      */

449     public void detachResourceFromPolicyList(Resource resource, SessionInfo session) throws Exception JavaDoc;
450
451     /**
452      * Attach a resource to a list of policies
453      *
454      * @param resource resource to attach
455      * @param selectedPolicies policies to attach to
456      * @param session originating session
457      * @throws Exception
458      */

459     public void attachResourceToPolicyList(Resource resource, PropertyList selectedPolicies, SessionInfo session) throws Exception JavaDoc;
460
461 }
462
Popular Tags