01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jbpm.identity.security;
23:
24: import java.security.*;
25: import java.util.*;
26: import org.jbpm.identity.Entity;
27:
28: /**
29: * a java.security.Policy implementation that in combination with the
30: * IdentityLoginModule enforces the secirity permissions modelled as
31: * in the package org.jbpm.identity.
32: */
33: public class IdentityPolicy extends Policy {
34:
35: public static final PermissionCollection ALL_PERMISSIONSCOLLECTION = new Permissions();
36: static {
37: ALL_PERMISSIONSCOLLECTION.add(new AllPermission());
38: ALL_PERMISSIONSCOLLECTION.setReadOnly();
39: }
40:
41: public void refresh() {
42: }
43:
44: public PermissionCollection getPermissions(CodeSource codesource) {
45: // no checks are done based on the origin of the code
46: // checks are only based on *who* is running the code.
47: return ALL_PERMISSIONSCOLLECTION;
48: }
49:
50: public PermissionCollection getPermissions(ProtectionDomain domain) {
51: PermissionCollection permissionCollection = new Permissions();
52:
53: Principal[] principals = domain.getPrincipals();
54: // if there are principals
55: if (principals != null) {
56: // loop over the principals
57: for (int i = 0; i < principals.length; i++) {
58: // if the principal is a org.jbpm.identity.Entity
59: if (Entity.class.isAssignableFrom(principals[i]
60: .getClass())) {
61: // add all the identity's permissions to the set of permissions.
62: Iterator iter = ((Entity) principals[i])
63: .getPermissions().iterator();
64: while (iter.hasNext()) {
65: permissionCollection.add((Permission) iter
66: .next());
67: }
68: }
69: }
70: }
71:
72: return super .getPermissions(domain);
73: }
74:
75: public boolean implies(ProtectionDomain domain,
76: Permission permission) {
77: return getPermissions(domain).implies(permission);
78: }
79: }
|