use of dev.samstevens.totp.qr.QrData in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManager method init.
@Override
@Transactional
public TwoFactorRegistrationResponseDto init(UUID identityId, TwoFactorAuthenticationType twoFactorAuthenticationType) {
Assert.notNull(identityId, "Identity identifier is required.");
IdmIdentityDto identity = identityService.get(identityId);
Assert.notNull(identity, "Identity is required.");
Assert.notNull(twoFactorAuthenticationType, "Two factor authentication method is required.");
//
String secret = secretGenerator.generate();
//
TwoFactorRegistrationResponseDto registration = new TwoFactorRegistrationResponseDto();
registration.setVerificationSecret(secret);
registration.setUsername(SpinalCase.format(identity.getUsername()));
// generate qr code
if (twoFactorAuthenticationType == TwoFactorAuthenticationType.APPLICATION) {
QrData qrcode = qrDataFactory.newBuilder().label(registration.getUsername()).secret(secret).issuer(// TODO: ApplicationConfiguration
"CzechIdM").build();
try {
byte[] imageData = qrGenerator.generate(qrcode);
String mimeType = qrGenerator.getImageMimeType();
registration.setQrcode(Utils.getDataUriForImage(imageData, mimeType));
} catch (Exception ex) {
throw new ResultCodeException(CoreResultCode.TWO_FACTOR_INIT_FAILED, ex);
}
} else {
// NOTIFICATION
sendVerificationCode(identity, generateCode(new GuardedString(secret)));
}
//
return registration;
}
Aggregations