Package sk.iway.iwcm.system.googleauth
Interface IGoogleAuthenticator
- All Known Implementing Classes:
GoogleAuthenticator
public interface IGoogleAuthenticator
Google Authenticator library interface.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks a verification code against a secret key using the current time.boolean
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.This method generates a new set of credentials including: Secret key. Validation code. A list of scratch codes.createCredentials
(String userName) This method generates a new set of credentials invoking the#createCredentials
method with no arguments.This method returns the credential repository used by this instance, ornull
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:- Secret key.
- Validation code.
- A list of scratch codes.
- Returns:
- secret key
-
createCredentials
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
This method generates the current TOTP password.- Parameters:
secret
- the encoded secret key.- Returns:
- the current TOTP password.
- Since:
- 1.1.0
-
getTotpPassword
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
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
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
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
boolean authorize(String secret, int verificationCode, long time) throws GoogleAuthenticatorException Checks a verification code against a secret key using the specified time. The algorithm also checks in a time window whose size determined by thewindowSize
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
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 theauthorizeUser(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:
-
authorizeUser
boolean authorizeUser(String userName, int verificationCode, long time) throws GoogleAuthenticatorException 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 theauthorize(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:
-
getCredentialRepository
ICredentialRepository getCredentialRepository()This method returns the credential repository used by this instance, ornull
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
This method sets the credential repository used by this instance. Ifnull
is passed to this method, no credential repository will be used, nor discovered using the ServiceLoader API.- Parameters:
repository
- The credential repository to use, ornull
to disable this feature.- Since:
- 1.0.0
-