1 25 26 package org.objectweb.easybeans.security.jacc; 27 28 import org.objectweb.easybeans.log.JLog; 29 import org.objectweb.easybeans.log.JLogFactory; 30 import org.objectweb.easybeans.security.jacc.provider.JPolicy; 31 import org.objectweb.easybeans.security.jacc.provider.JPolicyConfigurationFactory; 32 33 34 38 public final class PolicyProvider { 39 40 43 private static final String JACC_POLICY_PROVIDER = "javax.security.jacc.policy.provider"; 44 45 48 private static final String JACC_POLICY_CONFIG_FACTORY_PROVIDER = "javax.security.jacc.PolicyConfigurationFactory.provider"; 49 50 51 54 private PolicyProvider() { 55 56 } 57 58 61 private static JLog logger = JLogFactory.getLog(PolicyProvider.class); 62 63 68 public static void init() throws SecurityException { 69 70 String javaPolicy = System.getProperty(JACC_POLICY_PROVIDER); 73 74 if (javaPolicy != null) { 75 try { 76 java.security.Policy.setPolicy((java.security.Policy ) Class.forName(javaPolicy).newInstance()); 77 } catch (ClassNotFoundException cnfe) { 78 throw new SecurityException (cnfe.getMessage()); 80 } catch (IllegalAccessException iae) { 81 throw new SecurityException (iae.getMessage()); 83 } catch (InstantiationException ie) { 84 throw new SecurityException (ie.getMessage()); 86 } catch (ClassCastException cce) { 87 throw new SecurityException (cce.getMessage()); 89 } 90 logger.info("Using policy provider ''{0}''", javaPolicy); 91 } else { 92 logger.info("Using EasyBeans policy provider ''{0}''.", JPolicy.class.getName()); 94 java.security.Policy.setPolicy(JPolicy.getInstance()); 95 } 96 97 String jaccFactoryProvider = System.getProperty("JACC_POLICY_CONFIG_FACTORY_PROVIDER"); 100 if (jaccFactoryProvider == null) { 101 logger.info("Using EasyBeans PolicyConfigurationFactory provider and EasyBeans Policy provider"); 103 System.setProperty(JACC_POLICY_CONFIG_FACTORY_PROVIDER, JPolicyConfigurationFactory.class.getName()); 104 } else { 105 logger.info("Using factory ''{0}'' as PolicyConfigurationFactory provider.", jaccFactoryProvider); 106 } 107 108 } 109 110 } 111 | Popular Tags |