1 25 26 package org.objectweb.easybeans.security.jacc.provider; 27 28 import java.security.SecurityPermission ; 29 import java.util.HashMap ; 30 import java.util.Map ; 31 32 import javax.security.jacc.PolicyConfiguration ; 33 import javax.security.jacc.PolicyConfigurationFactory ; 34 import javax.security.jacc.PolicyContextException ; 35 36 import org.objectweb.easybeans.log.JLog; 37 import org.objectweb.easybeans.log.JLogFactory; 38 39 43 public class JPolicyConfigurationFactory extends PolicyConfigurationFactory { 44 45 48 private Map <String , PolicyConfiguration > policyConfigurations = null; 49 50 53 private static JLog logger = JLogFactory.getLog(JPolicyConfigurationFactory.class); 54 55 58 public JPolicyConfigurationFactory() { 59 policyConfigurations = new HashMap <String , PolicyConfiguration >(); 60 61 } 62 63 87 @Override 88 public PolicyConfiguration getPolicyConfiguration(final String contextID, final boolean remove) 89 throws PolicyContextException , SecurityException { 90 91 checkSetPolicy(); 93 94 PolicyConfiguration policyConfiguration = getInternalPolicyConfiguration(contextID); 96 97 if (policyConfiguration != null) { 99 if (remove) { 101 policyConfiguration.delete(); 103 ((JPolicyConfiguration) policyConfiguration).resetState(); 104 } 105 return policyConfiguration; 107 } 108 109 policyConfiguration = new JPolicyConfiguration(contextID); 112 113 policyConfigurations.put(contextID, policyConfiguration); 115 116 return policyConfiguration; 117 118 } 119 120 130 private synchronized PolicyConfiguration getInternalPolicyConfiguration(final String contextID) { 131 return policyConfigurations.get(contextID); 133 } 134 135 149 @Override 150 public boolean inService(final String contextID) throws PolicyContextException , SecurityException { 151 152 logger.debug("Check setpolicy..."); 154 checkSetPolicy(); 155 156 if (policyConfigurations.containsKey(contextID)) { 158 logger.debug("Existing config for contextID ''{0}'', gets internal config...", contextID); 159 return getInternalPolicyConfiguration(contextID).inService(); 160 } 161 logger.debug("Config for contextID ''{0}'' not found, return false", contextID); 163 return false; 164 } 165 166 174 private void checkSetPolicy() throws SecurityException { 175 SecurityManager securityManager = System.getSecurityManager(); 176 if (securityManager != null) { 177 securityManager.checkPermission(new SecurityPermission ("setPolicy")); 178 } 179 } 180 181 } 182 | Popular Tags |