Package sk.iway.iwcm.system.googleauth
Class GoogleAuthenticator
java.lang.Object
sk.iway.iwcm.system.googleauth.GoogleAuthenticator
- All Implemented Interfaces:
IGoogleAuthenticator
GoogleAuthenticator.java
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks a verification code against a secret key using the current time.booleanChecks a verification code against a secret key using the specified time.booleanauthorizeUser(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.booleanauthorizeUser(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#createCredentialsmethod with no arguments.This method loads the first available ICredentialRepository registered using the Java service loader API.intgetTotpPassword(String secret) This method generates the current TOTP password.intgetTotpPassword(String secret, long time) This method generates the TOTP password at the specified time.intgetTotpPasswordOfUser(String userName) This method generates the current TOTP password.intgetTotpPasswordOfUser(String userName, long time) This method generates the TOTP password at the specified time.voidsetCredentialRepository(ICredentialRepository repository) This method sets the credential repository used by this instance.
-
Field Details
-
RNG_ALGORITHM
The system property to specify the random number generator algorithm to use.- Since:
- 0.5.0
- See Also:
-
RNG_ALGORITHM_PROVIDER
The system property to specify the random number generator provider to use.- Since:
- 0.5.0
- See Also:
-
SCRATCH_CODE_MODULUS
public static final int SCRATCH_CODE_MODULUSModulus used to truncate the scratch code.
-
-
Constructor Details
-
GoogleAuthenticator
public GoogleAuthenticator() -
GoogleAuthenticator
-
-
Method Details
-
createCredentials
Description copied from interface:IGoogleAuthenticatorThis method generates a new set of credentials including:- Secret key.
- Validation code.
- A list of scratch codes.
- Specified by:
createCredentialsin interfaceIGoogleAuthenticator- Returns:
- secret key
-
createCredentials
Description copied from interface:IGoogleAuthenticatorThis method generates a new set of credentials invoking the#createCredentialsmethod with no arguments. The generated credentials are then saved using the configured#ICredentialRepositoryservice. The user must register this secret on their device.- Specified by:
createCredentialsin interfaceIGoogleAuthenticator- Parameters:
userName- the user name.- Returns:
- secret key
-
getTotpPassword
Description copied from interface:IGoogleAuthenticatorThis method generates the current TOTP password.- Specified by:
getTotpPasswordin interfaceIGoogleAuthenticator- Parameters:
secret- the encoded secret key.- Returns:
- the current TOTP password.
-
getTotpPassword
Description copied from interface:IGoogleAuthenticatorThis method generates the TOTP password at the specified time.- Specified by:
getTotpPasswordin interfaceIGoogleAuthenticator- Parameters:
secret- The encoded secret key.time- The time to use to calculate the password.- Returns:
- the TOTP password at the specified time.
-
getTotpPasswordOfUser
Description copied from interface:IGoogleAuthenticatorThis method generates the current TOTP password.- Specified by:
getTotpPasswordOfUserin interfaceIGoogleAuthenticator- Parameters:
userName- The user whose password must be created.- Returns:
- the current TOTP password.
-
getTotpPasswordOfUser
Description copied from interface:IGoogleAuthenticatorThis method generates the TOTP password at the specified time.- Specified by:
getTotpPasswordOfUserin interfaceIGoogleAuthenticator- 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.
-
authorize
Description copied from interface:IGoogleAuthenticatorChecks a verification code against a secret key using the current time.- Specified by:
authorizein interfaceIGoogleAuthenticator- Parameters:
secret- the encoded secret key.verificationCode- the verification code.- Returns:
trueif the validation code is valid,falseotherwise.- 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
public boolean authorize(String secret, int verificationCode, long time) throws GoogleAuthenticatorException Description copied from interface:IGoogleAuthenticatorChecks a verification code against a secret key using the specified time. The algorithm also checks in a time window whose size determined by thewindowSizeproperty of this class. The default value of 30 seconds recommended by RFC 6238 is used for the interval size.- Specified by:
authorizein interfaceIGoogleAuthenticator- Parameters:
secret- The encoded secret key.verificationCode- The verification code.time- The time to use to calculate the TOTP password..- Returns:
trueif the validation code is valid,falseotherwise.- 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.
-
authorizeUser
public boolean authorizeUser(String userName, int verificationCode) throws GoogleAuthenticatorException Description copied from interface:IGoogleAuthenticatorThis 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 theIGoogleAuthenticator.authorizeUser(String, int, long).- Specified by:
authorizeUserin interfaceIGoogleAuthenticator- Parameters:
userName- The user whose verification code is to be validated.verificationCode- The validation code.- Returns:
trueif the validation code is valid,falseotherwise.- Throws:
GoogleAuthenticatorException- if an unexpected error occurs.- See Also:
-
authorizeUser
public boolean authorizeUser(String userName, int verificationCode, long time) throws GoogleAuthenticatorException Description copied from interface:IGoogleAuthenticatorThis 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 theIGoogleAuthenticator.authorize(String, int, long)method.- Specified by:
authorizeUserin interfaceIGoogleAuthenticator- 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:
trueif the validation code is valid,falseotherwise.- Throws:
GoogleAuthenticatorException- if an unexpected error occurs.- See Also:
-
getCredentialRepository
This method loads the first available ICredentialRepository registered using the Java service loader API.- Specified by:
getCredentialRepositoryin interfaceIGoogleAuthenticator- Returns:
- the first registered ICredentialRepository or
nullif none is found.
-
setCredentialRepository
Description copied from interface:IGoogleAuthenticatorThis method sets the credential repository used by this instance. Ifnullis passed to this method, no credential repository will be used, nor discovered using the ServiceLoader API.- Specified by:
setCredentialRepositoryin interfaceIGoogleAuthenticator- Parameters:
repository- The credential repository to use, ornullto disable this feature.
-