java - Spring 通过自定义身份验证提供程序记住我

标签 java spring authentication spring-security

我想为我的应用程序实现记住我服务。我面临的主要问题是我正在使用自定义身份验证提供程序。它使用第三方应用程序进行身份验证。我无法直接访问他们的数据库。

我检查了这个Link它告诉 UserDetailService 的实现对于 userauthentixation 服务是必需的。不幸的是,就我而言,我无法做到这一点。

我检查了这个Link它还说您还可以实现 customRememberMeServices 。但我不确定这是如何做到的。它只是传递一个没有凭据的请求和响应。

由于我的理解有限; spring 将用户名和密码存储在 token 中

 base64(username + ":" + expirationTime + ":" +
         md5Hex(username + ":" + expirationTime + ":" password + ":" + key))

username:          As identifiable to the UserDetailsService
password:          That matches the one in the retrieved UserDetails
expirationTime:    The date and time when the remember-me token expires,
                   expressed in milliseconds
key:               A private key to prevent modification of the remember-me token

有什么办法可以从此 token 检索密码吗?如果不是,我还能怎样实现同样的目标?

最佳答案

没有。 token 是一种单向哈希。重点是密码用于创建 token ,稍后当用户再次连接时可以使用相同的数据进行验证。如果您无法从数据库读取密码,则无法直接使用此方法。您可以为每个用户创建一个伪造的随 secret 码,并将其存储在您有权访问的数据库中,并实现一个 UserDetailsS​​ervice 来加载该密码。

或者,您可以使用替代方案 "persistent token"实现,它将实际 token 存储在数据库中,而不是根据唯一的用户数据重建它。

关于java - Spring 通过自定义身份验证提供程序记住我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25403255/

相关文章:

java - Apache Derby : Column reference 'xx' is invalid, 或者是无效表达式的一部分。

java - Spring Data JPA 保存方法在 Java 8 功能图中的有效性

java - JDBC 存储过程调用

java - Hibernate Spring MVC 注入(inject) Autowiring 问题

java - 从 java.sql.Connection 实例化 JdbcTemplate

ios - WKWebView中的用户名/密码认证

facebook - 如何将 Facebook SDK 与 Nuxt.js 一起使用?

iphone - 如何通过 iPhone 对网站用户进行身份验证

java - 如何在同一方法中添加KeyPressed事件

java - 如何从 jframe 打开 jdialog