1 23 24 package javax.security.jacc; 25 26 27 import java.security.AccessController ; 28 import java.security.AccessControlException ; 29 import java.security.PrivilegedExceptionAction ; 30 import java.security.PrivilegedActionException ; 31 import java.security.SecurityPermission ; 32 33 import javax.security.jacc.PolicyConfiguration ; 34 35 import javax.security.jacc.PolicyContextException ; 36 37 56 57 public abstract class PolicyConfigurationFactory 58 { 59 private static String FACTORY_NAME = 60 "javax.security.jacc.PolicyConfigurationFactory.provider"; 61 62 private static PolicyConfigurationFactory pcFactory; 63 64 91 92 public static PolicyConfigurationFactory getPolicyConfigurationFactory() 93 throws java.lang.ClassNotFoundException , 94 javax.security.jacc.PolicyContextException 95 { 96 97 SecurityManager sm = System.getSecurityManager(); 98 if (sm != null) sm.checkPermission(new 99 java.security.SecurityPermission ("setPolicy")); 100 if(pcFactory != null) 101 return pcFactory; 102 103 String msg; 104 final String classname[] = { null }; 105 106 try { 107 108 Class clazz = null; 109 110 if (sm != null){ 111 try{ 112 clazz = (Class )AccessController.doPrivileged 113 (new PrivilegedExceptionAction (){ 114 public Object run() throws java.lang.Exception { 115 116 classname[0] = System.getProperty(FACTORY_NAME); 117 118 if(classname[0] == null){ 119 String msg = new String 120 ("JACC:Error PolicyConfigurationFactory : property not set : "+ FACTORY_NAME); 121 throw new ClassNotFoundException (msg); 122 } 123 124 return Class.forName(classname[0],true, 125 Thread.currentThread().getContextClassLoader()); 126 } 127 }); 128 } catch (PrivilegedActionException ex){ 129 Exception e = ex.getException() ; 130 if ( e instanceof java.lang.ClassNotFoundException ){ 131 throw (java.lang.ClassNotFoundException )e; 132 } else if ( e instanceof java.lang.InstantiationException ){ 133 throw (java.lang.InstantiationException )e; 134 } else if ( e instanceof java.lang.IllegalAccessException ){ 135 throw (java.lang.IllegalAccessException )e; 136 } 137 } 138 } else { 139 classname[0] = System.getProperty(FACTORY_NAME); 140 141 if (classname[0] == null){ 142 msg = new String 143 ("JACC:Error PolicyConfigurationFactory : property not set : "+ FACTORY_NAME); 144 throw new ClassNotFoundException (msg); 145 } 146 147 clazz = Class.forName(classname[0],true, 148 Thread.currentThread().getContextClassLoader()); 149 } 150 151 Object factory = clazz.newInstance(); 152 153 pcFactory = (PolicyConfigurationFactory ) factory; 154 155 } catch(java.lang.ClassNotFoundException cnfe){ 156 msg = new String 157 ("JACC:Error PolicyConfigurationFactory : cannot find class : " 158 + classname[0]); 159 throw new ClassNotFoundException (msg,cnfe); 160 } catch(java.lang.IllegalAccessException iae){ 161 msg = new String 162 ("JACC:Error PolicyConfigurationFactory : cannot access class : " 163 + classname[0]); 164 throw new PolicyContextException (msg,iae); 165 } catch(java.lang.InstantiationException ie){ 166 msg = new String 167 ("JACC:Error PolicyConfigurationFactory : cannot instantiate : " 168 + classname[0]); 169 throw new PolicyContextException (msg,ie); 170 } catch(java.lang.ClassCastException cce){ 171 msg = new String 172 ("JACC:Error PolicyConfigurationFactory : class not PolicyConfigurationFactory : "+ classname[0]); 173 throw new ClassCastException (msg); 174 } 175 176 return pcFactory; 177 178 } 179 180 231 232 public abstract PolicyConfiguration 233 getPolicyConfiguration(String contextID, boolean remove) 234 throws javax.security.jacc.PolicyContextException ; 235 236 256 257 public abstract boolean inService(String contextID) 258 throws javax.security.jacc.PolicyContextException ; 259 260 } 261 | Popular Tags |