KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > identity > security > IdentityPolicy


1 package org.jbpm.identity.security;
2
3 import java.security.*;
4 import java.util.*;
5 import org.jbpm.identity.Entity;
6
7 /**
8  * a java.security.Policy implementation that in combination with the
9  * IdentityLoginModule enforces the secirity permissions modelled as
10  * in the package org.jbpm.identity.
11  */

12 public class IdentityPolicy extends Policy {
13   
14   public static final PermissionCollection ALL_PERMISSIONSCOLLECTION = new Permissions();
15   static {
16     ALL_PERMISSIONSCOLLECTION.add(new AllPermission());
17     ALL_PERMISSIONSCOLLECTION.setReadOnly();
18   }
19   
20   public void refresh() {
21   }
22
23   public PermissionCollection getPermissions(CodeSource codesource) {
24     // no checks are done based on the origin of the code
25
// checks are only based on *who* is running the code.
26
return ALL_PERMISSIONSCOLLECTION;
27   }
28   
29   public PermissionCollection getPermissions(ProtectionDomain domain) {
30     PermissionCollection permissionCollection = new Permissions();
31     
32     Principal[] principals = domain.getPrincipals();
33     // if there are principals
34
if (principals!=null) {
35       // loop over the principals
36
for (int i=0; i<principals.length; i++) {
37         // if the principal is a org.jbpm.identity.Entity
38
if (Entity.class.isAssignableFrom(principals[i].getClass())) {
39           // add all the identity's permissions to the set of permissions.
40
Iterator iter = ((Entity)principals[i]).getPermissions().iterator();
41           while (iter.hasNext()) {
42             permissionCollection.add((Permission) iter.next());
43           }
44         }
45       }
46     }
47     
48     return super.getPermissions(domain);
49   }
50   
51   public boolean implies(ProtectionDomain domain, Permission permission) {
52     return getPermissions(domain).implies(permission);
53   }
54 }
55
Popular Tags