Package tech.mgl.utils.security.gen
Class MGL_OtpProvider
java.lang.Object
tech.mgl.utils.security.gen.MGL_OtpProvider
- All Implemented Interfaces:
OtpSource
Class containing implementation of HOTP/TOTP. Generates OTP codes for one or
more accounts.
- Author:
- HOTPOT (hotpot@mgl.tech)
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault passcode timeout period (in seconds) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintenumerateAccounts(Collection<String> result) Enumerate list of accounts that this OTP token supports.getNextCode(String accountName, String key) Return the next OTP code for specified username.Gets the counter for generating or verifying TOTP codes.respondToChallenge(String accountName, String key, String challenge) Generate response to a given challenge based on next OTP code.
-
Field Details
-
DEFAULT_INTERVAL
public static final int DEFAULT_INTERVALDefault passcode timeout period (in seconds)- See Also:
-
-
Constructor Details
-
MGL_OtpProvider
public MGL_OtpProvider() -
MGL_OtpProvider
public MGL_OtpProvider(int interval)
-
-
Method Details
-
getNextCode
Description copied from interface:OtpSourceReturn the next OTP code for specified username. Invoking this function may change internal state of the OTP generator, for example advancing the counter.- Specified by:
getNextCodein interfaceOtpSource- Parameters:
accountName- Username, email address or other unique identifier for the account.- Returns:
- OTP as string code.
- Throws:
OtpSourceException
-
respondToChallenge
public String respondToChallenge(String accountName, String key, String challenge) throws OtpSourceException Description copied from interface:OtpSourceGenerate response to a given challenge based on next OTP code. Subclasses are not required to implement this method.- Specified by:
respondToChallengein interfaceOtpSource- Parameters:
accountName- Username, email address or other unique identifier for the account.challenge- Server specified challenge as UTF8 string.- Returns:
- Response to the challenge.
- Throws:
OtpSourceException
-
getTotpCounter
Description copied from interface:OtpSourceGets the counter for generating or verifying TOTP codes.- Specified by:
getTotpCounterin interfaceOtpSource
-
enumerateAccounts
Description copied from interface:OtpSourceEnumerate list of accounts that this OTP token supports.- Specified by:
enumerateAccountsin interfaceOtpSource- Parameters:
result- Collection to append usernames. This object is NOT cleared on entry; if there are existing items, they will not be removed.- Returns:
- Number of accounts added to the collection.
-