简体   繁体   中英

Implementing UserDetails and CredentialsContainer in Spring Security

I want to erase the user's credentials after login, so i'm implementing UserDetails and CredentialsContainer in my Account class.

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

However, in the docs it says that CredentialsContainer is For internal framework use only .

So I was wondering if this can be a problem in the future.

You can implement the interface. However, it isn't intended to be implemented if you are writing your own AuthenticationProvider. From the 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.

So you can implement it so that Spring Security will call eraseCredentials on your app. However, it is not recommended for you to invoke eraseCredentials on the CredentialsContainer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM