1 26 27 package org.objectweb.jonas.security; 28 29 import org.objectweb.jonas_lib.security.jacc.JPolicy; 30 31 import org.objectweb.jonas.common.Log; 32 33 import org.objectweb.util.monolog.api.BasicLevel; 34 import org.objectweb.util.monolog.api.Logger; 35 36 40 public class PolicyProvider { 41 42 45 private PolicyProvider() { 46 47 } 48 49 52 private static Logger logger = null; 53 54 59 public static void init() throws SecurityException { 60 61 if (logger == null) { 62 logger = Log.getLogger(Log.JONAS_SECURITY_PREFIX); 63 } 64 65 68 String javaPolicy = System.getProperty("javax.security.jacc.policy.provider"); 69 70 if (javaPolicy != null) { 71 try { 72 java.security.Policy.setPolicy((java.security.Policy ) Class.forName(javaPolicy).newInstance()); 73 } catch (ClassNotFoundException cnfe) { 74 throw new SecurityException (cnfe.getMessage()); 76 } catch (IllegalAccessException iae) { 77 throw new SecurityException (iae.getMessage()); 79 } catch (InstantiationException ie) { 80 throw new SecurityException (ie.getMessage()); 82 } catch (ClassCastException cce) { 83 throw new SecurityException (cce.getMessage()); 85 } 86 logger.log(BasicLevel.INFO, "Using policy provider '" + javaPolicy + "'"); 87 } 88 89 String jaccFactoryProvider = System.getProperty("javax.security.jacc.PolicyConfigurationFactory.provider"); 92 if (jaccFactoryProvider == null) { 93 logger.log(BasicLevel.INFO, "Using JOnAS PolicyConfigurationFactory provider and JOnAS Policy provider"); 94 System.setProperty("javax.security.jacc.PolicyConfigurationFactory.provider", "org.objectweb.jonas_lib.security.jacc.PolicyConfigurationFactoryWrapper"); 95 java.security.Policy.setPolicy(JPolicy.getInstance()); 97 } else { 98 logger.log(BasicLevel.INFO, "Using factory '" + jaccFactoryProvider + "' as PolicyConfigurationFactory provider"); 99 } 100 101 103 104 } 105 106 } 107 | Popular Tags |