1 17 18 package org.apache.geronimo.security.jacc; 19 20 import java.util.HashMap ; 21 import java.util.Map ; 22 import javax.security.jacc.PolicyConfiguration ; 23 import javax.security.jacc.PolicyConfigurationFactory ; 24 import javax.security.jacc.PolicyContextException ; 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 34 public class GeronimoPolicyConfigurationFactory extends PolicyConfigurationFactory { 35 36 private final Log log = LogFactory.getLog(GeronimoPolicyConfigurationFactory.class); 37 private static GeronimoPolicyConfigurationFactory singleton; 38 private Map configurations = new HashMap (); 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 ("Singleton already assigned"); 45 } 46 singleton = this; 47 } 48 } 49 50 public void setPolicyConfiguration(String contextID, GeronimoPolicyConfiguration configuration) { 51 SecurityManager 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 contextID) throws PolicyContextException { 60 GeronimoPolicyConfiguration configuration = (GeronimoPolicyConfiguration) configurations.get(contextID); 61 62 if (configuration == null) { 63 throw new PolicyContextException ("No policy configuration registered for contextID: " + contextID); 64 } 65 66 log.trace("Get policy configuration " + contextID); 67 return configuration; 68 } 69 70 public PolicyConfiguration getPolicyConfiguration(String contextID, boolean remove) throws PolicyContextException { 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 contextID) throws PolicyContextException { 85 PolicyConfiguration 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 |