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 Detail

      • 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. This String is not persisted.
        Returns:
        a secure random String.