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 Details

    • createPasscode

      P createPasscode(U user, String purpose)
      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 PasswordToken object with the new plaintext passcode on the token field.
    • consume

      Optional<P> consume(U user, String purpose, String passcode)
      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

      boolean status(String passcodeId)
      Get the status of a PasswordToken.
      Parameters:
      passcodeId - The id of the PasswordToken.
      Returns:
      True if the token is valid, false otherwise.
    • invalidate

      boolean invalidate(String passcodeId)
      Invalidate an active passcode.
      Parameters:
      passcodeId - The id of the PasswordToken.
      Returns:
      True if the passcode was invalidated, false otherwise.
    • readTokensForUser

      List<P> readTokensForUser(U user, String purpose)
      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

      String generateSecureToken(boolean includeSpecialCharacters)
      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.