KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > jacc > JBossPolicyConfigurationFactory


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  *
7  */

8 package org.jboss.security.jacc;
9
10 import java.net.URL JavaDoc;
11 import java.security.Policy JavaDoc;
12 import javax.security.jacc.PolicyConfigurationFactory JavaDoc;
13 import javax.security.jacc.PolicyConfiguration JavaDoc;
14 import javax.security.jacc.PolicyContextException JavaDoc;
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 /** org.jboss.security.provider
21  *
22  * @author Scott.Stark@jboss.org
23  * @version $Revision: 1.2 $
24  */

25 public class JBossPolicyConfigurationFactory
26    extends PolicyConfigurationFactory JavaDoc
27 {
28    private StateMachine configStateMachine;
29    private ConcurrentReaderHashMap policyConfigMap = new ConcurrentReaderHashMap();
30    private DelegatingPolicy policy;
31
32    /** Build the JACC policy configuration state machine from the
33     * jacc-policy-config-states.xml file.
34     *
35     */

36    public JBossPolicyConfigurationFactory()
37    {
38       try
39       {
40          // Setup the state machine config
41
ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
42          URL JavaDoc 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 JavaDoc e)
47       {
48          IllegalStateException JavaDoc ex = new IllegalStateException JavaDoc("Failed to parse jacc-policy-config-states.xml");
49          ex.initCause(e);
50          throw ex;
51       }
52       // Get the DelegatingPolicy
53
Policy JavaDoc p = Policy.getPolicy();
54       if( (p instanceof DelegatingPolicy) == false )
55       {
56          // Assume that the installed policy delegates to the DelegatingPolicy
57
p = DelegatingPolicy.getInstance();
58       }
59       policy = (DelegatingPolicy) p;
60    }
61
62    public PolicyConfiguration JavaDoc getPolicyConfiguration(String JavaDoc contextID, boolean remove)
63       throws PolicyContextException JavaDoc
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 JavaDoc contextID)
77       throws PolicyContextException JavaDoc
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