Search in sources :

Example 1 with TokenType

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;
}
Also used : TokenType(password.pwm.svc.token.TokenType) TimeDuration(password.pwm.util.java.TimeDuration) TokenDestinationItem(password.pwm.bean.TokenDestinationItem) HashSet(java.util.HashSet)

Example 2 with TokenType

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) TokenType(password.pwm.svc.token.TokenType) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) TimeDuration(password.pwm.util.java.TimeDuration) TokenDestinationItem(password.pwm.bean.TokenDestinationItem) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

HashSet (java.util.HashSet)2 TokenDestinationItem (password.pwm.bean.TokenDestinationItem)2 TokenType (password.pwm.svc.token.TokenType)2 TimeDuration (password.pwm.util.java.TimeDuration)2 LinkedHashSet (java.util.LinkedHashSet)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 MacroMachine (password.pwm.util.macro.MacroMachine)1