org.apache.shiro.web.servlet.SimpleCookie Java Examples

The following examples show how to use org.apache.shiro.web.servlet.SimpleCookie. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShiroConfig.java    From MeetingFilm with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: SessionManager.java    From easyweb with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #3
Source File: ShiroConfig.java    From WebStack-Guns with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: ShiroConfig.java    From yyblog with MIT License 5 votes vote down vote up
@Bean
public SimpleCookie rememberMeCookie(){
    //这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
    SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
    //如果httyOnly设置为true,则客户端不会暴露给客户端脚本代码,使用HttpOnly cookie有助于减少某些类型的跨站点脚本攻击;
    simpleCookie.setHttpOnly(true);
    //记住我cookie生效时间,默认30天 ,单位秒:60 * 60 * 24 * 30
    simpleCookie.setMaxAge(259200);
    return simpleCookie;
}
 
Example #5
Source File: ShiroConfiguration.java    From spring-boot-seed with MIT License 5 votes vote down vote up
/**
 * rememberMeCookie: 记住自己的cookie
 *
 * @return SimpleCookie
 */
@Bean
public SimpleCookie rememberMeCookie() {
    //这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
    SimpleCookie simpleCookie = new SimpleCookie(CookieEnum.REMEMBER_ME.getValue());
    //记住我cookie生效时间30天 ,单位秒;
    simpleCookie.setMaxAge(259200);
    return simpleCookie;
}
 
Example #6
Source File: ShiroConfig.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
/**
     * cookie对象;会话Cookie模板 ,默认为: JSESSIONID 问题: 与SERVLET容器名冲突,重新定义为sid或rememberMe,自定义
     * @return
     */
    @Bean
    public SimpleCookie rememberMeCookie(){
        //这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
        SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
        //setcookie的httponly属性如果设为true的话,会增加对xss防护的安全系数。它有以下特点:
        //setcookie()的第七个参数
        //设为true后,只能通过http访问,javascript无法访问
        //防止xss读取cookie
//        simpleCookie.setHttpOnly(true);
//        simpleCookie.setPath("/");
        //<!-- 记住我cookie生效时间30天 ,单位秒;-->
        simpleCookie.setMaxAge(2592000);
        return simpleCookie;
    }
 
Example #7
Source File: ShiroConfig.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * cookie 属性设置
 */
private SimpleCookie rememberMeCookie() {
    SimpleCookie cookie = new SimpleCookie("rememberMe");
    cookie.setDomain(domain);
    cookie.setPath(path);
    cookie.setHttpOnly(httpOnly);
    cookie.setMaxAge(maxAge * 24 * 60 * 60);
    return cookie;
}
 
Example #8
Source File: ShiroConfig.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 产生cookie
 */
@Bean
@ConditionalOnMissingBean
public SimpleCookie rememberMeCookie() {

	log.info("ShiroConfiguration.rememberMeCookie()");
	// 这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
	SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
	// <!-- 记住我cookie生效时间30天 ,单位秒;-->
	simpleCookie.setMaxAge(2592000);
	simpleCookie.setComment("my cookie comment");
	return simpleCookie;
}
 
Example #9
Source File: ShiroConfig.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * cookie 属性设置
 */
public SimpleCookie rememberMeCookie()
{
    SimpleCookie cookie = new SimpleCookie("rememberMe");
    cookie.setDomain(domain);
    cookie.setPath(path);
    cookie.setHttpOnly(httpOnly);
    cookie.setMaxAge(maxAge * 24 * 60 * 60);
    return cookie;
}
 
Example #10
Source File: ShiroConfig.java    From mysiteforme with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleCookie rememberMeCookie(){
    //这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
    SimpleCookie cookie = new SimpleCookie("rememberMe");
    cookie.setHttpOnly(true);
    //记住我有效期长达30天
    cookie.setMaxAge(2592000);
    return cookie;
}
 
Example #11
Source File: ShiroConfig.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
 * cookie对象;
 *
 * @return
 */
public SimpleCookie rememberMeCookie() {
    // 这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
    SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
    // 记住我cookie生效时间30天 ,单位秒。 注释掉,默认永久不过期 2018-07-15
    simpleCookie.setMaxAge(redisProperties.getExpire());
    return simpleCookie;
}
 
