1 8 package org.jboss.security.jacc; 9 10 import java.net.URL ; 11 import java.security.Policy ; 12 import javax.security.jacc.PolicyConfigurationFactory ; 13 import javax.security.jacc.PolicyConfiguration ; 14 import javax.security.jacc.PolicyContextException ; 15 16 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 17 import org.jboss.util.state.StateMachine; 18 import org.jboss.util.state.xml.StateMachineParser; 19 20 25 public class JBossPolicyConfigurationFactory 26 extends PolicyConfigurationFactory 27 { 28 private StateMachine configStateMachine; 29 private ConcurrentReaderHashMap policyConfigMap = new ConcurrentReaderHashMap(); 30 private DelegatingPolicy policy; 31 32 36 public JBossPolicyConfigurationFactory() 37 { 38 try 39 { 40 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 42 URL states = loader.getResource("org/jboss/security/jacc/jacc-policy-config-states.xml"); 43 StateMachineParser smp = new StateMachineParser(); 44 configStateMachine = smp.parse(states); 45 } 46 catch(Exception e) 47 { 48 IllegalStateException ex = new IllegalStateException ("Failed to parse jacc-policy-config-states.xml"); 49 ex.initCause(e); 50 throw ex; 51 } 52 Policy p = Policy.getPolicy(); 54 if( (p instanceof DelegatingPolicy) == false ) 55 { 56 p = DelegatingPolicy.getInstance(); 58 } 59 policy = (DelegatingPolicy) p; 60 } 61 62 public PolicyConfiguration getPolicyConfiguration(String contextID, boolean remove) 63 throws PolicyContextException 64 { 65 JBossPolicyConfiguration pc = (JBossPolicyConfiguration) policyConfigMap.get(contextID); 66 if( pc == null ) 67 { 68 StateMachine sm = (StateMachine) configStateMachine.clone(); 69 pc = new JBossPolicyConfiguration(contextID, policy, sm); 70 policyConfigMap.put(contextID, pc); 71 } 72 pc.initPolicyConfiguration(remove); 73 return pc; 74 } 75 76 public boolean inService(String contextID) 77 throws PolicyContextException 78 { 79 boolean inService = false; 80 JBossPolicyConfiguration pc = (JBossPolicyConfiguration) policyConfigMap.get(contextID); 81 if( pc != null ) 82 inService = pc.inService(); 83 return inService; 84 } 85 } 86 | Popular Tags |