KickJava   Java API By Example, From Geeks To Geeks.

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


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: PolicyConfigurationFactoryWrapper.java,v 1.2 2004/04/09 09:58:27 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_lib.security.jacc;
28
29 import javax.security.jacc.PolicyConfiguration JavaDoc;
30 import javax.security.jacc.PolicyConfigurationFactory JavaDoc;
31 import javax.security.jacc.PolicyContextException JavaDoc;
32
33
34 /**
35  * Defines a wrapper for the PolicyConfigurationFactory
36  * Uses a wrapper because JACC provider factory is loaded by abstract Factory
37  * with the system classloader. The problem is that System classloader loads only
38  * few JOnAS classes. All classes are loaded by JOnAS classloader
39  * This wrapper could be removed if the class is no more loaded by System classloader
40  * @author Florent Benoit
41  */

42 public class PolicyConfigurationFactoryWrapper extends PolicyConfigurationFactory JavaDoc {
43
44     /**
45      * List of PolicyConfiguration objects
46      * Manage all configurations available
47      */

48     private PolicyConfigurationFactory JavaDoc policyConfigurationFactory = null;
49
50     /**
51      * Name of the implementation class
52      */

53     private static final String JavaDoc CLASS_NAME = "org.objectweb.jonas_lib.security.jacc.JPolicyConfigurationFactory";
54
55     /**
56      * Update policyConfigurationFactory object for delegating requests
57      */

58     public PolicyConfigurationFactoryWrapper() {
59         try {
60             ClassLoader JavaDoc classLoader = Thread.currentThread().getContextClassLoader();
61             Class JavaDoc clazz = classLoader.loadClass(CLASS_NAME);
62             Object JavaDoc o = clazz.newInstance();
63             policyConfigurationFactory = (PolicyConfigurationFactory JavaDoc) o;
64         } catch (Exception JavaDoc e) {
65             // no logger available (bootstrap jar)
66
System.err.println("PolicyConfigurationFactoryWrapper : Error with JACC :" + e.getMessage());
67         }
68     }
69
70
71     /**
72      * This method is used to obtain an instance of the provider specific
73      * class that implements the PolicyConfiguration interface that corresponds
74      * to the identified policy context within the provider.
75      * @param contextID A String identifying the policy context whose
76      * PolicyConfiguration interface is to be returned. The value passed
77      * to this parameter must not be null.
78      * @param remove A boolean value that establishes whether or not the policy
79      * statements of an existing policy context are to be removed before
80      * its PolicyConfiguration object is returned. If the value passed to
81      * this parameter is true, the policy statements of an existing
82      * policy context will be removed. If the value is false,
83      * they will not be removed.
84      * @return an Object that implements the PolicyConfiguration Interface
85      * matched to the Policy provider and corresponding to the
86      * identified policy context.
87      * @throws SecurityException when called by an AccessControlContext that
88      * has not been granted the "setPolicy" SecurityPermission.
89      * @throws PolicyContextException if the implementation throws a checked
90      * exception that has not been accounted for by the
91      * getPolicyConfiguration method signature. The exception thrown
92      * by the implementation class will be encapsulated
93      * (during construction) in the thrown PolicyContextException.
94      */

95     public PolicyConfiguration JavaDoc getPolicyConfiguration(String JavaDoc contextID, boolean remove) throws PolicyContextException JavaDoc, SecurityException JavaDoc {
96         return policyConfigurationFactory.getPolicyConfiguration(contextID, remove);
97     }
98
99     /**
100      * This method determines if the identified policy context exists
101      * with state "inService" in the Policy provider associated with
102      * the factory.
103      * @param contextID A string identifying a policy context
104      * @return true if the identified policy context exists within
105      * the provider and its state is "inService", false otherwise.
106      * @throws SecurityException when called by an AccessControlContext
107      * that has not been granted the "setPolicy" SecurityPermission.
108      * @throws PolicyContextException if the implementation throws a checked
109      * exception that has not been accounted for by the inService
110      * method signature. The exception thrown by the implementation
111      * class will be encapsulated (during construction) in the thrown
112      * PolicyContextException.
113      */

114     public boolean inService(String JavaDoc contextID) throws PolicyContextException JavaDoc, SecurityException JavaDoc {
115         return policyConfigurationFactory.inService(contextID);
116     }
117
118
119 }
120
Popular Tags