Example #12
Source File: ShiroConfig.java    From SpringAll with MIT License 5 votes vote down vote up
/**
 * cookie对象
 * @return
 */
public SimpleCookie rememberMeCookie() {
	// 设置cookie名称,对应login.html页面的<input type="checkbox" name="rememberMe"/>
	SimpleCookie cookie = new SimpleCookie("rememberMe");
	// 设置cookie的过期时间,单位为秒,这里为一天
	cookie.setMaxAge(86400);
	return cookie;
}
 
Example #13
Source File: ShiroConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: ShiroConfiguration.java    From easyweb with Apache License 2.0 5 votes vote down vote up
@Bean(name = "sessionManager")
public DefaultWebSessionManager getSessionManager(
        RedisSessionDAO sessionDAO,
        SimpleCookie sessionIdCookie) {
    SessionManager sessionManager = new SessionManager();
    sessionManager.setSessionDAO(sessionDAO);
    sessionManager.setGlobalSessionTimeout(1800000);
    //定时清理失效会话, 清理用户直接关闭浏览器造成的孤立会话4分钟检查一次
    sessionManager.setSessionValidationInterval(24000);
    sessionManager.setSessionValidationSchedulerEnabled(true);
    sessionManager.setSessionIdCookie(sessionIdCookie);
    sessionManager.setSessionIdCookieEnabled(true);
    return sessionManager;
}
 
Example #15
Source File: ShiroConfiguration.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
/**
 * cookie对象;
 * @return
 */
public SimpleCookie rememberMeCookie(){
   //这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
   SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
   //<!-- 记住我cookie生效时间30天 ,单位秒;-->
   simpleCookie.setMaxAge(2592000);
   return simpleCookie;
}
 
Example #16
Source File: ShiroConfig.java    From ElementVueSpringbootCodeTemplate with Apache License 2.0 5 votes vote down vote up
/**
 * cookie对象;
 *
 * @return
 */
public SimpleCookie rememberMeCookie() {
    // 这个参数是cookie的名称,对应前端的checkbox 的name = rememberMe
    SimpleCookie simpleCookie = new SimpleCookie("rememberMe");

    // <!-- 记住我cookie生效时间30天(259200) ,单位秒;-->
    simpleCookie.setMaxAge(259200);

    return simpleCookie;
}
 
Example #17
Source File: ShiroAutoConfiguration.java    From utils with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #18
Source File: SecurityConfiguration.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public Cookie rememberMeCookie() {
	SimpleCookie cookie = new SimpleCookie("rememberMe");
	cookie.setHttpOnly(true);
	cookie.setMaxAge(31536000);
	return cookie;
}
 
Example #19
Source File: ShiroConfig.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
@DependsOn("mybatisPlusConfig")
public SimpleCookie rememberMeCookie() {
    //这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
    SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
    // 记住我cookie生效时间 单位秒
    int adminRememberMeMaxAge = Integer.parseInt(systemConfigService.selectAllConfig().get
            ("admin_remember_me_max_age").toString());
    simpleCookie.setMaxAge(adminRememberMeMaxAge * 24 * 60 * 60);
    return simpleCookie;
}
 
Example #20
Source File: ShiroConfig.java    From EasyReport with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleCookie rememberMeCookie() {
    final SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
    simpleCookie.setHttpOnly(true);
    simpleCookie.setMaxAge(259200);
    return simpleCookie;
}
 
Example #21
Source File: ShiroConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * cookie 管理器
 * @return
 */
@Bean(name="cookieRememberMeManager")
@DependsOn({"simpleCookie"})
public CookieRememberMeManager getCookieRememberMeManager(SimpleCookie simpleCookie){
    CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
    cookieRememberMeManager.setCookie(simpleCookie);
    /**
     * 设置 rememberMe cookie 的密钥 ,不设置 很可能:javax.crypto.BadPaddingException: Given final block not properly padded
     */
    cookieRememberMeManager.setCipherKey(Base64.decode("2AvVhdsgUs0FSA3SDFAdag=="));
    return cookieRememberMeManager ;
}
 
Example #22
Source File: ShiroConfig.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * cookie 属性设置
 */
public SimpleCookie rememberMeCookie()
{
    SimpleCookie cookie = new SimpleCookie("rememberMe");
    cookie.setDomain(domain);
    cookie.setPath(path);
    cookie.setHttpOnly(httpOnly);
    cookie.setMaxAge(maxAge * 24 * 60 * 60);
    return cookie;
}
 
