Springs Simple<记住我>不工作:-(

发布于 2024-09-19 18:13:14 字数 1223 浏览 12 评论 0原文

我正在尝试利用 Spring Security 的 身份验证。我的安全上下文中的行如下所示:

 <security:remember-me key="89dqj219dn910lsAc12" user-service-ref="jpaUserDetailsService"/>

虽然我使用自己的 UserDetailsS​​ervice 实现(已测试且工作正常),但我也尝试过使用默认的实现来遇到相同的问题,即:

  1. 在选中“记住我”复选框的情况下登录,会按预期生成 cookie:

    名称:SPRING_SECURITY_REMEMBER_ME_COOKIE;值:c2FzczoxMjg1NTIxOTI1NzY4OmIxODQ5YTE2ZDY1MDVmZDFhNWRlN2Y2NzFlMzc1MmI0;主机:本地主机;路径:/webapp;安全:否;有效期至:2010 年 9 月 26 日星期日 17:25:25 GMT)

  2. 浏览器已重新启动

  3. cookie仍然存在

  4. 尝试访问任何安全页面都会以“访问被拒绝”错误结束:

    org.springframework.security.access.AccessDeniedException:访问被拒绝

    作为字符串的身份验证对象:org.springframework.security.authentication.RememberMeAuthenticationToken@ffcaab94:主体:de.myapp.businessobjects.AppUser@35c12e:用户名:用户名;密码:[受保护];启用:真;帐户未过期:true;凭证未过期:true;帐户非锁定:true;个人信息:32768; ;凭证:[受保护];已验证:真实;详细信息:org.springframework.security.web.authentication.WebAuthenticationDetails@957e:RemoteIpAddress:127.0.0.1;会话 ID:空;未授予任何权限

我很困惑,不知道出了什么问题或从哪里开始调试。请帮忙?

I am trying to make use of Spring Security's <remember-me/> authentification. The line in my security context looks like this:

 <security:remember-me key="89dqj219dn910lsAc12" user-service-ref="jpaUserDetailsService"/>

Although I use my own implementation of UserDetailsService (tested & working), I have also tried with the default one running into the same issue, which is this:

  1. Logging in with "remember-me" checkbox checked, a cookie is generated as expected:

    Name: SPRING_SECURITY_REMEMBER_ME_COOKIE; Value: c2FzczoxMjg1NTIxOTI1NzY4OmIxODQ5YTE2ZDY1MDVmZDFhNWRlN2Y2NzFlMzc1MmI0; Host: localhost; Path: /webapp; Secure: No; Valid until: Sun, 26 Sep 2010 17:25:25 GMT)

  2. The browser restarted

  3. The cookie is still there

  4. Trying to access any secured page ends in "Access denied" error:

    org.springframework.security.access.AccessDeniedException: Access is denied

    Authentication object as a String: org.springframework.security.authentication.RememberMeAuthenticationToken@ffcaab94: Principal: de.myapp.businessobjects.AppUser@35c12e: Username: username; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; PersonalInformation: 32768; ; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@957e: RemoteIpAddress: 127.0.0.1; SessionId: null; Not granted any authorities

I am confused an do not know what goes wrong or where to start debugging. Help, please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巴黎夜雨 2024-09-26 18:13:14

看起来用户已成功通过身份验证,但由于某种原因他没有权限(即角色)。因此,请确保您的 UserDetailsS​​ervice 返回的用户详细信息从 UserDetails.getAuthorities() 返回正确的权限。

It looks like user is successfully authenticated, but for some reason he has no authorities (i.e. roles). So, make sure that user details returned by your UserDetailsService returns proper authorities from UserDetails.getAuthorities().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文