public class DefaultPasscodeService<P extends PasswordToken,U extends User,D extends com.broadleafcommerce.data.tracking.core.mapping.BusinessTypeAware & com.broadleafcommerce.data.tracking.core.mapping.ModelMapperMappable> extends Object implements PasscodeService<P,U>
| Constructor and Description |
|---|
DefaultPasscodeService(SimplePayloadMapper mapper,
PasswordTokenRepository<D> passwordTokenRepository,
org.springframework.security.crypto.password.PasswordEncoder passwordEncoder,
PasswordTokenProperties passwordTokenProperties) |
| Modifier and Type | Method and Description |
|---|---|
Optional<P> |
consume(U user,
String purpose,
String passcode)
Consume a passcode.
|
P |
createPasscode(U user,
String purpose)
Create a new token for a User with a specific purpose.
|
protected P |
createPasswordToken(U user,
String purpose,
String encodedToken)
Create a new
<P extends PasswordToken> from a User, purpose, and encoded token. |
protected Optional<P> |
findActiveUserToken(U user,
String purpose,
String token)
Find saved token for the given user & purpose that is not expired.
|
String |
generateSecureToken()
Generate a new random token String.
|
protected SimplePayloadMapper |
getMapper() |
protected org.springframework.security.crypto.password.PasswordEncoder |
getPasswordEncoder() |
protected PasswordTokenProperties |
getPasswordTokenProperties() |
protected PasswordTokenRepository<D> |
getPasswordTokenRepository() |
protected char[] |
getTokenChars() |
protected Duration |
getTokenDuration() |
protected int |
getTokenLength() |
boolean |
invalidate(String passcodeId)
Invalidate an active passcode.
|
protected boolean |
isTokenExpired(P token)
Determine if the given token is expired.
|
protected boolean |
markTokenAsUsed(P token)
Mark a token as used, set the used date, and save the token.
|
protected boolean |
matchesToken(String token,
P savedToken)
Determine if the given token String matches the saved token PasswordToken.
|
List<P> |
readTokensForUser(U user,
String purpose)
Return all of a user's tokens for a particular purpose.
|
protected List<P> |
readUnusedTokensForUser(U user,
String purpose)
Find all unused tokens for the given user and purpose.
|
boolean |
status(String passcodeId)
Get the status of a
PasswordToken. |
protected static final Random RANDOM
public DefaultPasscodeService(SimplePayloadMapper mapper, PasswordTokenRepository<D> passwordTokenRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, PasswordTokenProperties passwordTokenProperties)
public P createPasscode(U user, String purpose)
PasscodeServicecreatePasscode in interface PasscodeService<P extends PasswordToken,U extends User>user - The User who will own the token.purpose - The purpose for this token.PasswordToken object with the new plaintext passcode on the token
field.public Optional<P> consume(U user, String purpose, String passcode)
PasscodeServiceconsume in interface PasscodeService<P extends PasswordToken,U extends User>user - The User that owns the token.purpose - The purpose of the token. This will be validated against the purpose stored
with the token.passcode - The passcode String to consume.public boolean invalidate(String passcodeId)
PasscodeServiceinvalidate in interface PasscodeService<P extends PasswordToken,U extends User>passcodeId - The id of the PasswordToken.public boolean status(String passcodeId)
PasscodeServicePasswordToken.status in interface PasscodeService<P extends PasswordToken,U extends User>passcodeId - The id of the PasswordToken.public List<P> readTokensForUser(U user, String purpose)
PasscodeServicereadTokensForUser in interface PasscodeService<P extends PasswordToken,U extends User>user - The User that owns the tokens.purpose - The purpose of the tokens.PasswordToken.public String generateSecureToken()
PasscodeServicegenerateSecureToken in interface PasscodeService<P extends PasswordToken,U extends User>protected Optional<P> findActiveUserToken(U user, String purpose, String token)
user - The user that owns the tokenpurpose - The purpose of the tokentoken - The token to match<P extends PasswordToken>, or emptyprotected boolean matchesToken(String token, P savedToken)
token - The unencoded String to matchsavedToken - The saved token with the encoded valueprotected List<P> readUnusedTokensForUser(U user, String purpose)
user - The user that owns the tokenpurpose - The purpose of the token<P extends PasswordToken> for the given user and purposeprotected P createPasswordToken(U user, String purpose, String encodedToken)
<P extends PasswordToken> from a User, purpose, and encoded token.user - The user that will own the tokenpurpose - The purpose of the tokenencodedToken - The encoded token value<P extends PasswordToken>protected boolean isTokenExpired(P token)
PasswordTokenProperties.getTtl().token - The saved token to testprotected boolean markTokenAsUsed(P token)
token - The token to update.protected char[] getTokenChars()
protected int getTokenLength()
protected Duration getTokenDuration()
protected SimplePayloadMapper getMapper()
protected PasswordTokenRepository<D> getPasswordTokenRepository()
protected org.springframework.security.crypto.password.PasswordEncoder getPasswordEncoder()
protected PasswordTokenProperties getPasswordTokenProperties()
Copyright © 2021. All rights reserved.