Interface IGoogleAuthenticator

All Known Implementing Classes:
GoogleAuthenticator

public interface IGoogleAuthenticator
Google Authenticator library interface.
  • Method Summary

    Modifier and Type Method Description
    boolean authorize​(String secret, int verificationCode)
    Checks a verification code against a secret key using the current time.
    boolean authorize​(String secret, int verificationCode, long time)
    Checks a verification code against a secret key using the specified time.
    boolean authorizeUser​(String userName, int verificationCode)
    This method validates a verification code of the specified user whose private key is retrieved from the configured credential repository using the current time.
    boolean authorizeUser​(String userName, int verificationCode, long time)
    This method validates a verification code of the specified user whose private key is retrieved from the configured credential repository.
    GoogleAuthenticatorKey createCredentials()
    This method generates a new set of credentials including: Secret key. Validation code. A list of scratch codes.
    GoogleAuthenticatorKey createCredentials​(String userName)
    This method generates a new set of credentials invoking the #createCredentials method with no arguments.
    ICredentialRepository getCredentialRepository()
    This method returns the credential repository used by this instance, or null if none is set or none can be found using the ServiceLoader API.
    int getTotpPassword​(String secret)
    This method generates the current TOTP password.
    int getTotpPassword​(String secret, long time)
    This method generates the TOTP password at the specified time.
    int getTotpPasswordOfUser​(String userName)
    This method generates the current TOTP password.
    int getTotpPasswordOfUser​(String userName, long time)
    This method generates the TOTP password at the specified time.
    void setCredentialRepository​(ICredentialRepository repository)
    This method sets the credential repository used by this instance.
  • Method Details

    • createCredentials

      GoogleAuthenticatorKey createCredentials()
      This method generates a new set of credentials including:
      1. Secret key.
      2. Validation code.
      3. A list of scratch codes.

      The user must register this secret on their device.

      Returns:
      secret key
    • createCredentials

      GoogleAuthenticatorKey createCredentials​(String userName)
      This method generates a new set of credentials invoking the #createCredentials method with no arguments. The generated credentials are then saved using the configured #ICredentialRepository service.

      The user must register this secret on their device.

      Parameters:
      userName - the user name.
      Returns:
      secret key
    • getTotpPassword

      int getTotpPassword​(String secret)
      This method generates the current TOTP password.
      Parameters:
      secret - the encoded secret key.
      Returns:
      the current TOTP password.
      Since:
      1.1.0
    • getTotpPassword

      int getTotpPassword​(String secret, long time)
      This method generates the TOTP password at the specified time.
      Parameters:
      secret - The encoded secret key.
      time - The time to use to calculate the password.
      Returns:
      the TOTP password at the specified time.
      Since:
      1.1.0
    • getTotpPasswordOfUser

      int getTotpPasswordOfUser​(String userName)
      This method generates the current TOTP password.
      Parameters:
      userName - The user whose password must be created.
      Returns:
      the current TOTP password.
      Since:
      1.1.0
    • getTotpPasswordOfUser

      int getTotpPasswordOfUser​(String userName, long time)
      This method generates the TOTP password at the specified time.
      Parameters:
      userName - The user whose password must be created.
      time - The time to use to calculate the password.
      Returns:
      the TOTP password at the specified time.
      Since:
      1.1.0
    • authorize

      boolean authorize​(String secret, int verificationCode)
      Checks a verification code against a secret key using the current time.
      Parameters:
      secret - the encoded secret key.
      verificationCode - the verification code.
      Returns:
      true if the validation code is valid, false otherwise.
      Throws:
      GoogleAuthenticatorException - if a failure occurs during the calculation of the validation code. The only failures that should occur are related with the cryptographic functions provided by the JCE.
      See Also:
      authorize(String, int, long)
    • authorize

      boolean authorize​(String secret, int verificationCode, long time)
      Checks a verification code against a secret key using the specified time. The algorithm also checks in a time window whose size determined by the windowSize property of this class.

      The default value of 30 seconds recommended by RFC 6238 is used for the interval size.

      Parameters:
      secret - The encoded secret key.
      verificationCode - The verification code.
      time - The time to use to calculate the TOTP password..
      Returns:
      true if the validation code is valid, false otherwise.
      Throws:
      GoogleAuthenticatorException - if a failure occurs during the calculation of the validation code. The only failures that should occur are related with the cryptographic functions provided by the JCE.
      Since:
      0.6.0
    • authorizeUser

      boolean authorizeUser​(String userName, int verificationCode)
      This method validates a verification code of the specified user whose private key is retrieved from the configured credential repository using the current time. This method delegates the validation to the authorizeUser(String, int, long).
      Parameters:
      userName - The user whose verification code is to be validated.
      verificationCode - The validation code.
      Returns:
      true if the validation code is valid, false otherwise.
      Throws:
      GoogleAuthenticatorException - if an unexpected error occurs.
      See Also:
      authorize(String, int)
    • authorizeUser

      boolean authorizeUser​(String userName, int verificationCode, long time)
      This method validates a verification code of the specified user whose private key is retrieved from the configured credential repository. This method delegates the validation to the authorize(String, int, long) method.
      Parameters:
      userName - The user whose verification code is to be validated.
      verificationCode - The validation code.
      time - The time to use to calculate the TOTP password.
      Returns:
      true if the validation code is valid, false otherwise.
      Throws:
      GoogleAuthenticatorException - if an unexpected error occurs.
      Since:
      0.6.0
      See Also:
      authorize(String, int)
    • getCredentialRepository

      ICredentialRepository getCredentialRepository()
      This method returns the credential repository used by this instance, or null if none is set or none can be found using the ServiceLoader API.
      Returns:
      the credential repository used by this instance.
      Since:
      1.0.0
    • setCredentialRepository

      void setCredentialRepository​(ICredentialRepository repository)
      This method sets the credential repository used by this instance. If null is passed to this method, no credential repository will be used, nor discovered using the ServiceLoader API.
      Parameters:
      repository - The credential repository to use, or null to disable this feature.
      Since:
      1.0.0