本文整理汇总了Java中org.apache.shiro.web.servlet.SimpleCookie类的典型用法代码示例。如果您正苦于以下问题:Java SimpleCookie类的具体用法?Java SimpleCookie怎么用?Java SimpleCookie使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleCookie类属于org.apache.shiro.web.servlet包,在下文中一共展示了SimpleCookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultWebSessionManager
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
/**
* @see DefaultWebSessionManager
*/
@Bean(name = "sessionManager")
public DefaultWebSessionManager defaultWebSessionManager() {
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
//sessionManager.setSessionDAO(new CustomSessionDAO());
sessionManager.setCacheManager(ehCacheManager());
//单位为毫秒(1秒=1000毫秒) 3600000毫秒为1个小时
sessionManager.setSessionValidationInterval(3600000 * 12);
//3600000 milliseconds = 1 hour
sessionManager.setGlobalSessionTimeout(3600000 * 12);
sessionManager.setDeleteInvalidSessions(true);
sessionManager.setSessionValidationSchedulerEnabled(true);
Cookie cookie = new SimpleCookie(ShiroHttpSession.DEFAULT_SESSION_ID_NAME);
cookie.setName("WEBID");
cookie.setHttpOnly(true);
sessionManager.setSessionIdCookie(cookie);
return sessionManager;
}
示例2: getSessionId
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Override
protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
// 如果参数中包含“__sid”参数,则使用此sid会话。 例如:http://localhost/project?__sid=xxx&__cookie=true
String sid = request.getParameter("__sid");
if (StringUtils.isNotBlank(sid)) {
// 是否将sid保存到cookie,浏览器模式下使用此参数。
if (WebUtils.isTrue(request, "__cookie")) {
HttpServletRequest rq = (HttpServletRequest) request;
HttpServletResponse rs = (HttpServletResponse) response;
Cookie template = getSessionIdCookie();
Cookie cookie = new SimpleCookie(template);
cookie.setValue(sid);
cookie.saveTo(rq, rs);
}
// 设置当前session状态
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE, ShiroHttpServletRequest.URL_SESSION_ID_SOURCE); // session来源与url
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID, sid);
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID, Boolean.TRUE);
return sid;
} else {
return super.getSessionId(request, response);
}
}
示例3: getSessionId
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Override
protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
// 如果参数中包含“__sid”参数,则使用此sid会话。
// 例如:http://localhost/project?__sid=xxx&__cookie=true
String sid = request.getParameter("__sid");
if (StringUtils.isNotBlank(sid)) {
// 是否将sid保存到cookie,浏览器模式下使用此参数。
if (WebUtils.isTrue(request, "__cookie")) {
HttpServletRequest rq = (HttpServletRequest) request;
HttpServletResponse rs = (HttpServletResponse) response;
Cookie template = getSessionIdCookie();
Cookie cookie = new SimpleCookie(template);
cookie.setValue(sid);
cookie.saveTo(rq, rs);
}
// 设置当前session状态
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE,
ShiroHttpServletRequest.URL_SESSION_ID_SOURCE); // session来源与url
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID, sid);
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID, Boolean.TRUE);
return sid;
} else {
return super.getSessionId(request, response);
}
}
示例4: rememberSerializedIdentity
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
/**
* 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);
Cookie template = getCookie(); //the class attribute is really a template for the outgoing cookies
Cookie cookie = new SimpleCookie(template);
cookie.setValue(base64);
cookie.saveTo(request, response);
}
示例5: sessionIdCookie
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Bean(name="sessionIdCookie")
public SimpleCookie sessionIdCookie (){
SimpleCookie simpleCookie = new SimpleCookie("sid");
simpleCookie.setHttpOnly(true);
simpleCookie.setMaxAge(-1);
return simpleCookie;
}
示例6: rememberMeCookie
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Bean(name="rememberMeCookie")
public SimpleCookie rememberMeCookie(){
SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
simpleCookie.setHttpOnly(true);
simpleCookie.setMaxAge(2592000); //30天
return simpleCookie;
}
示例7: getSessionManager
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Bean(name = "sessionManager")
public DefaultWebSessionManager getSessionManager(
SessionDAO sessionDAO,
SimpleCookie sessionIdCookie) {
SessionManager sessionManager=new SessionManager();
// SessionManager sessionManager = new SessionManager();
sessionManager.setSessionDAO(sessionDAO);
sessionManager.setGlobalSessionTimeout(1800000);
//定时清理失效会话, 清理用户直接关闭浏览器造成的孤立会话
sessionManager.setSessionValidationInterval(120000);
sessionManager.setSessionValidationSchedulerEnabled(true);
sessionManager.setSessionIdCookie(sessionIdCookie);
sessionManager.setSessionIdCookieEnabled(true);
return sessionManager;
}
示例8: getSessionId
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Override
protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
// 如果参数中包含“__sid”参数,则使用此sid会话。 例如:http://localhost/project?__sid=xxx&__cookie=true
String sid = request.getParameter("__sid");
if (StringUtils.isNotBlank(sid)) {
// 是否将sid保存到cookie,浏览器模式下使用此参数。
if (WebUtils.isTrue(request, "__cookie")){
HttpServletRequest rq = (HttpServletRequest)request;
HttpServletResponse rs = (HttpServletResponse)response;
Cookie template = getSessionIdCookie();
Cookie cookie = new SimpleCookie(template);
cookie.setValue(sid); cookie.saveTo(rq, rs);
}
// 设置当前session状态
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE,
ShiroHttpServletRequest.URL_SESSION_ID_SOURCE); // session来源与url
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID, sid);
request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID, Boolean.TRUE);
return sid;
}else{
return super.getSessionId(request, response);
}
}
示例9: getSessionIdCookie
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Bean(name = "sessionIdCookie")
public SimpleCookie getSessionIdCookie() {
SimpleCookie cookie = new SimpleCookie("lemsid");
cookie.setHttpOnly(true); //-- 安全的考虑
cookie.setMaxAge(-1); //-- 仅存在与浏览器进程,浏览器关闭则失效
return cookie;
}
示例10: rememberMeCookie
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(Cookie.class)
public Cookie rememberMeCookie() {
SimpleCookie cookie = new SimpleCookie();
cookie.setName(authFilterProperties.getRememberMeParamName());
cookie.setMaxAge(shiroCookieProperties.getMaxAge());
cookie.setValue(shiroCookieProperties.getValue());
cookie.setVersion(shiroCookieProperties.getVersion());
cookie.setHttpOnly(shiroCookieProperties.isHttpOnly());
cookie.setSecure(shiroCookieProperties.isSecure());
return cookie;
}
示例11: rememberMeCookie
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Bean
public Cookie rememberMeCookie() {
SimpleCookie cookie = new SimpleCookie("rememberMe");
cookie.setHttpOnly(true);
cookie.setMaxAge(31536000);
return cookie;
}
示例12: rememberMeCookie
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
@Bean
public SimpleCookie rememberMeCookie() {
SimpleCookie cookie = new SimpleCookie("rememberMe");
cookie.setHttpOnly(true);
cookie.setMaxAge(2592000);
return cookie;
}
示例13: DefaultWebSessionManager
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
public DefaultWebSessionManager() {
Cookie cookie = new SimpleCookie(ShiroHttpSession.DEFAULT_SESSION_ID_NAME);
cookie.setHttpOnly(true); //more secure, protects against XSS attacks
this.sessionIdCookie = cookie;
this.sessionIdCookieEnabled = true;
this.sessionIdUrlRewritingEnabled = true;
}
示例14: storeSessionId
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
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);
}
示例15: CookieRememberMeManager
import org.apache.shiro.web.servlet.SimpleCookie; //导入依赖的package包/类
/**
* Constructs a new {@code CookieRememberMeManager} with a default {@code rememberMe} cookie template.
*/
public CookieRememberMeManager() {
Cookie cookie = new SimpleCookie(DEFAULT_REMEMBER_ME_COOKIE_NAME);
cookie.setHttpOnly(true);
//One year should be long enough - most sites won't object to requiring a user to log in if they haven't visited
//in a year:
cookie.setMaxAge(Cookie.ONE_YEAR);
this.cookie = cookie;
}