|
|
@ -117,7 +117,8 @@ public class OTPManagementServiceImpl implements OTPManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException {
|
|
|
|
public OneTimePinDTO isValidOTP(String oneTimeToken, boolean requireRenewal) throws OTPManagementException,
|
|
|
|
|
|
|
|
BadRequestException {
|
|
|
|
if (StringUtils.isBlank(oneTimeToken)){
|
|
|
|
if (StringUtils.isBlank(oneTimeToken)){
|
|
|
|
String msg = "Received blank OTP to verify. OTP: " + oneTimeToken;
|
|
|
|
String msg = "Received blank OTP to verify. OTP: " + oneTimeToken;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -141,17 +142,19 @@ public class OTPManagementServiceImpl implements OTPManagementService {
|
|
|
|
oneTimePinDTO.getCreatedAt().getTime() + oneTimePinDTO.getExpiryTime() * 1000L);
|
|
|
|
oneTimePinDTO.getCreatedAt().getTime() + oneTimePinDTO.getExpiryTime() * 1000L);
|
|
|
|
|
|
|
|
|
|
|
|
if (currentTimestamp.after(expiredTimestamp)) {
|
|
|
|
if (currentTimestamp.after(expiredTimestamp)) {
|
|
|
|
String renewedOTP = UUID.randomUUID().toString();
|
|
|
|
if (requireRenewal) {
|
|
|
|
renewOTP(oneTimePinDTO, renewedOTP);
|
|
|
|
String renewedOTP = UUID.randomUUID().toString();
|
|
|
|
Gson gson = new Gson();
|
|
|
|
renewOTP(oneTimePinDTO, renewedOTP);
|
|
|
|
Tenant tenant = gson.fromJson(oneTimePinDTO.getMetaInfo(), Tenant.class);
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
Tenant tenant = gson.fromJson(oneTimePinDTO.getMetaInfo(), Tenant.class);
|
|
|
|
|
|
|
|
|
|
|
|
Properties props = new Properties();
|
|
|
|
Properties props = new Properties();
|
|
|
|
props.setProperty("first-name", tenant.getAdminFirstName());
|
|
|
|
props.setProperty("first-name", tenant.getAdminFirstName());
|
|
|
|
props.setProperty("otp-token", renewedOTP);
|
|
|
|
props.setProperty("otp-token", renewedOTP);
|
|
|
|
props.setProperty("email", oneTimePinDTO.getEmail());
|
|
|
|
props.setProperty("email", oneTimePinDTO.getEmail());
|
|
|
|
props.setProperty("type", oneTimePinDTO.getEmailType());
|
|
|
|
props.setProperty("type", oneTimePinDTO.getEmailType());
|
|
|
|
sendMail(props, oneTimePinDTO.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE);
|
|
|
|
sendMail(props, oneTimePinDTO.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE);
|
|
|
|
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return oneTimePinDTO;
|
|
|
|
return oneTimePinDTO;
|
|
|
@ -234,8 +237,14 @@ public class OTPManagementServiceImpl implements OTPManagementService {
|
|
|
|
for (String username : deviceEnrollmentInvitation.getUsernames()) {
|
|
|
|
for (String username : deviceEnrollmentInvitation.getUsernames()) {
|
|
|
|
String emailAddress = DeviceManagerUtil.getUserClaimValue(
|
|
|
|
String emailAddress = DeviceManagerUtil.getUserClaimValue(
|
|
|
|
username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS);
|
|
|
|
username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS);
|
|
|
|
oneTimePinDTO = generateOneTimePin(emailAddress, OTPEmailTypes.DEVICE_ENROLLMENT.toString(), username,
|
|
|
|
|
|
|
|
null, tenantId, false);
|
|
|
|
OneTimePinDTO oneTimePinData = new OneTimePinDTO();
|
|
|
|
|
|
|
|
oneTimePinData.setEmail(emailAddress);
|
|
|
|
|
|
|
|
oneTimePinData.setTenantId(tenantId);
|
|
|
|
|
|
|
|
oneTimePinData.setUsername(username);
|
|
|
|
|
|
|
|
oneTimePinData.setEmailType(OTPEmailTypes.USER_INVITE.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
oneTimePinDTO = generateOneTimePin(oneTimePinData, false);
|
|
|
|
oneTimePinDTOList.add(oneTimePinDTO);
|
|
|
|
oneTimePinDTOList.add(oneTimePinDTO);
|
|
|
|
props.setProperty("first-name", DeviceManagerUtil.
|
|
|
|
props.setProperty("first-name", DeviceManagerUtil.
|
|
|
|
getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME));
|
|
|
|
getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME));
|
|
|
@ -269,27 +278,17 @@ public class OTPManagementServiceImpl implements OTPManagementService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create One Time Token
|
|
|
|
* Create One Time Token
|
|
|
|
* @param email email
|
|
|
|
* @param oneTimePinDTO Data related to the one time pin
|
|
|
|
* @param emailType email type
|
|
|
|
|
|
|
|
* @param userName username
|
|
|
|
|
|
|
|
* @param metaDataObj meta data object
|
|
|
|
|
|
|
|
* @param tenantId tenant Id
|
|
|
|
|
|
|
|
* @return {@link OneTimePinDTO}
|
|
|
|
* @return {@link OneTimePinDTO}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public OneTimePinDTO generateOneTimePin(String email, String emailType, String userName, Object metaDataObj,
|
|
|
|
public OneTimePinDTO generateOneTimePin(OneTimePinDTO oneTimePinDTO, boolean persistPin) throws OTPManagementException {
|
|
|
|
int tenantId, boolean persistPin) throws OTPManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String otpValue = UUID.randomUUID().toString();
|
|
|
|
String otpValue = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
Gson gson = new Gson();
|
|
|
|
String metaInfo = gson.toJson(metaDataObj);
|
|
|
|
String metaInfo = gson.toJson(oneTimePinDTO.getMetaInfo());
|
|
|
|
|
|
|
|
|
|
|
|
OneTimePinDTO oneTimePinDTO = new OneTimePinDTO();
|
|
|
|
|
|
|
|
oneTimePinDTO.setEmail(email);
|
|
|
|
|
|
|
|
oneTimePinDTO.setTenantId(tenantId);
|
|
|
|
|
|
|
|
oneTimePinDTO.setUsername(userName);
|
|
|
|
|
|
|
|
oneTimePinDTO.setEmailType(emailType);
|
|
|
|
|
|
|
|
oneTimePinDTO.setMetaInfo(metaInfo);
|
|
|
|
oneTimePinDTO.setMetaInfo(metaInfo);
|
|
|
|
oneTimePinDTO.setOtpToken(otpValue);
|
|
|
|
oneTimePinDTO.setOtpToken(otpValue);
|
|
|
|
|
|
|
|
|
|
|
|