Example #23
Source File: ShiroConfig.java    From erp-framework with MIT License 5 votes vote down vote up
/**
 * cookie对象,通过登录界面的记住我
 * @return
 */
@Bean
public SimpleCookie rememberMeCookie(){
    //这个参数是cookie的名称,对应前端的checkbox的name = rememberMe
    SimpleCookie cookie = new SimpleCookie("rememberMe");

    //setcookie的httponly属性如果设为true的话,会增加对xss防护的安全系数。它有以下特点:
    //setcookie()的第七个参数
    //设为true后,只能通过http访问,javascript无法访问
    //防止xss读取cookie
    cookie.setHttpOnly(true);
    //记住我有效期长达30天
    cookie.setMaxAge(2592000);
    return cookie;
}
 
Example #24
Source File: ShiroConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 设置rememberMe  Cookie 7天
 * @return
 */
@Bean(name="simpleCookie")
public SimpleCookie getSimpleCookie(){
    SimpleCookie simpleCookie = new SimpleCookie();
    simpleCookie.setName("rememberMe");
    simpleCookie.setHttpOnly(true);
    simpleCookie.setMaxAge(7*24*60*60);
    return simpleCookie ;
}
 
Example #25
Source File: ShiroConfig.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * cookie 管理器
 * @return
 */
@Bean(name="cookieRememberMeManager")
@DependsOn({"simpleCookie"})
public CookieRememberMeManager getCookieRememberMeManager(SimpleCookie simpleCookie){
    CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager();
    cookieRememberMeManager.setCookie(simpleCookie);
    /**
     * 设置 rememberMe cookie 的密钥 ,不设置 很可能:javax.crypto.BadPaddingException: Given final block not properly padded
     */
    cookieRememberMeManager.setCipherKey(Base64.decode("2AvVhdsgUs0FSA3SDFAdag=="));
    return cookieRememberMeManager ;
}
 
Example #26
Source File: ShiroConfig.java    From MeetingFilm with Apache License 2.0 5 votes vote down vote up
/**
 * rememberMe管理器, cipherKey生成见{@code Base64Test.java}
 */
@Bean
public CookieRememberMeManager rememberMeManager(SimpleCookie rememberMeCookie) {
    CookieRememberMeManager manager = new CookieRememberMeManager();
    manager.setCipherKey(Base64.decode("Z3VucwAAAAAAAAAAAAAAAA=="));
    manager.setCookie(rememberMeCookie);
    return manager;
}
 
Example #27
Source File: ShiroConfig.java    From MeetingFilm with Apache License 2.0 5 votes vote down vote up
/**
 * 记住密码Cookie
 */
@Bean
public SimpleCookie rememberMeCookie() {
    SimpleCookie simpleCookie = new SimpleCookie("rememberMe");
    simpleCookie.setHttpOnly(true);
    simpleCookie.setMaxAge(7 * 24 * 60 * 60);//7天
    return simpleCookie;
}
 
Example #28
Source File: FormAuthenticationFilter.java    From frpMgr with MIT License 5 votes vote down vote up
/**
 * 构造方法
 */
public FormAuthenticationFilter() {
	super();
	rememberUserCodeCookie = new SimpleCookie(DEFAULT_REMEMBER_USERCODE_PARAM);
	rememberUserCodeCookie.setHttpOnly(true);
       rememberUserCodeCookie.setMaxAge(Cookie.ONE_YEAR);
}
 
Example #29
Source File: ShiroConfig.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * cookie 属性设置
 */
public SimpleCookie rememberMeCookie()
{
    SimpleCookie cookie = new SimpleCookie("rememberMe");
    cookie.setDomain(domain);
    cookie.setPath(path);
    cookie.setHttpOnly(httpOnly);
    cookie.setMaxAge(maxAge * 24 * 60 * 60);
    return cookie;
}
 
Example #30
Source File: AuthConfig.java    From v-mock with MIT License 5 votes vote down vote up
/**
 * cookie 属性设置
 */
public SimpleCookie rememberMeCookie() {
    SimpleCookie cookie = new SimpleCookie("rememberMe");
    cookie.setPath("/");
    cookie.setHttpOnly(true);
    cookie.setMaxAge(30 * 24 * 60 * 60);
    return cookie;
}