/* ==================================================================
* Created [2009-4-27 下午11:32:55] by Jon.King
* ==================================================================
* TSS
* ==================================================================
* mailTo:jinpujun@hotmail.com
* Copyright (c) Jon.King, 2009-2012
* ==================================================================
*/
package com.jinhe.tss.core.web.listener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.log4j.Logger;
import com.jinhe.tss.core.Config;
import com.jinhe.tss.core.sso.context.Context;
import com.jinhe.tss.core.sso.online.OnlineUserManagerFactory;
/**
* <p> SessionDestroyedListener.java </p>
*
* Session超时监听程序:相关Session超时时,注销在线用户库中对应记录信息
*
*/
public class SessionDestroyedListener implements HttpSessionListener {
private Logger log = Logger.getLogger(this.getClass());
public void sessionCreated(HttpSessionEvent event) {
HttpSession session = event.getSession();
// 设置 session 的过期时间
if(session.isNew()){
String configValue = Config.getAttribute(Config.SESSION_CYCLELIFE_CONFIG);
if (configValue != null && !configValue.trim().equals("")) {
session.setMaxInactiveInterval(Integer.parseInt(configValue)); // 以秒为单位
}
}
String sessionId = session.getId();
String appCode = Context.getApplicationContext().getCurrentAppCode();
log.debug("应用【" + appCode + "】里 sessionId为:" + sessionId
+ " 的session创建完成,有效期为:" + session.getMaxInactiveInterval() + " 秒 ");
}
public void sessionDestroyed(HttpSessionEvent event) {
String sessionId = event.getSession().getId();
String appCode = Context.getApplicationContext().getCurrentAppCode();
log.debug("应用【" + appCode + "】里 sessionId为:" + sessionId + " 的session已经过期," +
"有效期为:" + event.getSession().getMaxInactiveInterval() + " 秒 ");
String token = OnlineUserManagerFactory.getManager().logout(appCode, sessionId);
Context.destroyIdentityCard(token); //去除登陆用户身份证card信息
}
}