java - 在 Spring Security 中实现 UserDetails 和 CredentialsContainer

标签 java spring spring-security

我想在登录后删除用户的凭据,因此我在我的 Account 类中实现 UserDetails 和 CredentialsContainer。

@Entity
public class Account implements UserDetails, CredentialsContainer {
...

但是,在文档中它说 CredentialsContainer 仅供内部框架使用

所以我想知道这是否会成为 future 的问题。

最佳答案

您可以实现该接口(interface)。但是,如果您正在编写自己的 AuthenticationProvider,则不打算实现它。来自javadoc:

For internal framework use only. Users who are writing their own AuthenticationProvider implementations should create and return an appropriate Authentication object there, minus any sensitive data, rather than using this interface.

因此,您可以实现它,以便 Spring Security 将在您的应用程序上调用eraseCredentials。但是,不建议您在CredentialsContainer上调用eraseCredentials。

关于java - 在 Spring Security 中实现 UserDetails 和 CredentialsContainer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31921460/

相关文章:

spring - grails - 获取全局当前用户

spring - 默认 Spring Security 重定向到 favicon

Grails Spring Security 使用 https 重定向到登录页面

java - 将 Jboss 插件更新到 eclipse 时无法访问 Marketplace

java - 在 Android 客户端应用程序中混淆 URL

java - 在 Java 中,将变量直接分配给包装类是一个好的做法吗?

java - Spring - 查找@Scheduled的执行时间

java - JSF 2 viewScope bean 瞬时注入(inject) Spring 服务 bean

java - 如何从android中的.txt文件中获取字符串

java - spring 调度程序没有加载我的组件