KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > security > jacc > JPolicyWrapper


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: JPolicyWrapper.java,v 1.1 2004/07/08 13:45:47 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_lib.security.jacc;
28
29 import java.security.CodeSource JavaDoc;
30 import java.security.Permission JavaDoc;
31 import java.security.PermissionCollection JavaDoc;
32 import java.security.Policy JavaDoc;
33 import java.security.ProtectionDomain JavaDoc;
34
35
36 /**
37  * Wrapper to the JPolicy class. This is used to instantiate
38  * the real Policy object by using Thread classloader.
39  * @author Florent Benoit
40  */

41 public class JPolicyWrapper extends Policy JavaDoc {
42
43     /**
44      * Internal policy object
45      */

46     private Policy JavaDoc wrappedPolicy = null;
47
48     /**
49      * Name of the implementation class
50      */

51     private static final String JavaDoc CLASS_NAME = "org.objectweb.jonas_lib.security.jacc.JPolicy";
52
53
54     /**
55      * Default constructor
56      */

57     public JPolicyWrapper() {
58         super();
59         try {
60             ClassLoader JavaDoc classLoader = Thread.currentThread().getContextClassLoader();
61             Class JavaDoc clazz = classLoader.loadClass(CLASS_NAME);
62             wrappedPolicy = (Policy JavaDoc) clazz.newInstance();
63         } catch (Exception JavaDoc e) {
64             // no logger available (class packaged in bootstrap jar)
65
throw new RuntimeException JavaDoc("JPolicyWrapper : Error with JACC/Policy object :" + e.getMessage());
66         }
67     }
68
69
70     /**
71      * Refreshes/reloads the policy configuration.
72      */

73     public void refresh() {
74         wrappedPolicy.refresh();
75     }
76
77     /**
78      * Evaluates the global policy and returns a PermissionCollection object
79      * specifying the set of permissions allowed given the characteristics
80      * of the protection domain.
81      * @param codesource the given codesource on which retrieve permissions
82      * @return permissions
83      */

84     public PermissionCollection JavaDoc getPermissions(CodeSource JavaDoc codesource) {
85         return wrappedPolicy.getPermissions(codesource);
86     }
87
88     /**
89      * Evaluates the global policy and returns a PermissionCollection object
90      * specifying the set of permissions allowed given the characteristics
91      * of the protection domain.
92      * @param domain the given domain on which retrieve permissions
93      * @return permissions
94      */

95     public PermissionCollection JavaDoc getPermissions(ProtectionDomain JavaDoc domain) {
96         return wrappedPolicy.getPermissions(domain);
97     }
98
99     /**
100      * Evaluates the global policy for the permissions granted
101      * to the ProtectionDomain and tests whether the permission is granted.
102      * @param domain the ProtectionDomain to test.
103      * @param permission the Permission object to be tested for implication.
104      * @return true if "permission" is a proper subset of a permission
105      * granted to this ProtectionDomain.
106      */

107     public boolean implies(ProtectionDomain JavaDoc domain, Permission JavaDoc permission) {
108         return wrappedPolicy.implies(domain, permission);
109     }
110
111 }
112
Popular Tags