Search in sources :

Example 6 with SimpleCookie

use of org.apache.shiro.web.servlet.SimpleCookie 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 7 with SimpleCookie

use of org.apache.shiro.web.servlet.SimpleCookie in project vip by guangdada.

the class ShiroConfig method rememberMeCookie.

/**
 * 记住密码Cookie
 */
@Bean
public SimpleCookie rememberMeCookie() {
    SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
    simpleCookie.setHttpOnly(true);
    // 7天
    simpleCookie.setMaxAge(7 * 24 * 60 * 60);
    return simpleCookie;
}
Also used : SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) 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)

Example 8 with SimpleCookie

use of org.apache.shiro.web.servlet.SimpleCookie in project wechat by dllwh.

the class ShiroConfig method rememberMeCookie.

/**
 * @方法描述 : 记住我
 * @return
 */
public SimpleCookie rememberMeCookie() {
    // 这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
    SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
    // 记住我cookie生效时间30天 ,单位秒;
    simpleCookie.setMaxAge(2592000);
    return simpleCookie;
}
Also used : SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie)

Example 9 with SimpleCookie

use of org.apache.shiro.web.servlet.SimpleCookie in project shiro by apache.

the class DefaultWebSessionManager method storeSessionId.

private void storeSessionId(Serializable currentId, HttpServletRequest request, HttpServletResponse response) {
    if (currentId == null) {
        String msg = "sessionId cannot be null when persisting for subsequent requests.";
        throw new IllegalArgumentException(msg);
    }
    Cookie template = getSessionIdCookie();
    Cookie cookie = new SimpleCookie(template);
    String idString = currentId.toString();
    cookie.setValue(idString);
    cookie.saveTo(request, response);
    log.trace("Set session ID cookie for session with id {}", idString);
}
Also used : Cookie(org.apache.shiro.web.servlet.Cookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie)

Example 10 with SimpleCookie

use of org.apache.shiro.web.servlet.SimpleCookie in project shiro by apache.

the class AbstractShiroWebConfiguration method buildCookie.

protected Cookie buildCookie(String name, int maxAge, String path, String domain, boolean secure) {
    Cookie cookie = new SimpleCookie(name);
    cookie.setHttpOnly(true);
    cookie.setMaxAge(maxAge);
    cookie.setPath(path);
    cookie.setDomain(domain);
    cookie.setSecure(secure);
    return cookie;
}
Also used : Cookie(org.apache.shiro.web.servlet.Cookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie)

Aggregations

SimpleCookie (org.apache.shiro.web.servlet.SimpleCookie)11 Cookie (org.apache.shiro.web.servlet.Cookie)5 ShiroFilterFactoryBean (org.apache.shiro.spring.web.ShiroFilterFactoryBean)3 Bean (org.springframework.context.annotation.Bean)3 DefaultWebSessionManager (org.apache.shiro.web.session.mgt.DefaultWebSessionManager)2 IocBean (org.nutz.ioc.loader.annotation.IocBean)2 MethodInvokingFactoryBean (org.springframework.beans.factory.config.MethodInvokingFactoryBean)2 EhCacheManagerFactoryBean (org.springframework.cache.ehcache.EhCacheManagerFactoryBean)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CacheManager (org.apache.shiro.cache.CacheManager)1 MemoryConstrainedCacheManager (org.apache.shiro.cache.MemoryConstrainedCacheManager)1 EhCacheManager (org.apache.shiro.cache.ehcache.EhCacheManager)1 EnterpriseCacheSessionDAO (org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO)1 CookieRememberMeManager (org.apache.shiro.web.mgt.CookieRememberMeManager)1 ShiroHttpServletRequest (org.apache.shiro.web.servlet.ShiroHttpServletRequest)1 SimplePrincipalSerializer (org.nutz.integration.shiro.SimplePrincipalSerializer)1 UU32SessionIdGenerator (org.nutz.integration.shiro.UU32SessionIdGenerator)1 LCacheManager (org.nutz.plugins.cache.impl.lcache.LCacheManager)1 RedisCacheManager (org.nutz.plugins.cache.impl.redis.RedisCacheManager)1