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;
}
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;
}
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"));
}
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);
}
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;
}
Aggregations