Interface PasscodeService<P extends PasswordToken,U extends User>
- All Known Implementing Classes:
DefaultPasscodeService
public interface PasscodeService<P extends PasswordToken,U extends User>
This service provides methods for creating and consuming random passcodes.
- Author:
- Cade Rea (cade-rea)
-
Method Summary
Modifier and TypeMethodDescriptionConsume a passcode.createPasscode(U user, String purpose) Create a new token for a User with a specific purpose.Generate a new random token String with only letters and numbers.generateSecureToken(boolean includeSpecialCharacters) Generate a new random token String that may special characters.booleaninvalidate(String passcodeId) Invalidate an active passcode.readTokensForUser(U user, String purpose) Return all of a user's tokens for a particular purpose.booleanGet the status of aPasswordToken.
-
Method Details
-
createPasscode
Create a new token for a User with a specific purpose.- Parameters:
user- The User who will own the token.purpose- The purpose for this token.- Returns:
- A new
PasswordTokenobject with the new plaintext passcode on the token field.
-
consume
Consume a passcode.- Parameters:
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.- Returns:
- An optional containing the used token if successful, empty if unsuccessful.
-
status
Get the status of aPasswordToken.- Parameters:
passcodeId- The id of thePasswordToken.- Returns:
- True if the token is valid, false otherwise.
-
invalidate
Invalidate an active passcode.- Parameters:
passcodeId- The id of thePasswordToken.- Returns:
- True if the passcode was invalidated, false otherwise.
-
readTokensForUser
Return all of a user's tokens for a particular purpose. The token fields of the returned objects will contain the encoded passcode.- Parameters:
user- The User that owns the tokens.purpose- The purpose of the tokens.- Returns:
- A List of
PasswordToken.
-
generateSecureToken
String generateSecureToken()Generate a new random token String with only letters and numbers. This String is not persisted.- Returns:
- A secure random String.
-
generateSecureToken
Generate a new random token String that may special characters. The String is not persisted.- Parameters:
includeSpecialCharacters- True if special characters should be included in the token. If false, only letters and numbers will be used.- Returns:
- A secure random String.
-