|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.atlassian.security.password.DefaultPasswordEncoder
public final class DefaultPasswordEncoder
Converts salt and encoded password bytes into a standard base64 encoding for storage. Strings are converted to and from bytes using the UTF-8 encoding. A prefix is added in braces (e.g. "{SHA}") to distinguish between different implementations.
It is strongly recommended that clients use the default implementation returned bygetDefaultInstance(), which uses PKCS5S2PasswordHashGenerator
with RandomSaltGenerator.
The storage format used by this class is "{" + identifier + "}" + encodedSaltAndHash,
where identifier and saltPlusHash are defined as follows:
identifier: the identifier string provided to the constructorencodedSaltAndHash: the result of new String(encodeBase64(saltAndHash), "UTF-8")encodeBase64: the result of encodeBase64(saltAndHash)saltAndHash: the result of ArrayUtils.add(salt, hash)salt: the result of SaltGenerator.generateSalt(int)hash: the result of passwordHashGenerator.generateHash(password.getBytes("UTF-8"), salt)getDefaultInstance().
The thread-safety of this encoder depends on the thread-safety of the hash and salt generators
used. The encoder returned by getDefaultInstance() is safe for use on multiple threads.
Base64.encodeBase64(byte[]),
PasswordHashGenerator,
SaltGenerator| Constructor Summary | |
|---|---|
DefaultPasswordEncoder(String identifier,
PasswordHashGenerator hashGenerator,
SaltGenerator saltGenerator)
Constructs a new encoder with specified identifier, hash generator and salt generator. |
|
| Method Summary | |
|---|---|
boolean |
canDecodePassword(String encodedPassword)
Returns true if the encodedPassword is in the right format for decoding and verification by this implementation, otherwise false. |
String |
encodePassword(String rawPassword)
Encodes a password and returns it as a String suitable for storage by the client. |
static PasswordEncoder |
getDefaultInstance()
Returns a new encoder with identifier "PKCS5S2" using PKCS5S2PasswordHashGenerator
as the hash generator and RandomSaltGenerator as the salt generator. |
boolean |
isValidPassword(String rawPassword,
String prefixedEncodedPassword)
Returns true if the rawPassword matches the stored password hash in encodedPassword, otherwise false. |
static PasswordEncoder |
newInstance(String identifier,
PasswordHashGenerator hashGenerator)
Returns a new encoder with specified identifier and hash generator, using RandomSaltGenerator
as the salt generator. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultPasswordEncoder(String identifier,
PasswordHashGenerator hashGenerator,
SaltGenerator saltGenerator)
| Method Detail |
|---|
public static PasswordEncoder getDefaultInstance()
PKCS5S2PasswordHashGenerator
as the hash generator and RandomSaltGenerator as the salt generator.
This instance is safe for use by multiple threads.
PKCS5S2PasswordHashGenerator,
RandomSaltGenerator
public static PasswordEncoder newInstance(String identifier,
PasswordHashGenerator hashGenerator)
RandomSaltGenerator
as the salt generator.
The thread-safety of this instance depends on the thread-safety of the hash generator implementation.
public final boolean canDecodePassword(String encodedPassword)
PasswordEncoder
canDecodePassword in interface PasswordEncoderencodedPassword - the stored password associated with this user
public final String encodePassword(String rawPassword)
throws IllegalArgumentException
PasswordEncoderPasswordEncoder.canDecodePassword(String) to be implemented easily.
encodePassword in interface PasswordEncoderrawPassword - the password provided by the user
IllegalArgumentException - if the rawPassword is null or empty
public final boolean isValidPassword(String rawPassword,
String prefixedEncodedPassword)
throws IllegalArgumentException
PasswordEncoderPasswordEncoder.encodePassword(String). If the encoded password
is not in a format which is handled by this encoder, this method will return false.
If multiple encodings are supported by an application, the client should call
PasswordEncoder.canDecodePassword(String) to check that the password was generated by
this encoder before calling this method.
isValidPassword in interface PasswordEncoderrawPassword - the raw password provided by the user for authenticationprefixedEncodedPassword - the stored password associated with the user
IllegalArgumentException - if either rawPassword or encodedPassword is null or empty
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||