1 26 27 package org.objectweb.jonas_lib.security.jacc; 28 29 30 import java.security.SecurityPermission ; 31 import java.util.HashMap ; 32 import java.util.Map ; 33 34 import javax.security.jacc.PolicyConfiguration ; 35 import javax.security.jacc.PolicyConfigurationFactory ; 36 import javax.security.jacc.PolicyContextException ; 37 38 import org.objectweb.util.monolog.api.BasicLevel; 39 import org.objectweb.util.monolog.api.Logger; 40 41 import org.objectweb.jonas_lib.I18n; 42 43 import org.objectweb.common.TraceCore; 44 45 49 public class JPolicyConfigurationFactory extends PolicyConfigurationFactory { 50 51 54 public static final String FACTORY_NAME = "org.objectweb.jonas_lib.security.jacc.JPolicyConfigurationFactory"; 55 56 59 private static I18n i18n = I18n.getInstance(JPolicyConfigurationFactory.class); 60 61 65 private Map policyConfigurations = null; 66 67 70 private static Logger logger = null; 71 72 75 public JPolicyConfigurationFactory() { 76 policyConfigurations = new HashMap (); 77 logger = TraceCore.sec; 78 79 } 80 81 105 public PolicyConfiguration getPolicyConfiguration(String contextID, boolean remove) throws PolicyContextException , SecurityException { 106 107 checkSetPolicy(); 109 110 111 PolicyConfiguration policyConfiguration = getInternalPolicyConfiguration(contextID); 113 114 if (policyConfiguration != null) { 116 if (remove) { 118 policyConfiguration.delete(); 120 ((JPolicyConfiguration) policyConfiguration).resetState(); 121 } 122 return policyConfiguration; 124 } else { policyConfiguration = new JPolicyConfiguration(contextID); 127 } 128 129 policyConfigurations.put(contextID, policyConfiguration); 131 132 return policyConfiguration; 133 134 } 135 136 137 147 private synchronized PolicyConfiguration getInternalPolicyConfiguration(String contextID) { 148 return (PolicyConfiguration ) policyConfigurations.get(contextID); 150 } 151 152 153 168 public boolean inService(String contextID) throws PolicyContextException , SecurityException { 169 170 if (logger.isLoggable(BasicLevel.DEBUG)) { 171 logger.log(BasicLevel.DEBUG, "Check setpolicy..."); 172 } 173 174 checkSetPolicy(); 176 177 if (logger.isLoggable(BasicLevel.DEBUG)) { 178 logger.log(BasicLevel.DEBUG, "Context exist ?"); 179 } 180 181 if (policyConfigurations.containsKey(contextID)) { 183 if (logger.isLoggable(BasicLevel.DEBUG)) { 184 logger.log(BasicLevel.DEBUG, "Look internal config..."); 185 } 186 return getInternalPolicyConfiguration(contextID).inService(); 187 } else { 188 if (logger.isLoggable(BasicLevel.DEBUG)) { 190 logger.log(BasicLevel.DEBUG, "Policy configuration not found, return false"); 191 } 192 return false; 193 } 194 } 195 196 204 private void checkSetPolicy() throws SecurityException { 205 SecurityManager securityManager = System.getSecurityManager(); 206 if (securityManager != null) { 207 securityManager.checkPermission(new SecurityPermission ("setPolicy")); 208 } 209 } 210 211 212 } 213 | Popular Tags |