shiro rememberMe cookie 过期时间

ja_rome 2017-02-09 05:18:27
在项目中集成shiro ,配置了rememberMe 记住我,但是浏览器cookie中却没有rememberMe,看了下网页信息,发现cookie的创建时间与过期时间是相同的。

shiro 配置文件如下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<!-- web.xml中shiro对应的过滤器名称 -->
<!-- Shiro 的Web过滤器 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<!-- loginUrl认证提交地址,如果没有认证将会请求此地址进行认证,请求此地址将由formAuthenticationFilter进行表单认证 -->
<property name="loginUrl" value="/login" />
<!-- 认证成功统一跳转到first.action,建议不配置,shiro认证成功自动到上一个请求路径 -->
<property name="successUrl" value="/index" />
<!-- 没有权限操作时的跳转页面 -->
<property name="unauthorizedUrl" value="/403" />
<!-- 自定义filter配置 -->
<property name="filters">
<map>
<!-- 将自定义 的FormAuthenticationFilter注入shiroFilter中 -->
<entry key="authc" value-ref="formAuthenticationFilter" />
<!-- sesion过滤器 -->
<entry key="kickout" value-ref="carfiKickout" />
</map>
</property>
<!-- 过虑器链定义,从上向下顺序执行,一般将/**放在最下边 -->
<property name="filterChainDefinitions">
<value>
/getVerifyCode = anon
/validVerifyCode = anon
/bootstrapValidator/** = anon
/cityselect/** = anon
/css/** = anon
/dist/** = anon
/img/** = anon
/js/** = anon
/lay/** = anon
/layer/** = anon
/vendor/** = anon
/common/** = anon
/echarts/** = anon
/ads/** = anon
/kickout.jsp = anon
/logout = logout
/index.jsp = user,kickout
/index = user,kickout
/carfi/** = user,kickout
/sys/** = user,kickout
/org/** = user,kickout
/ = user,kickout
/** = authc,kickout
</value>
</property>
</bean>
<!-- kickout过滤器 -->
<bean id="carfiKickout" class="com.carfi.vrcp.shiro.CarfiKickoutFilter">
<property name="cacheManager" ref="shiroCacheManager"/>
<property name="sessionManager" ref="sessionManager"/>
<property name="kickoutAfter" value="false"/>
<property name="maxSession" value="1"/>
<property name="kickoutUrl" value="/kickout.jsp"/>
</bean>
<!-- 安全管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="userRealm" />
<!-- 注入缓存管理器 -->
<property name="cacheManager" ref="shiroCacheManager" />
<!-- 注入session管理器 -->
<property name="sessionManager" ref="sessionManager" />
<!-- 记住我 -->
<property name="rememberMeManager" ref="rememberMeManager" />
</bean>

<!-- 自定义 realm -->
<bean id="userRealm" class="com.carfi.vrcp.shiro.CustomRealm">
<!-- 将凭证匹配器设置到realm中,realm按照凭证匹配器的要求进行散列 -->
<property name="credentialsMatcher" ref="credentialsMatcher" />
</bean>

<!-- 凭证匹配器 -->
<bean id="credentialsMatcher"
class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<!-- MD5加密 -->
<property name="hashAlgorithmName" value="md5" />
<!-- 散列 -->
<property name="hashIterations" value="1" />
</bean>

<!-- 缓存管理器 使用Ehcache实现 -->
<bean id="shiroCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManager" ref="ehCacheManager" />
</bean>
<!-- 缓存管理器 -->
<!-- <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<property name="cacheManagerConfigFile" value="classpath:shiro-ehcache.xml"
/> </bean> -->
<!-- 会话管理器 -->
<bean id="sessionManager"
class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
<!-- session的失效时长,单位毫秒 -->
<property name="globalSessionTimeout" value="360000000" />
<!-- 删除失效的session -->
<property name="deleteInvalidSessions" value="true" />
</bean>
<!-- 自定义form认证过虑器 -->
<!-- 基于Form表单的身份验证过滤器,不配置将也会注册此过虑器,表单中的用户账号、密码及loginurl将采用默认值,建议配置 -->
<bean id="formAuthenticationFilter" class="com.carfi.vrcp.shiro.CustomFormAuthenticationFilter">
<!-- 表单中账号的input名称 -->
<property name="usernameParam" value="username" />
<!-- 表单中密码的input名称 -->
<property name="passwordParam" value="password" />
<!-- 记住我input的名称 -->
<property name="rememberMeParam" value="rememberMe" />
</bean>
<!-- 启用shrio授权注解拦截方式 -->
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
<!-- rememberMeManager管理器,写cookie,取出cookie生成用户信息 -->
<bean id="rememberMeManager" class="org.apache.shiro.web.mgt.CookieRememberMeManager">
<property name="cipherKey" value="#{T(org.apache.shiro.codec.Base64).decode('4AvVhmFLUs0KTA3Kprsdag==')}"/>
<property name="cookie" ref="rememberMeCookie" />
</bean>
<!-- 记住我cookie -->
<bean id="rememberMeCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
<!-- rememberMe是cookie的名字 -->
<constructor-arg value="rememberMe" />
<property name="httpOnly" value="true"/>
<!-- 记住我cookie生效时间30天 2592000 604800-->
<property name="maxAge" value="2592000" />
</bean>

</beans>

请教各位大神,怎样解决该问题?
...全文
1110 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ja_rome 2019-05-22
  • 打赏
  • 举报
回复
引用 7 楼 JackSparrow414 的回复:
引用 6 楼 ja_rome 的回复:
[quote=引用 5 楼 JackSparrow414 的回复:] 楼主,有解决方法了吗?我也遇到了这样的情况
过去太久远了。我忘记了
我找到原因了,是由于在AuthenticationInfo中SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(authUser, password, getName());这个位置,第一个参数,如果传的是对象,但是这个对象没有实现Serializable接口,就会出现这样的问题[/quote]干得漂亮,就用你这个来结贴算了。哈哈
JackSparrow414 2019-03-27
  • 打赏
  • 举报
回复
引用 6 楼 ja_rome 的回复:
引用 5 楼 JackSparrow414 的回复:
楼主,有解决方法了吗?我也遇到了这样的情况
过去太久远了。我忘记了
我找到原因了,是由于在AuthenticationInfo中SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(authUser, password, getName());这个位置,第一个参数,如果传的是对象,但是这个对象没有实现Serializable接口,就会出现这样的问题
ja_rome 2019-03-26
  • 打赏
  • 举报
回复
引用 5 楼 JackSparrow414 的回复:
楼主,有解决方法了吗?我也遇到了这样的情况
过去太久远了。我忘记了
JackSparrow414 2019-03-25
  • 打赏
  • 举报
回复
楼主,有解决方法了吗?我也遇到了这样的情况
AM18 2017-08-04
  • 打赏
  • 举报
回复
楼主,楼主,楼主,呼叫。。。。
AM18 2017-08-04
  • 打赏
  • 举报
回复
请问你解决了没有,我的也是这个问题!!!
biaonian8601 2017-04-06
  • 打赏
  • 举报
回复
请问你解决了没有,我的也是这个问题!!!
ja_rome 2017-02-09
  • 打赏
  • 举报
回复
都没人回答吗?

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