Package tv.hd3g.authkit.mod.service
Class TOTPServiceImpl
- java.lang.Object
-
- tv.hd3g.authkit.mod.service.TOTPServiceImpl
-
- All Implemented Interfaces:
TOTPService
@Service public class TOTPServiceImpl extends Object implements TOTPService
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.commons.codec.binary.Base32base32
-
Constructor Summary
Constructors Constructor Description TOTPServiceImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckCode(Credential credential, String stringCode)voidcheckCodeAndPassword(Credential credential, ValidationTOTPDto validationDto)List<String>makeBackupCodes()static StringmakeCodeAtTime(byte[] secret, long timeMillis, int timeStepSeconds)See https://github.com/j256/two-factor-auth/blob/master/src/main/java/com/j256/twofactorauth/TimeBasedOneTimePasswordUtil.javaStringmakeQRCode(URI url)StringmakeSecret()URImakeURI(String secret, User user, String totpDomain)voidremoveTOTP(Credential credential)voidsetupTOTP(String base32Secret, Collection<String> backupCodes, String userUUID)voidsetupTOTPWithChecks(ValidationSetupTOTPDto setupDto, String expectedUserUUID)
-
-
-
Method Detail
-
makeSecret
public String makeSecret()
- Specified by:
makeSecretin interfaceTOTPService- Returns:
- base32 coded
-
makeURI
public URI makeURI(String secret, User user, String totpDomain)
- Specified by:
makeURIin interfaceTOTPService
-
makeQRCode
public String makeQRCode(URI url)
- Specified by:
makeQRCodein interfaceTOTPService- Returns:
- base64 coded
-
makeBackupCodes
public List<String> makeBackupCodes()
- Specified by:
makeBackupCodesin interfaceTOTPService
-
setupTOTP
@Transactional(readOnly=false) public void setupTOTP(String base32Secret, Collection<String> backupCodes, String userUUID)
- Specified by:
setupTOTPin interfaceTOTPService
-
setupTOTPWithChecks
@Transactional(readOnly=false) public void setupTOTPWithChecks(ValidationSetupTOTPDto setupDto, String expectedUserUUID)
- Specified by:
setupTOTPWithChecksin interfaceTOTPService
-
checkCodeAndPassword
@Transactional(readOnly=true) public void checkCodeAndPassword(Credential credential, ValidationTOTPDto validationDto)
- Specified by:
checkCodeAndPasswordin interfaceTOTPService
-
checkCode
@Transactional(readOnly=false) public void checkCode(Credential credential, String stringCode) throws UserCantLoginException.BadTOTPCodeCantLoginException
- Specified by:
checkCodein interfaceTOTPService- Throws:
UserCantLoginException.BadTOTPCodeCantLoginException
-
removeTOTP
@Transactional(readOnly=false) public void removeTOTP(Credential credential)
- Specified by:
removeTOTPin interfaceTOTPService
-
makeCodeAtTime
public static String makeCodeAtTime(byte[] secret, long timeMillis, int timeStepSeconds) throws GeneralSecurityException
See https://github.com/j256/two-factor-auth/blob/master/src/main/java/com/j256/twofactorauth/TimeBasedOneTimePasswordUtil.java- Throws:
GeneralSecurityException
-
-