qq_34292472 2020-05-27 18:05 采纳率: 0%
浏览 329

spring security设置好了remember-me依然重定向到了登陆页面?

如题,我开启了security的remember-me功能,数据库查询正常,
浏览器登陆正常,第一次登陆的时候也成功的设置了remember-me的
cookie信息,数据库也正常存储了toeken信息,但是关闭浏览器之后直接
访问连接直接重定向到登陆页面,这是为什么?
附上配置信息

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
            http://www.springframework.org/schema/security
            http://www.springframework.org/schema/security/spring-security-4.2.xsd">
    <security:http auto-config="false">
        <security:intercept-url pattern="/error" access="permitAll()"/>
        <security:intercept-url pattern="/userlogin" access="permitAll()"/>
        <security:intercept-url pattern="/admin" access="hasAuthority('All')"/>
        <security:intercept-url pattern="/**" access="isFullyAuthenticated()"/>
        <!--        authentication-failure-url="/error" authentication-success-forward-url="/security"
                    认证失败跳转的页面,认证成功跳转的页面(这两个方法都是线程同步)
        -->
        <security:form-login login-page="/userlogin" login-processing-url="/user" authentication-success-handler-ref="succes" authentication-failure-handler-ref="failure"/>
        <!--        <security:access-denied-handler error-page="/error"/>-->
        <security:csrf disabled="true"/>
        <security:remember-me data-source-ref="dataSource" user-service-ref="userService"/>
    </security:http>
    <security:authentication-manager>
        <security:authentication-provider user-service-ref="userService">
            <security:password-encoder ref="password"/>
        </security:authentication-provider>
    </security:authentication-manager>
    <bean id="userService" class="com.project.config.UserService"/>
    <bean id="password" class="com.project.config.PasswordNo"/>
    <bean id="succes" class="com.project.config.MyAuthenticationnSuccessHandler"/>
    <bean id="failure" class="com.project.config.MyAuthenticationFailureHandler"/>
</beans>

jsp页面

<html>
<body>
<h2>这是登陆页面</h2>

<form id="loginForm" action="http://www.demo.com:8080/user" method="post">
    账号:<input type="text" name="username"><br/>
    密码:<input type="password" name="password"><br/>
    记住:<input type="checkbox" name="remember-me" value="true"/><br/>
    <input type="submit" value="提交">
</form>
</body>
</html>

请大佬帮我看一下实在是不知道到底还有哪里有问题了,非常感谢

这边后面调试了一下log4j配置信息,之前一直返回登陆界面其实是浏览器cookie存储的token与数据库存储的不匹配,因为log4j的配置问题没有输出异常信息.
今天分析源码发现PersistentTokenBasedRememberMeServices的
processAutoLoginCookie方法中的!presentedToken.equals(token.getTokenValue())作比较居然不相等,从而抛出:Invalid remember-me token (Series/token) mismatch. Implies previous cookie theft attack.
但是我解析cookie出来的token明明与数据库存储的token一模一样,为啥会判断不相等呢?

  • 写回答

1条回答 默认 最新

  • syyyyyyyyyyyyyyh 2020-05-28 10:13
    关注

    cookie不设置默认时间,关闭浏览器失效

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值