01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.security;
23:
24: import org.jboss.portal.security.spi.provider.PermissionRepository;
25:
26: import javax.security.auth.Subject;
27: import java.security.Permission;
28: import java.security.PermissionCollection;
29:
30: /**
31: * Base permission that can act either as a container or as a permission that has an URI.
32: *
33: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
34: * @version $Revision: 8784 $
35: */
36: public abstract class PortalPermission extends Permission {
37:
38: /** . */
39: protected final String uri;
40:
41: /** . */
42: protected final PortalPermissionCollection collection;
43:
44: public PortalPermission(String name,
45: PortalPermissionCollection collection) {
46: super (name);
47: if (collection == null) {
48: throw new IllegalArgumentException("Need a repositoty");
49: }
50: collection.owner = this ;
51:
52: //
53: this .uri = null;
54: this .collection = collection;
55: }
56:
57: public PortalPermission(String name, String uri) {
58: super (name);
59: if (uri == null) {
60: throw new IllegalArgumentException("Need an uri");
61: }
62: this .uri = uri;
63: this .collection = null;
64: }
65:
66: /** Return the uri for the permission or null if the permission acts as a container. */
67: public String getURI() {
68: return uri;
69: }
70:
71: /** Return an instance of PortalPermissionCollection or null if the permission does not act as a container. */
72: public PermissionCollection newPermissionCollection() {
73: return collection;
74: }
75:
76: /** Return true if the permission is a container. */
77: public boolean isContainer() {
78: return collection != null;
79: }
80:
81: /**
82: * Return the portal permission type.
83: *
84: * @return the portal permission type
85: */
86: public abstract String getType();
87:
88: /**
89: * Implement the imply logic when we check the permission against a domain.
90: *
91: * @param repository
92: * @param caller
93: * @param permission
94: * @return true if the permission is implied
95: */
96: public abstract boolean implies(PermissionRepository repository,
97: Subject caller, String roleName, PortalPermission permission)
98: throws PortalSecurityException;
99: }
|