use of org.apache.shiro.session.SessionListener in project tesla by linking12.
the class AuthzConfig method sessionManager.
@Bean
public SessionManager sessionManager() {
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
Collection<SessionListener> listeners = new ArrayList<SessionListener>();
listeners.add(new TeslaSessionListener());
sessionManager.setSessionListeners(listeners);
sessionManager.setSessionDAO(sessionDAO());
return sessionManager;
}
use of org.apache.shiro.session.SessionListener in project wechat by dllwh.
the class ShiroConfig method sessionManager.
/**
* @方法描述 : session管理器
* @return
*/
// @Bean("sessionManager")
public DefaultWebSessionManager sessionManager() {
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
// session的失效时长,默认是30 分钟((1800000)),该值以毫秒为时间单位
sessionManager.setGlobalSessionTimeout(TIMEOUT);
// 是否在会话过期后会调用SessionDAO的delete方法删除会话,默认true
sessionManager.setDeleteInvalidSessions(true);
// 间隔多少时间检查,不配置是60分钟
sessionManager.setSessionValidationScheduler(sessionValidationScheduler());
// 是否开启session验证检测
sessionManager.setSessionValidationSchedulerEnabled(true);
// 定时清理失效session , 清理用户直接关闭浏览器造成的孤立会话 :默认每小时检测一次
sessionManager.setSessionValidationInterval(INTERVAL);
// 是否启用/禁用,默认是启用的;如果禁用后将不会设置Session Id Cookie,即默认使用了Servlet容器的JSESSIONID
sessionManager.setSessionIdCookieEnabled(true);
sessionManager.setSessionIdCookie(sessionIdCookie());
// sessionManager.setSessionIdUrlRewritingEnabled(false);
// sessionManager.setSessionDAO(sessionDAO);
// session 监听
Collection<SessionListener> sessionListeners = Lists.newArrayList();
sessionListeners.add(new CustomSessionListener());
sessionManager.setSessionListeners(sessionListeners);
return sessionManager;
}
use of org.apache.shiro.session.SessionListener in project shiro by apache.
the class DefaultSessionManagerTest method testSessionListenerExpiredNotification.
@Test
public void testSessionListenerExpiredNotification() {
final boolean[] expired = new boolean[1];
SessionListener listener = new SessionListenerAdapter() {
public void onExpiration(Session session) {
expired[0] = true;
}
};
sm.getSessionListeners().add(listener);
sm.setGlobalSessionTimeout(100);
Session session = sm.start(null);
sleep(150);
try {
sm.checkValid(new DefaultSessionKey(session.getId()));
fail("check should have thrown an exception.");
} catch (InvalidSessionException expected) {
// do nothing - expected.
}
assertTrue(expired[0]);
}
Aggregations