我想为我的应用程序实现记住我服务。我面临的主要问题是我正在使用自定义身份验证提供程序。它使用第三方应用程序进行身份验证。我无法直接访问他们的数据库。
我检查了这个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 码,并将其存储在您有权访问的数据库中,并实现一个 UserDetailsService
来加载该密码。
或者,您可以使用替代方案 "persistent token"实现,它将实际 token 存储在数据库中,而不是根据唯一的用户数据重建它。
关于java - Spring 通过自定义身份验证提供程序记住我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25403255/