Search in sources :

Example 1 with SimpleCookie

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

use of org.apache.shiro.web.servlet.SimpleCookie in project Spring-Family by Sierou-Java.

the class ShiroConfiguration method rememberMeCookie.

// /////////////////////////////////////缓存 END/////////////////////////////////////
// /////////////////////////////////////记住我 START/////////////////////////////////////
/**
 * cookie对象;
 * @return
 */
@Bean
public SimpleCookie rememberMeCookie() {
    System.out.println("ShiroConfiguration.rememberMeCookie()");
    // 这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
    SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
    // <!-- 记住我cookie生效时间30天 ,单位秒;-->
    simpleCookie.setMaxAge(259200);
    return simpleCookie;
}
Also used : SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with SimpleCookie

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

the class SampleShiroNativeSessionsServletModule method bindSessionManager.

@Override
protected void bindSessionManager(AnnotatedBindingBuilder<SessionManager> bind) {
    bind.to(DefaultWebSessionManager.class);
    bindConstant().annotatedWith(Names.named("shiro.globalSessionTimeout")).to(5000L);
    bindConstant().annotatedWith(Names.named("shiro.sessionIdUrlRewritingEnabled")).to(false);
    bind(DefaultWebSessionManager.class);
    bind(Cookie.class).toInstance(new SimpleCookie("myCookie"));
}
Also used : Cookie(org.apache.shiro.web.servlet.Cookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie)

Example 4 with SimpleCookie

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

the class CookieRememberMeManager method rememberSerializedIdentity.

/**
 * Base64-encodes the specified serialized byte array and sets that base64-encoded String as the cookie value.
 * <p/>
 * The {@code subject} instance is expected to be a {@link WebSubject} instance with an HTTP Request/Response pair
 * so an HTTP cookie can be set on the outgoing response.  If it is not a {@code WebSubject} or that
 * {@code WebSubject} does not have an HTTP Request/Response pair, this implementation does nothing.
 *
 * @param subject    the Subject for which the identity is being serialized.
 * @param serialized the serialized bytes to be persisted.
 */
protected void rememberSerializedIdentity(Subject subject, byte[] serialized) {
    if (!WebUtils.isHttp(subject)) {
        if (log.isDebugEnabled()) {
            String msg = "Subject argument is not an HTTP-aware instance.  This is required to obtain a servlet " + "request and response in order to set the rememberMe cookie. Returning immediately and " + "ignoring rememberMe operation.";
            log.debug(msg);
        }
        return;
    }
    HttpServletRequest request = WebUtils.getHttpRequest(subject);
    HttpServletResponse response = WebUtils.getHttpResponse(subject);
    // base 64 encode it and store as a cookie:
    String base64 = Base64.encodeToString(serialized);
    // the class attribute is really a template for the outgoing cookies
    Cookie template = getCookie();
    Cookie cookie = new SimpleCookie(template);
    cookie.setValue(base64);
    cookie.saveTo(request, response);
}
Also used : ShiroHttpServletRequest(org.apache.shiro.web.servlet.ShiroHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Cookie(org.apache.shiro.web.servlet.Cookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) SimpleCookie(org.apache.shiro.web.servlet.SimpleCookie) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 5 with SimpleCookie

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

the class ShiroConfig method sessionIdCookie.

/**
 * ----------------------------------------------- [公共方法]
 */
/**
 * ----------------------------------------------- [私有方法]
 */
/**
 * @方法描述 : sessionIdCookie的实现,用于重写覆盖容器默认的JSESSIONID
 * @return
 */
public SimpleCookie sessionIdCookie() {
    SimpleCookie cookie = new SimpleCookie();
    cookie.setName("shiro.sesssionCookie");
    // 设置Cookie的路径,默认空,即存储在域名根下
    cookie.setPath("/");
    // 设置Cookie的过期时间,秒为单位,默认-1表示关闭浏览器时过期Cookie
    cookie.setMaxAge(7200);
    // 如果设置为true,则客户端不会暴露给客户端脚本代码,使用HttpOnly cookie有助于减少某些类型的跨站点脚本攻击
    cookie.setHttpOnly(true);
    return cookie;
}
Also used : 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