【问题标题】:Spring security remember-me with customAuthenticationProvider带有 customAuthenticationProvider 的 Spring 安全记住我
【发布时间】:2013-06-11 12:24:30
【问题描述】:

我正在使用CustomAuthentication 提供程序进行身份验证,它扩展了AbstractUserDetailsAuthenticationProvider。我必须这样做,因为我想针对 Web 服务进行身份验证,并且需要用户 ID 和密码。这是唯一允许我这样做的课程。 现在我在实现记住我的功能时遇到了问题,这是我的安全上下文文件 -

<http auto-config="true">
    <intercept-url pattern="/j_spring_security_check" access="IS_AUTHENTICATED_ANONYMOUSLY"/>       
    <intercept-url pattern="/dashboard*" access="ROLE_USER" />
    <form-login login-page="/login.html" default-target-url="/dashboard1.html#meetings"
        authentication-failure-url="/loginFailed.html" />
    <logout logout-success-url="/login.html" />
</http>

<beans:bean name="customAuthenticationProvider" class = "com.component.WebServiceUserDetailsAuthenticationProvider"/>

<authentication-manager>
  <authentication-provider ref = "customAuthenticationProvider"/>
</authentication-manager>

</beans:beans>  

现在我正在尝试实现记住我,但它强制我拥有我无法拥有的用户详细信息服务,因为我需要用户名和密码来验证我的 Web 服务和 userdetailservice 公开的方法只提供用户名不密码,这就是我必须首先使用 customAuthentication 的原因。

【问题讨论】:

  • 您实际上并没有说出您的问题是什么,因此您可能应该编辑您的问题以澄清。此外,您不需要扩展AbstractUserDetailsAuthenticationProvider。你可以直接实现AuthenticationProvider接口。
  • 嗨,卢克,我现在已经完成了我的问题。还有 AbstractUserDeta ..... 我之所以使用是因为我只想为方法 authenticate 提供实现,这就是 abstractUs.. 的用途。

标签: spring spring-security remember-me


【解决方案1】:

Remember-me 是另一种验证用户身份的方式,因此当它接收到 remember-me cookie 时,需要对其进行验证并加载信息以供用户将其提供给应用程序。为此,它使用UserDetailsService 接口。

基本实现TokenBasedRememberMeServices 需要访问密码才能验证令牌。如果你的系统不能提供,那么你就不能使用它。

替代方案是PersistentTokenBasedRememberMeServices,它使用数据库来存储remember-me 令牌。它不需要访问密码,但您仍然需要实现UserDetailsService 以允许它为经过身份验证的用户加载信息。它返回的UserDetails 对象不需要包含密码,但它应该至少包含用户名,以便您知道谁登录了。

【讨论】:

    猜你喜欢
    • 2017-08-10
    • 1970-01-01
    • 2013-01-25
    • 2015-07-27
    • 1970-01-01
    • 2016-08-31
    • 2012-12-17
    • 1970-01-01
    • 2018-07-25
    相关资源
    最近更新 更多