1 4 package com.sslexplorer.agent; 5 6 import javax.servlet.http.HttpSessionBindingEvent ; 7 import javax.servlet.http.HttpSessionBindingListener ; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 12 import com.sslexplorer.security.SessionInfo; 13 14 public class AgentUnregisterHook implements HttpSessionBindingListener { 15 16 final static String AGENT_UNREGISTER_HOOK = "agentUnregister"; 17 18 final static Log log = LogFactory.getLog(AgentUnregisterHook.class); 19 20 private SessionInfo session; 21 22 private AgentUnregisterHook(SessionInfo session) { 23 this.session = session; 24 if (session.getHttpSession().getAttribute(AGENT_UNREGISTER_HOOK) != null) { 25 throw new IllegalStateException ( 26 "May only be one agent unregister hook in any session."); 27 } 28 session.getHttpSession().setAttribute(AGENT_UNREGISTER_HOOK, this); 29 } 30 31 public void valueBound(HttpSessionBindingEvent event) { 32 if (log.isInfoEnabled()) 33 log.info("New session agent hook."); 34 } 35 36 public void valueUnbound(HttpSessionBindingEvent event) { 37 if (log.isInfoEnabled()) 38 log.info("Session invalidate. Deregistering agent"); 39 DefaultAgentManager.getInstance().unregisterAgent(session); 40 } 41 42 public static void register(SessionInfo session) { 43 if(session.getHttpSession() != null && session.getHttpSession().getAttribute(AGENT_UNREGISTER_HOOK) == null) { 44 new AgentUnregisterHook(session); 45 } 46 } 47 48 } | Popular Tags |