1 22 package org.jboss.web.tomcat.security; 23 24 import org.apache.catalina.InstanceEvent; 25 import org.apache.catalina.InstanceListener; 26 import org.apache.catalina.Wrapper; 27 import org.jboss.logging.Logger; 28 import org.jboss.metadata.WebMetaData; 29 import org.jboss.security.RunAsIdentity; 30 31 38 public class RunAsListener implements InstanceListener 39 { 40 43 public static ThreadLocal metaDataLocal = new ThreadLocal (); 44 45 private static Logger log = Logger.getLogger(RunAsListener.class); 46 private WebMetaData metaData; 47 48 public RunAsListener() 49 { 50 this.metaData = (WebMetaData) metaDataLocal.get(); 51 } 52 53 59 public void instanceEvent(InstanceEvent event) 60 { 61 Wrapper servlet = event.getWrapper(); 62 String type = event.getType(); 63 if (servlet != null && metaData != null) 64 { 65 boolean trace = log.isTraceEnabled(); 66 String name = servlet.getName(); 67 RunAsIdentity identity = metaData.getRunAsIdentity(name); 68 if (trace) 69 log.trace(name + ", runAs: " + identity); 70 if( type.equals(InstanceEvent.BEFORE_INIT_EVENT) 72 || type.equals(InstanceEvent.BEFORE_DESTROY_EVENT) ) 73 { 74 SecurityAssociationActions.pushRunAsIdentity(identity); 75 } 76 else if( type.equals(InstanceEvent.AFTER_INIT_EVENT) 78 || type.equals(InstanceEvent.AFTER_DESTROY_EVENT) ) 79 { 80 SecurityAssociationActions.popRunAsIdentity(); 81 } 82 } 83 } 84 } 85 | Popular Tags |