1 23 24 package com.sun.enterprise.security.authorize; 25 26 import java.security.SecurityPermission ; 27 import java.util.Iterator ; 28 import java.util.Set ; 29 import java.util.Map ; 30 import java.util.HashMap ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.security.jacc.PolicyContextHandler ; 33 34 41 public class PolicyContextHandlerImpl implements PolicyContextHandler { 42 43 public static final String HTTP_SERVLET_REQUEST = 44 "javax.servlet.http.HttpServletRequest"; 45 public static final String SOAP_MESSAGE = "javax.xml.soap.SOAPMessage"; 46 public static final String ENTERPRISE_BEAN = "javax.ejb.EnterpriseBean"; 47 public static final String EJB_ARGUMENTS = "javax.ejb.arguments"; 48 public static final String SUBJECT = "javax.security.auth.Subject.container"; 49 public static final String REUSE = "java.security.Policy.supportsReuse"; 50 51 private static PolicyContextHandlerImpl pchimpl = null; 52 53 private ThreadLocal thisHandlerData = new ThreadLocal (); 54 55 private PolicyContextHandlerImpl() { 56 } 57 58 public static PolicyContextHandler getInstance() { 59 SecurityManager sm = System.getSecurityManager(); 60 if (sm != null) { 61 sm.checkPermission(new SecurityPermission ("setPolicy")); 62 } 63 64 if (pchimpl == null) { 65 pchimpl = new PolicyContextHandlerImpl(); 66 } 67 return pchimpl; 68 } 69 70 public boolean supports(String key) { 71 String [] s = getKeys(); 72 for (int i = 0; i<s.length; i++) { 73 if (s[i].equalsIgnoreCase(key)) { 74 return true; 75 } 76 } 77 return false; 78 } 79 80 public String [] getKeys(){ 81 String [] s = { 82 HTTP_SERVLET_REQUEST, 83 SOAP_MESSAGE, 84 ENTERPRISE_BEAN, 85 SUBJECT, 86 EJB_ARGUMENTS, 87 REUSE 88 }; 89 return s; 90 } 91 92 public Object getContext(String key, Object data) { 93 return getHandlerData().get(key); 95 } 96 97 public HandlerData getHandlerData() { 98 HandlerData handlerData = (HandlerData)thisHandlerData.get(); 99 if (handlerData == null) { 100 handlerData = HandlerData.getInstance(); 101 thisHandlerData.set(handlerData); 102 } 103 return handlerData; 104 } 105 } 106 | Popular Tags |