PolicyProvider.java

00001 
00027 package org.objectweb.jonas.security;
00028 
00029 import org.objectweb.jonas_lib.security.jacc.JPolicy;
00030 
00031 import org.objectweb.jonas.common.Log;
00032 
00033 import org.objectweb.util.monolog.api.BasicLevel;
00034 import org.objectweb.util.monolog.api.Logger;
00035 
00040 public class PolicyProvider {
00041 
00045     private PolicyProvider() {
00046 
00047     }
00048 
00052     private static Logger logger = null;
00053 
00059     public static void init() throws SecurityException {
00060 
00061         if (logger == null) {
00062             logger = Log.getLogger(Log.JONAS_SECURITY_PREFIX);
00063         }
00064 
00065         // Check if we have to use an existing policy provider
00066         // Section 2.7
00067 
00068         String javaPolicy = System.getProperty("javax.security.jacc.policy.provider");
00069 
00070         if (javaPolicy != null) {
00071             try {
00072                 java.security.Policy.setPolicy((java.security.Policy) Class.forName(javaPolicy).newInstance());
00073             } catch (ClassNotFoundException cnfe) {
00074                 // problem with property value of classpath
00075                 throw new SecurityException(cnfe.getMessage());
00076             } catch (IllegalAccessException iae) {
00077                 // problem with policy class definition
00078                 throw new SecurityException(iae.getMessage());
00079             } catch (InstantiationException ie) {
00080                 // problem with policy instantiation
00081                 throw new SecurityException(ie.getMessage());
00082             } catch (ClassCastException cce) {
00083                 // Not instance of java.security.policy
00084                 throw new SecurityException(cce.getMessage());
00085             }
00086             logger.log(BasicLevel.INFO, "Using policy provider '" + javaPolicy + "'");
00087         }
00088 
00089         // Defines the JOnAS JACC provider if no provider is already defined
00090         // Section 2.3
00091         String jaccFactoryProvider = System.getProperty("javax.security.jacc.PolicyConfigurationFactory.provider");
00092         if (jaccFactoryProvider == null) {
00093             logger.log(BasicLevel.INFO, "Using JOnAS PolicyConfigurationFactory provider and JOnAS Policy provider");
00094             System.setProperty("javax.security.jacc.PolicyConfigurationFactory.provider", "org.objectweb.jonas_lib.security.jacc.PolicyConfigurationFactoryWrapper");
00095             // Add the JOnAS delegating policy provider
00096             java.security.Policy.setPolicy(JPolicy.getInstance());
00097         } else {
00098             logger.log(BasicLevel.INFO, "Using factory '" + jaccFactoryProvider + "' as PolicyConfigurationFactory provider");
00099         }
00100 
00101         // TODO : Register Context Handler
00102 
00103 
00104     }
00105 
00106 }

Generated on Tue Feb 15 15:05:22 2005 for JOnAS by  doxygen 1.3.9.1