1 22 package org.jboss.web.tomcat.security; 23 24 import java.io.IOException ; 25 import java.security.CodeSource ; 26 import java.util.Map ; 27 28 import javax.security.jacc.PolicyContext ; 29 import javax.servlet.ServletException ; 30 import javax.servlet.http.HttpServletRequest ; 31 32 import org.apache.catalina.connector.Request; 33 import org.apache.catalina.connector.Response; 34 import org.apache.catalina.valves.ValveBase; 35 import org.jboss.logging.Logger; 36 import org.jboss.metadata.WebMetaData; 37 import org.jboss.security.SecurityRolesAssociation; 38 39 47 public class JaccContextValve extends ValveBase 48 { 49 private static Logger log = Logger.getLogger(JaccContextValve.class); 50 public static ThreadLocal activeCS = new ThreadLocal (); 51 52 53 private String contextID; 54 55 private CodeSource warCS; 56 private WebMetaData metaData; 57 private boolean trace; 58 59 public JaccContextValve(WebMetaData wmd, CodeSource cs) 60 { 61 this.metaData = wmd; 62 this.contextID = metaData.getJaccContextID(); 63 this.warCS = cs; 64 this.trace = log.isTraceEnabled(); 65 } 66 67 public void invoke(Request request, Response response) 68 throws IOException , ServletException 69 { 70 activeCS.set(warCS); 71 HttpServletRequest httpRequest = (HttpServletRequest ) request.getRequest(); 72 73 Map principalToRoleSetMap = metaData.getPrincipalVersusRolesMap(); 75 SecurityRolesAssociation.setSecurityRoles(principalToRoleSetMap); 76 if(trace) 77 log.trace("MetaData:"+metaData+":principalToRoleSetMap"+principalToRoleSetMap); 78 79 try 80 { 81 PolicyContext.setContextID(contextID); 83 HttpServletRequestPolicyContextHandler.setRequest(httpRequest); 85 getNext().invoke(request, response); 87 } 88 finally 89 { 90 SecurityAssociationActions.clear(); 91 activeCS.set(null); 92 SecurityRolesAssociation.setSecurityRoles(null); 93 } 94 } 95 } 96 | Popular Tags |