001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer: Florent BENOIT
022: * --------------------------------------------------------------------------
023: * $Id: JPolicyWrapper.java 5100 2004-07-08 13:45:47Z benoitf $
024: * --------------------------------------------------------------------------
025: */package org.objectweb.jonas_lib.security.jacc;
026:
027: import java.security.CodeSource;
028: import java.security.Permission;
029: import java.security.PermissionCollection;
030: import java.security.Policy;
031: import java.security.ProtectionDomain;
032:
033: /**
034: * Wrapper to the JPolicy class. This is used to instantiate
035: * the real Policy object by using Thread classloader.
036: * @author Florent Benoit
037: */
038: public class JPolicyWrapper extends Policy {
039:
040: /**
041: * Internal policy object
042: */
043: private Policy wrappedPolicy = null;
044:
045: /**
046: * Name of the implementation class
047: */
048: private static final String CLASS_NAME = "org.objectweb.jonas_lib.security.jacc.JPolicy";
049:
050: /**
051: * Default constructor
052: */
053: public JPolicyWrapper() {
054: super ();
055: try {
056: ClassLoader classLoader = Thread.currentThread()
057: .getContextClassLoader();
058: Class clazz = classLoader.loadClass(CLASS_NAME);
059: wrappedPolicy = (Policy) clazz.newInstance();
060: } catch (Exception e) {
061: // no logger available (class packaged in bootstrap jar)
062: throw new RuntimeException(
063: "JPolicyWrapper : Error with JACC/Policy object :"
064: + e.getMessage());
065: }
066: }
067:
068: /**
069: * Refreshes/reloads the policy configuration.
070: */
071: public void refresh() {
072: wrappedPolicy.refresh();
073: }
074:
075: /**
076: * Evaluates the global policy and returns a PermissionCollection object
077: * specifying the set of permissions allowed given the characteristics
078: * of the protection domain.
079: * @param codesource the given codesource on which retrieve permissions
080: * @return permissions
081: */
082: public PermissionCollection getPermissions(CodeSource codesource) {
083: return wrappedPolicy.getPermissions(codesource);
084: }
085:
086: /**
087: * Evaluates the global policy and returns a PermissionCollection object
088: * specifying the set of permissions allowed given the characteristics
089: * of the protection domain.
090: * @param domain the given domain on which retrieve permissions
091: * @return permissions
092: */
093: public PermissionCollection getPermissions(ProtectionDomain domain) {
094: return wrappedPolicy.getPermissions(domain);
095: }
096:
097: /**
098: * Evaluates the global policy for the permissions granted
099: * to the ProtectionDomain and tests whether the permission is granted.
100: * @param domain the ProtectionDomain to test.
101: * @param permission the Permission object to be tested for implication.
102: * @return true if "permission" is a proper subset of a permission
103: * granted to this ProtectionDomain.
104: */
105: public boolean implies(ProtectionDomain domain,
106: Permission permission) {
107: return wrappedPolicy.implies(domain, permission);
108: }
109:
110: }
|