Jat*_*tin 0 java spring spring-security
我花了一天时间,但不明白为什么remember_meSPring Security无法正常工作.我只使用xml作为配置,没有Java代码:
<http use-expressions="false" auto-config="true">
        <intercept-url pattern="/css/**" filters="none" />
        <intercept-url pattern="/**" access="ROLE_USER" />
        <form-login login-page="/BL/index.html" default-target-url="/BL/main.html"
            authentication-failure-url="/BL/index.html?autherror=true"
            always-use-default-target='true' />
        <logout logout-url="/logout" logout-success-url="/BL/index.html"
            invalidate-session="true" />
        <remember-me data-source-ref="dataSource"
            user-service-ref="jdbcUserService" key="99999989"
            token-validity-seconds="86400" />
        <access-denied-handler error-page="/BL/index.html?autherror=true" />
    </http>
简而言之index.html就是我的登录页面.当我登录时,我看到一个cookie由名称SPRING_SECURITY_REMEMBER_ME_COOKIE和值创建V2FrblE1Vlk3cFd6ZDIvZnRjdnlIZz09OndOb2h2NmUvdFlZRHJvRFRPV3lheHc9PQ.
但如果我现在回到index.html页面,它会要求我再次登录.我仍然看到相同的cookie值.上面的xml配置中有什么错误?我希望它不应该让我再次登录,但应该重定向到我的主页,因为我已经登录了.
我看到下面的登录服务器.看起来正在将请求作为空字符串发送给用户:
14:16:34,031 DEBUG JdbcUserDetailsManager:155 - 查询返回没有结果用户''14:16:34,031 DEBUG DaoAuthenticationProvider:131 - 用户''未找到14:16:34,031 DEBUG UsernamePasswordAuthenticationFilter:318 - 验证请求失败:org.springframework .security.authentication.BadCredentialsException:错误凭据14:16:34,032 DEBUG UsernamePasswordAuthenticationFilter:319 - 更新了SecurityContextHolder以包含null身份验证14:16:34,032 DEBUG UsernamePasswordAuthenticationFilter:320 - 委托身份验证失败handlerorg.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler @ 6011c7cf 14:16:34,032 DEBUG PersistentTokenBasedRememberMeServices:214 - 交互式登录尝试失败.14:16:34,032 DEBUG PersistentTokenBasedRememberMeServices:300 - 取消cookie 14:16:34,032 DEBUG SimpleUrlAuthenticationFailureHandler:67 - 重定向到/BL/index.html?autherror=true
Spring不会阻止登录用户访问登录页面.
要测试RememberMe提供程序,您至少需要两个页面(使用不同的登录名)
用户拥有此cookie后,您可以关闭浏览器,再次打开浏览器,然后直接访问受保护的页面(不应将用户重定向或转发到登录页面)
但是您的日志声明显示,您尝试通过登录页面登录用户,另一方面您告诉您要使用记住我令牌.- 对于使用"记住我"Cookie,您不能请求登录页面,而是一些普通页面.
RememberMeAuthenticationFilter将(在尝试登录时)在DEBUG级别打印此消息:
| 归档时间: | 
 | 
| 查看次数: | 3122 次 | 
| 最近记录: |