1 26 27 package org.objectweb.jonas.security.jacc; 28 29 import javax.security.jacc.PolicyContextException ; 30 import javax.security.jacc.PolicyContextHandler ; 31 32 import org.objectweb.jonas.common.Log; 33 34 import org.objectweb.util.monolog.api.BasicLevel; 35 import org.objectweb.util.monolog.api.Logger; 36 37 43 public class JPolicyContextHandler implements PolicyContextHandler { 44 45 49 private static final String CONTAINER_SUBJECT = "javax.security.auth.Subject.container"; 50 51 55 private static final String SOAP_MESSAGE = "javax.xml.soap.SOAPMessage"; 56 57 61 private static final String HTTP_SERVLET_REQUEST = "javax.servlet.http.HttpServletRequest"; 62 63 67 private static final String ENTERPRISE_BEAN = "javax.ejb.EnterpriseBean"; 68 69 73 private static final String EJB_ARGUMENTS = "javax.ejb.arguments"; 74 75 78 private static final String [] SUPPORTED_KEYS = new String [] {CONTAINER_SUBJECT, SOAP_MESSAGE, HTTP_SERVLET_REQUEST, 79 ENTERPRISE_BEAN, EJB_ARGUMENTS}; 80 81 84 private static Logger logger = Log.getLogger(Log.JONAS_JACC_SECURITY_PREFIX); 85 86 89 public JPolicyContextHandler() { 90 super(); 91 92 } 93 94 100 public boolean supports(String key) throws PolicyContextException { 101 for (int k = 0; k < SUPPORTED_KEYS.length; k++) { 102 if (key.equals(SUPPORTED_KEYS[k])) { 103 return true; 104 } 105 } 106 return false; 107 } 108 109 113 public String [] getKeys() throws PolicyContextException { 114 return SUPPORTED_KEYS; 115 } 116 117 125 public Object getContext(String key, Object data) throws PolicyContextException { 126 127 if (logger.isLoggable(BasicLevel.DEBUG)) { 128 logger.log(BasicLevel.DEBUG, "Asking key" + key); 129 } 130 131 if (data == null || !(data instanceof JPolicyContextHandlerData)) { 133 logger.log(BasicLevel.WARN, "No data object or Data object not instance of JPolicyContextHandlerData"); 134 return null; 135 } 136 137 Object contextObject = null; 138 JPolicyContextHandlerData jPolicyContextHandlerData = (JPolicyContextHandlerData) data; 139 140 if (key.equals(HTTP_SERVLET_REQUEST)) { 141 if (logger.isLoggable(BasicLevel.DEBUG)) { 142 logger.log(BasicLevel.DEBUG, "Key == '" + HTTP_SERVLET_REQUEST + "'"); 143 } 144 contextObject = jPolicyContextHandlerData.getHttpServletRequest(); 145 } else if (key.equals(EJB_ARGUMENTS)) { 146 if (logger.isLoggable(BasicLevel.DEBUG)) { 147 logger.log(BasicLevel.DEBUG, "Key == '" + EJB_ARGUMENTS + "'"); 148 } 149 contextObject = jPolicyContextHandlerData.getEjbArguments(); 150 } else if (key.equals(CONTAINER_SUBJECT)) { 151 if (logger.isLoggable(BasicLevel.DEBUG)) { 152 logger.log(BasicLevel.DEBUG, "Key == '" + CONTAINER_SUBJECT + "'"); 153 } 154 contextObject = jPolicyContextHandlerData.getContainerSubject(); 155 156 } 157 158 if (logger.isLoggable(BasicLevel.DEBUG)) { 159 logger.log(BasicLevel.DEBUG, "Returning object '" + contextObject + "' for key '" + key + "'"); 160 } 161 return contextObject; 162 163 } 164 165 } | Popular Tags |