Search in sources :

Example 1 with DefaultWebSessionManager

use of org.apache.shiro.web.session.mgt.DefaultWebSessionManager in project vip by guangdada.

the class ShiroConfig method defaultWebSessionManager.

/**
 * session管理器(单机环境)
 */
@Bean
@ConditionalOnProperty(prefix = "guns", name = "spring-session-open", havingValue = "false")
public DefaultWebSessionManager defaultWebSessionManager(CacheManager cacheShiroManager, GunsProperties gunsProperties) {
    DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
    sessionManager.setCacheManager(cacheShiroManager);
    sessionManager.setSessionValidationInterval(gunsProperties.getSessionValidationInterval() * 1000);
    sessionManager.setGlobalSessionTimeout(gunsProperties.getSessionInvalidateTime() * 1000);
    sessionManager.setDeleteInvalidSessions(true);
    sessionManager.setSessionValidationSchedulerEnabled(true);
    Cookie cookie = new SimpleCookie(ShiroHttpSession.DEFAULT_SESSION_ID_NAME);
    cookie.setName("shiroCookie");
    cookie.setHttpOnly(true);
    sessionManager.setSessionIdCookie(cookie);
    return sessionManager;
}
Also used : Cookie(org.apache.shiro.web.servlet.Cookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) DefaultWebSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) MethodInvokingFactoryBean(org.springframework.beans.factory.config.MethodInvokingFactoryBean) EhCacheManagerFactoryBean(org.springframework.cache.ehcache.EhCacheManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 2 with DefaultWebSessionManager

use of org.apache.shiro.web.session.mgt.DefaultWebSessionManager in project mica2 by obiba.

the class SecurityManagerFactory method initializeSessionManager.

private void initializeSessionManager(DefaultWebSecurityManager dsm) {
    DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
    sessionManager.setSessionDAO(new EnterpriseCacheSessionDAO());
    sessionManager.setSessionValidationInterval(SESSION_VALIDATION_INTERVAL);
    sessionManager.setSessionValidationSchedulerEnabled(true);
    dsm.setSessionManager(sessionManager);
}
Also used : EnterpriseCacheSessionDAO(org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO) DefaultWebSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager)

Example 3 with DefaultWebSessionManager

use of org.apache.shiro.web.session.mgt.DefaultWebSessionManager in project nutzboot by nutzam.

the class ShiroEnvStarter method getWebSessionManager.

@IocBean(name = "shiroWebSessionManager")
public WebSessionManager getWebSessionManager() {
    DefaultWebSessionManager webSessionManager = conf.make(DefaultWebSessionManager.class, "shiro.session.manager.");
    // 带缓存的shiro会话
    EnterpriseCacheSessionDAO sessionDAO = new EnterpriseCacheSessionDAO();
    sessionDAO.setSessionIdGenerator(new UU32SessionIdGenerator());
    webSessionManager.setSessionDAO(sessionDAO);
    // cookie
    conf.putIfAbsent(PROP_SESSION_COOKIE_NAME, "sid");
    conf.putIfAbsent(PROP_SESSION_COOKIE_MAXAGE, "946080000");
    conf.putIfAbsent(PROP_SESSION_COOKIE_HTTPONLY, "true");
    SimpleCookie cookie = conf.make(SimpleCookie.class, "shiro.session.cookie.");
    webSessionManager.setSessionIdCookie(cookie);
    webSessionManager.setSessionIdCookieEnabled(true);
    webSessionManager.setCacheManager(ioc.get(CacheManager.class, "shiroCacheManager"));
    return webSessionManager;
}
Also used : SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) EnterpriseCacheSessionDAO(org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO) DefaultWebSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager) LCacheManager(org.nutz.plugins.cache.impl.lcache.LCacheManager) MemoryConstrainedCacheManager(org.apache.shiro.cache.MemoryConstrainedCacheManager) RedisCacheManager(org.nutz.plugins.cache.impl.redis.RedisCacheManager) CacheManager(org.apache.shiro.cache.CacheManager) EhCacheManager(org.apache.shiro.cache.ehcache.EhCacheManager) UU32SessionIdGenerator(org.nutz.integration.shiro.UU32SessionIdGenerator) IocBean(org.nutz.ioc.loader.annotation.IocBean)

Example 4 with DefaultWebSessionManager

use of org.apache.shiro.web.session.mgt.DefaultWebSessionManager 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;
}
Also used : ArrayList(java.util.ArrayList) DefaultWebSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager) SessionListener(org.apache.shiro.session.SessionListener) InitializingBean(org.springframework.beans.factory.InitializingBean) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with DefaultWebSessionManager

use of org.apache.shiro.web.session.mgt.DefaultWebSessionManager 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;
}
Also used : DefaultWebSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager) SessionListener(org.apache.shiro.session.SessionListener) CustomSessionListener(com.cdeledu.core.shiro.listener.CustomSessionListener) CustomSessionListener(com.cdeledu.core.shiro.listener.CustomSessionListener)

Aggregations

DefaultWebSessionManager (org.apache.shiro.web.session.mgt.DefaultWebSessionManager)6 SessionListener (org.apache.shiro.session.SessionListener)2 EnterpriseCacheSessionDAO (org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO)2 ShiroFilterFactoryBean (org.apache.shiro.spring.web.ShiroFilterFactoryBean)2 SimpleCookie (org.apache.shiro.web.servlet.SimpleCookie)2 Bean (org.springframework.context.annotation.Bean)2 CustomSessionListener (com.cdeledu.core.shiro.listener.CustomSessionListener)1 ArrayList (java.util.ArrayList)1 CacheManager (org.apache.shiro.cache.CacheManager)1 MemoryConstrainedCacheManager (org.apache.shiro.cache.MemoryConstrainedCacheManager)1 EhCacheManager (org.apache.shiro.cache.ehcache.EhCacheManager)1 Cookie (org.apache.shiro.web.servlet.Cookie)1 UU32SessionIdGenerator (org.nutz.integration.shiro.UU32SessionIdGenerator)1 IocBean (org.nutz.ioc.loader.annotation.IocBean)1 LCacheManager (org.nutz.plugins.cache.impl.lcache.LCacheManager)1 RedisCacheManager (org.nutz.plugins.cache.impl.redis.RedisCacheManager)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 MethodInvokingFactoryBean (org.springframework.beans.factory.config.MethodInvokingFactoryBean)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 EhCacheManagerFactoryBean (org.springframework.cache.ehcache.EhCacheManagerFactoryBean)1