Class TOTPService
java.lang.Object
de.bytestore.hostinger.security.service.TOTPService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondev.samstevens.totp.qr.QrDatagenerateCode(User userIO) Generates a QR code for the given user and adds it to the QR data.String[]generateRecoveryCodes(User userIO, int amountIO) Generates recovery codes for a user.Generates a secret using the secret generator.getDataUriForImage(dev.samstevens.totp.qr.QrData codeIO) Retrieves the data URI for an image generated using the specifiedcodeIOobject.byte[]getImageSRC(dev.samstevens.totp.qr.QrData codeIO) Retrieves the image source data of a QR code generated using the specifiedcodeIOobject.Returns the MIME type of the image generated by theimageGenerator.String[]getRecoveryCodes(User userIO) Retrieves the recovery codes associated with a user.getUserByUsername(String usernameIO) Retrieves the user with the given username or email from the database.booleanhasRecoveryCode(User userIO, String codeIO) Checks if the given user has a recovery code.booleanChecks if the given user has Time-based One-Time Password (TOTP) authentication enabled.booleanChecks if a user has Time-based One-Time Password (TOTP) authentication enabled.voidonApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) Saves the user's information and secret for Time-based One-Time Password (TOTP) authentication.voidsaveRecoveryCodes(User userIO, String[] codesIO, TOTPStorage storageIO) Saves the recovery codes for a user.voidUpdates the verifier for Time-based One-Time Password (TOTP) authentication.booleanverifyRecoveryCode(User userIO, String codeIO) Verifies the recovery code provided by the user.booleanverifyTOTP(User userIO, Integer otpIO) Verifies the Time-based One-Time Password (TOTP) entered by the user.booleanverifyTOTP(User userIO, Integer otpIO, String secretIO) Verifies the Time-based One-Time Password (TOTP) entered by the user.
-
Constructor Details
-
TOTPService
public TOTPService(io.jmix.core.security.SystemAuthenticator systemAuthenticator)
-
-
Method Details
-
onApplicationStarted
@EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event) -
updateVerifier
public void updateVerifier()Updates the verifier for Time-based One-Time Password (TOTP) authentication.This method sets the time period and time period discrepancy of the TOTP verifier based on the configuration settings in the TOTPAppSetting class. It logs the changes made to the verifier.
- See Also:
-
TOTPAppSetting#setAllowedTimePeriodDiscrepancy(Integer)TOTPAppSetting#setPeriod(Integer)TOTPAppSetting#getAllowedTimePeriodDiscrepancy()TOTPAppSetting#getPeriod()
-
generateSecret
Generates a secret using the secret generator.- Returns:
- the generated secret.
-
generateCode
Generates a QR code for the given user and adds it to the QR data.- Parameters:
userIO- the user object for which the QR code is generated- Returns:
- the QR data object containing the generated QR code
- Throws:
TOTPMailUnset
-
getImageSRC
public byte[] getImageSRC(dev.samstevens.totp.qr.QrData codeIO) throws dev.samstevens.totp.exceptions.QrGenerationException Retrieves the image source data of a QR code generated using the specifiedcodeIOobject.- Parameters:
codeIO- the QR data object representing the QR code- Returns:
- the byte array containing the image source data
- Throws:
dev.samstevens.totp.exceptions.QrGenerationException- if there is an error in generating the QR code image
-
getDataUriForImage
public String getDataUriForImage(dev.samstevens.totp.qr.QrData codeIO) throws dev.samstevens.totp.exceptions.QrGenerationException Retrieves the data URI for an image generated using the specifiedcodeIOobject.- Parameters:
codeIO- the QR data object representing the QR code- Returns:
- the data URI for the image
- Throws:
dev.samstevens.totp.exceptions.QrGenerationException- if there is an error in generating the QR code image
-
getMimeType
Returns the MIME type of the image generated by theimageGenerator.- Returns:
- the MIME type of the image
-
verifyTOTP
Verifies the Time-based One-Time Password (TOTP) entered by the user.- Parameters:
userIO- the User object for which the TOTP is to be verifiedotpIO- the TOTP entered by the user- Returns:
- true if the TOTP is valid, false otherwise
-
verifyTOTP
Verifies the Time-based One-Time Password (TOTP) entered by the user.- Parameters:
userIO- the User object for which the TOTP is to be verifiedotpIO- the TOTP entered by the usersecretIO- the secret associated with the TOTP (optional, can be null)- Returns:
- true if the TOTP is valid, false otherwise
-
generateRecoveryCodes
Generates recovery codes for a user.- Parameters:
userIO- the User object for which recovery codes are generatedamountIO- the amount of recovery codes to generate- Returns:
- an array of generated recovery codes
-
saveRecoveryCodes
Saves the recovery codes for a user.- Parameters:
userIO- The User object representing the user for which recovery codes are saved.codesIO- An array of recovery codes to be saved.
-
verifyRecoveryCode
Verifies the recovery code provided by the user. This method checks if the recovery code is valid by comparing it with the recovery codes associated with the user.- Parameters:
userIO- the User object for which the recovery code is to be verifiedcodeIO- the recovery code provided by the user- Returns:
- true if the recovery code is valid and has been successfully redeemed, false otherwise
-
hasRecoveryCode
Checks if the given user has a recovery code.- Parameters:
userIO- the User object for which the recovery code is to be checkedcodeIO- the recovery code to check- Returns:
- true if the user has the recovery code, false otherwise
-
getRecoveryCodes
Retrieves the recovery codes associated with a user.- Parameters:
userIO- the User object for which the recovery codes are retrieved- Returns:
- an array of recovery codes
-
save
Saves the user's information and secret for Time-based One-Time Password (TOTP) authentication.- Parameters:
userIO- the User object representing the user's informationsecretIO- the QrData object containing the secret for TOTP authentication- Returns:
-
hasTOTP
Checks if a user has Time-based One-Time Password (TOTP) authentication enabled.- Parameters:
usernameIO- the username of the user to check for TOTP authentication- Returns:
- true if the user has TOTP enabled, false otherwise
-
hasTOTP
Checks if the given user has Time-based One-Time Password (TOTP) authentication enabled.- Parameters:
userIO- the User object to check for TOTP authentication- Returns:
- true if the user has TOTP enabled, false otherwise
-
getUserByUsername
Retrieves the user with the given username or email from the database.- Parameters:
usernameIO- the username or email of the user to retrieve- Returns:
- the User object representing the retrieved user, or null if no user is found
-