Interface PasswordEncoderService
- All Known Implementing Classes:
DefaulPasswordEncoderService,LDAPPasswordEncoderService
public interface PasswordEncoderService
The PasswordEncoderService encodes and decodes passwords for a given user. Based on the given
passwordEncoding the corresponding PasswordEncoder is used for the encoding/decoding. Use
getSupportedEncodings() to have a look which PasswordEncoders are supported.- Spring Bean ID:
- passwordEncoderService
-
Method Summary
Modifier and TypeMethodDescriptionTries to decodes from the givenuserthe encoded password based on the encoding set to the user.Encodes the givenplainTextPasswordwith the corresponding PasswordEncoder (based on thepasswordEncoding) and returns it.booleanisSupportedEncoding(String encoding) Checks if the given password encoding is supported.booleanChecks if the encoded password (stored in the user) matches the given plain text password.
-
Method Details
-
encode
String encode(UserModel user, String plainTextPassword, String passwordEncoding) throws PasswordEncoderNotFoundException Encodes the givenplainTextPasswordwith the corresponding PasswordEncoder (based on thepasswordEncoding) and returns it. Theusercan be used as 'salt' in the implementation of thePasswordEncoders- Parameters:
user- can be used as 'salt'. SeeMD5PasswordEncoderplainTextPassword- the plain passwordpasswordEncoding- based on this encoding the correct PasswordEncoder is used- Returns:
- the encoded password
- Throws:
PasswordEncoderNotFoundException- if for the given passwordEncoding no PasswordEncoder is known
-
decode
String decode(UserModel user) throws PasswordEncoderNotFoundException, CannotDecodePasswordException Tries to decodes from the givenuserthe encoded password based on the encoding set to the user.see
UserModel.getEncodedPassword()andUserModel.getPasswordEncoding()- Parameters:
user- contains the encoded password and the encoding- Returns:
- the password in plain text if possible
- Throws:
PasswordEncoderNotFoundException- if for the given passwordEncoding no PasswordEncoder is known in the systemCannotDecodePasswordException- if the encoded password cannot be decoded, see MD5PasswordEncoder
-
isSupportedEncoding
Checks if the given password encoding is supported.- Parameters:
encoding- the password encoding- Returns:
trueif the given encoding is supported,falseotherwise.- See Also:
-
getSupportedEncodings
Collection<String> getSupportedEncodings()- Returns:
- a collection with the supported encodings of this system.
-
isValid
Checks if the encoded password (stored in the user) matches the given plain text password. For this the plain password will be encoded and compared with the user's encoded password.- Parameters:
user- the user contains the encoded password and the (password) encodingplainPassword- the plain text password- Returns:
trueif the encoded passwords matches,falseotherwise
-