KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > jacc > GeronimoPolicyConfigurationFactory


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.security.jacc;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22 import javax.security.jacc.PolicyConfiguration JavaDoc;
23 import javax.security.jacc.PolicyConfigurationFactory JavaDoc;
24 import javax.security.jacc.PolicyContextException JavaDoc;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.geronimo.security.GeronimoSecurityPermission;
29
30
31 /**
32  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
33  */

34 public class GeronimoPolicyConfigurationFactory extends PolicyConfigurationFactory JavaDoc {
35
36     private final Log log = LogFactory.getLog(GeronimoPolicyConfigurationFactory.class);
37     private static GeronimoPolicyConfigurationFactory singleton;
38     private Map JavaDoc configurations = new HashMap JavaDoc();
39
40     public GeronimoPolicyConfigurationFactory() {
41         synchronized (GeronimoPolicyConfigurationFactory.class) {
42             if (singleton != null) {
43                 log.error("Singleton already assigned. There may be more than one GeronimoPolicyConfigurationFactory being used.");
44                 throw new IllegalStateException JavaDoc("Singleton already assigned");
45             }
46             singleton = this;
47         }
48     }
49
50     public void setPolicyConfiguration(String JavaDoc contextID, GeronimoPolicyConfiguration configuration) {
51         SecurityManager JavaDoc sm = System.getSecurityManager();
52         if (sm != null) sm.checkPermission(new GeronimoSecurityPermission("setPolicyConfiguration"));
53
54         configurations.put(contextID, configuration);
55
56         log.trace("Set policy configuration " + contextID);
57     }
58
59     public GeronimoPolicyConfiguration getGeronimoPolicyConfiguration(String JavaDoc contextID) throws PolicyContextException JavaDoc {
60         GeronimoPolicyConfiguration configuration = (GeronimoPolicyConfiguration) configurations.get(contextID);
61
62         if (configuration == null) {
63             throw new PolicyContextException JavaDoc("No policy configuration registered for contextID: " + contextID);
64         }
65
66         log.trace("Get policy configuration " + contextID);
67         return configuration;
68     }
69
70     public PolicyConfiguration JavaDoc getPolicyConfiguration(String JavaDoc contextID, boolean remove) throws PolicyContextException JavaDoc {
71         GeronimoPolicyConfiguration configuration = (GeronimoPolicyConfiguration) configurations.get(contextID);
72
73         if (configuration == null) {
74             configuration = new PolicyConfigurationGeneric(contextID);
75             configurations.put(contextID, configuration);
76         } else {
77             configuration.open(remove);
78         }
79
80         log.trace("Get " + (remove ? "CLEANED" : "") + " policy configuration " + contextID);
81         return configuration;
82     }
83
84     public boolean inService(String JavaDoc contextID) throws PolicyContextException JavaDoc {
85         PolicyConfiguration JavaDoc configuration = getPolicyConfiguration(contextID, false);
86
87         log.trace("Policy configuration " + contextID + " put into service");
88         return configuration.inService();
89     }
90
91     static GeronimoPolicyConfigurationFactory getSingleton() {
92         return singleton;
93     }
94 }
95
Popular Tags