use of password.pwm.svc.token.TokenType in project pwm by pwm-project.
the class UpdateProfileUtil method checkForTokenVerificationProgress.
static ProcessStatus checkForTokenVerificationProgress(final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean, final UpdateProfileProfile updateProfileProfile) throws PwmUnrecoverableException, ServletException, IOException {
final Map<String, TokenDestinationItem.Type> requiredTokenValidations = determineTokenValidationsRequired(pwmRequest, updateProfileBean, updateProfileProfile);
if (!requiredTokenValidations.isEmpty()) {
final Set<String> remainingValidations = new HashSet<>(requiredTokenValidations.keySet());
remainingValidations.removeAll(updateProfileBean.getCompletedTokenFields());
if (!remainingValidations.isEmpty()) {
if (StringUtil.isEmpty(updateProfileBean.getCurrentTokenField())) {
updateProfileBean.setCurrentTokenField(remainingValidations.iterator().next());
updateProfileBean.setTokenSent(false);
}
if (!updateProfileBean.isTokenSent()) {
final TokenDestinationItem tokenDestinationItem = tokenDestinationItemForCurrentValidation(pwmRequest, updateProfileBean, updateProfileProfile);
final TimeDuration tokenLifetime = tokenDestinationItem.getType() == TokenDestinationItem.Type.email ? updateProfileProfile.getTokenDurationEmail(pwmRequest.getConfig()) : updateProfileProfile.getTokenDurationSMS(pwmRequest.getConfig());
TokenUtil.initializeAndSendToken(pwmRequest, TokenUtil.TokenInitAndSendRequest.builder().userInfo(pwmRequest.getPwmSession().getUserInfo()).tokenDestinationItem(tokenDestinationItem).emailToSend(PwmSetting.EMAIL_UPDATEPROFILE_VERIFICATION).tokenType(TokenType.UPDATE).smsToSend(PwmSetting.SMS_UPDATE_PROFILE_TOKEN_TEXT).tokenLifetime(tokenLifetime).build());
updateProfileBean.setTokenSent(true);
}
forwardToEnterCode(pwmRequest, updateProfileProfile, updateProfileBean);
return ProcessStatus.Halt;
}
}
return ProcessStatus.Continue;
}
use of password.pwm.svc.token.TokenType in project pwm by pwm-project.
the class NewUserUtils method checkForTokenVerificationProgress.
static ProcessStatus checkForTokenVerificationProgress(final PwmRequest pwmRequest, final NewUserBean newUserBean, final NewUserProfile newUserProfile) throws PwmUnrecoverableException, ServletException, IOException {
final Map<String, TokenDestinationItem.Type> requiredTokenValidations = determineTokenValidationsRequired(pwmRequest, newUserBean, newUserProfile);
if (!requiredTokenValidations.isEmpty()) {
final Set<String> remainingValidations = new HashSet<>(requiredTokenValidations.keySet());
remainingValidations.removeAll(newUserBean.getCompletedTokenFields());
if (!remainingValidations.isEmpty()) {
if (StringUtil.isEmpty(newUserBean.getCurrentTokenField())) {
newUserBean.setCurrentTokenField(remainingValidations.iterator().next());
newUserBean.setTokenSent(false);
}
if (!newUserBean.isTokenSent()) {
final TokenDestinationItem tokenDestinationItem = tokenDestinationItemForCurrentValidation(pwmRequest, newUserBean, newUserProfile);
if (pwmRequest.getConfig().getTokenStorageMethod() == TokenStorageMethod.STORE_LDAP) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "cannot generate new user tokens when storage type is configured as STORE_LDAP." }));
}
final Map<String, String> tokenPayloadMap = NewUserFormUtils.toTokenPayload(pwmRequest, newUserBean);
final MacroMachine macroMachine = createMacroMachineForNewUser(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), newUserBean.getNewUserForm(), tokenDestinationItem);
final TimeDuration tokenLifetime = figureTokenLifetime(pwmRequest.getConfig(), newUserProfile, tokenDestinationItem);
TokenUtil.initializeAndSendToken(pwmRequest, TokenUtil.TokenInitAndSendRequest.builder().userInfo(null).tokenDestinationItem(tokenDestinationItem).emailToSend(PwmSetting.EMAIL_NEWUSER_VERIFICATION).tokenType(TokenType.NEWUSER).smsToSend(PwmSetting.SMS_NEWUSER_TOKEN_TEXT).inputTokenData(tokenPayloadMap).macroMachine(macroMachine).tokenLifetime(tokenLifetime).build());
newUserBean.setTokenSent(true);
}
NewUserServlet.forwardToEnterCode(pwmRequest, newUserProfile, newUserBean);
return ProcessStatus.Halt;
}
}
return ProcessStatus.Continue;
}
Aggregations