Search in sources :

Example 6 with NewUserBean

use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.

the class NewUserServlet method restValidateForm.

@ActionHandler(action = "validate")
private ProcessStatus restValidateForm(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final Locale locale = pwmRequest.getLocale();
    try {
        final NewUserBean newUserBean = getNewUserBean(pwmRequest);
        final NewUserForm newUserForm = NewUserFormUtils.readFromJsonRequest(pwmRequest, newUserBean);
        PasswordUtility.PasswordCheckInfo passwordCheckInfo = verifyForm(pwmRequest, newUserForm, true);
        if (passwordCheckInfo.isPassed() && passwordCheckInfo.getMatch() == PasswordUtility.PasswordCheckInfo.MatchStatus.MATCH) {
            passwordCheckInfo = new PasswordUtility.PasswordCheckInfo(Message.getLocalizedMessage(locale, Message.Success_NewUserForm, pwmApplication.getConfig()), passwordCheckInfo.isPassed(), passwordCheckInfo.getStrength(), passwordCheckInfo.getMatch(), passwordCheckInfo.getErrorCode());
        }
        final RestCheckPasswordServer.JsonOutput jsonData = RestCheckPasswordServer.JsonOutput.fromPasswordCheckInfo(passwordCheckInfo);
        final RestResultBean restResultBean = RestResultBean.withData(jsonData);
        pwmRequest.outputJsonResult(restResultBean);
    } catch (PwmOperationalException e) {
        final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
        LOGGER.debug(pwmRequest, "error while validating new user form: " + e.getMessage());
        pwmRequest.outputJsonResult(restResultBean);
    }
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) PasswordUtility(password.pwm.util.operations.PasswordUtility) RestCheckPasswordServer(password.pwm.ws.server.rest.RestCheckPasswordServer) NewUserBean(password.pwm.http.bean.NewUserBean) RestResultBean(password.pwm.ws.server.RestResultBean) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 7 with NewUserBean

use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.

the class NewUserServlet method restCheckProgress.

@ActionHandler(action = "checkProgress")
private ProcessStatus restCheckProgress(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final NewUserBean newUserBean = getNewUserBean(pwmRequest);
    final Instant startTime = newUserBean.getCreateStartTime();
    if (startTime == null) {
        pwmRequest.respondWithError(PwmError.ERROR_INCORRECT_REQ_SEQUENCE.toInfo(), true);
        return ProcessStatus.Halt;
    }
    final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
    final long minWaitTime = newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_MINIMUM_WAIT_TIME) * 1000L;
    final Instant completeTime = Instant.ofEpochMilli(startTime.toEpochMilli() + minWaitTime);
    final BigDecimal percentComplete;
    final boolean complete;
    // be sure minimum wait time has passed
    if (Instant.now().isAfter(completeTime)) {
        percentComplete = new BigDecimal("100");
        complete = true;
    } else {
        final TimeDuration elapsedTime = TimeDuration.fromCurrent(startTime);
        complete = false;
        percentComplete = new Percent(elapsedTime.getTotalMilliseconds(), minWaitTime).asBigDecimal();
    }
    final LinkedHashMap<String, Object> outputMap = new LinkedHashMap<>();
    outputMap.put("percentComplete", percentComplete);
    outputMap.put("complete", complete);
    final RestResultBean restResultBean = RestResultBean.withData(outputMap);
    LOGGER.trace(pwmRequest, "returning result for restCheckProgress: " + JsonUtil.serialize(restResultBean));
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : Percent(password.pwm.util.java.Percent) Instant(java.time.Instant) NewUserProfile(password.pwm.config.profile.NewUserProfile) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) TimeDuration(password.pwm.util.java.TimeDuration) NewUserBean(password.pwm.http.bean.NewUserBean) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 8 with NewUserBean

use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.

the class NewUserServlet method handleAgree.

@ActionHandler(action = "agree")
private ProcessStatus handleAgree(final PwmRequest pwmRequest) throws ServletException, IOException, PwmUnrecoverableException, ChaiUnavailableException {
    LOGGER.debug(pwmRequest, "user accepted new-user agreement");
    final NewUserBean newUserBean = getNewUserBean(pwmRequest);
    newUserBean.setAgreementPassed(true);
    return ProcessStatus.Continue;
}
Also used : NewUserBean(password.pwm.http.bean.NewUserBean)

Example 9 with NewUserBean

use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.

the class NewUserServlet method preProcessCheck.

@Override
public ProcessStatus preProcessCheck(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final Configuration config = pwmApplication.getConfig();
    if (!config.readSettingAsBoolean(PwmSetting.NEWUSER_ENABLE)) {
        throw new PwmUnrecoverableException(PwmError.ERROR_SERVICE_NOT_AVAILABLE);
    }
    final NewUserBean newUserBean = pwmApplication.getSessionStateService().getBean(pwmRequest, NewUserBean.class);
    final String signedFormData = pwmRequest.readParameterAsString(PwmConstants.PARAM_SIGNED_FORM, PwmHttpRequestWrapper.Flag.BypassValidation);
    if (!StringUtil.isEmpty(signedFormData)) {
        final Map<String, String> jsonForm = RestFormSigningServer.readSignedFormValue(pwmApplication, signedFormData);
        LOGGER.trace("detected signedForm parameter in request, will read and place in bean; keys=" + JsonUtil.serializeCollection(jsonForm.keySet()));
        newUserBean.setRemoteInputData(jsonForm);
    }
    // convert a url command like /public/newuser/profile/xxx to set profile.
    if (readProfileFromUrl(pwmRequest, newUserBean)) {
        return ProcessStatus.Halt;
    }
    final ProcessAction action = this.readProcessAction(pwmRequest);
    // convert a url command like /public/newuser/12321321 to redirect with a process action.
    if (action == null) {
        if (pwmRequest.convertURLtokenCommand(PwmServletDefinition.NewUser, NewUserAction.enterCode)) {
            return ProcessStatus.Halt;
        }
    } else if (action != NewUserAction.complete && action != NewUserAction.checkProgress) {
        if (pwmRequest.isAuthenticated()) {
            pwmRequest.respondWithError(PwmError.ERROR_USERAUTHENTICATED.toInfo());
            return ProcessStatus.Halt;
        }
    }
    return ProcessStatus.Continue;
}
Also used : PwmApplication(password.pwm.PwmApplication) FormConfiguration(password.pwm.config.value.data.FormConfiguration) Configuration(password.pwm.config.Configuration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) NewUserBean(password.pwm.http.bean.NewUserBean)

Example 10 with NewUserBean

use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.

the class NewUserUtils method remoteSendFormData.

private static void remoteSendFormData(final PwmRequest pwmRequest, final NewUserForm newUserForm, final FormDataRequestBean.Mode mode) throws PwmUnrecoverableException, PwmDataValidationException {
    final RestFormDataClient restFormDataClient = new RestFormDataClient(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel());
    if (!restFormDataClient.isEnabled()) {
        return;
    }
    final NewUserBean newUserBean = NewUserServlet.getNewUserBean(pwmRequest);
    final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
    final FormDataRequestBean.FormInfo formInfo = FormDataRequestBean.FormInfo.builder().mode(mode).moduleProfileID(newUserBean.getProfileID()).sessionID(pwmRequest.getPwmSession().getLoginInfoBean().getGuid()).module(FormDataRequestBean.FormType.NewUser).build();
    final FormDataRequestBean formDataRequestBean = FormDataRequestBean.builder().formInfo(formInfo).formConfigurations(newUserProfile.readSettingAsForm(PwmSetting.NEWUSER_FORM)).formValues(newUserForm.getFormData()).build();
    final FormDataResponseBean formDataResponseBean = restFormDataClient.invoke(formDataRequestBean, pwmRequest.getLocale());
    if (formDataResponseBean.isError()) {
        final ErrorInformation error = new ErrorInformation(PwmError.ERROR_REMOTE_ERROR_VALUE, formDataResponseBean.getErrorDetail(), new String[] { formDataResponseBean.getErrorMessage() });
        throw new PwmDataValidationException(error);
    }
}
Also used : FormDataResponseBean(password.pwm.ws.client.rest.form.FormDataResponseBean) ErrorInformation(password.pwm.error.ErrorInformation) PwmDataValidationException(password.pwm.error.PwmDataValidationException) RestFormDataClient(password.pwm.ws.client.rest.form.RestFormDataClient) FormDataRequestBean(password.pwm.ws.client.rest.form.FormDataRequestBean) NewUserBean(password.pwm.http.bean.NewUserBean) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Aggregations

NewUserBean (password.pwm.http.bean.NewUserBean)10 NewUserProfile (password.pwm.config.profile.NewUserProfile)5 ErrorInformation (password.pwm.error.ErrorInformation)4 PwmOperationalException (password.pwm.error.PwmOperationalException)4 PwmApplication (password.pwm.PwmApplication)3 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)3 Instant (java.time.Instant)2 LinkedHashMap (java.util.LinkedHashMap)2 PwmDataValidationException (password.pwm.error.PwmDataValidationException)2 PwmSession (password.pwm.http.PwmSession)2 MacroMachine (password.pwm.util.macro.MacroMachine)2 PasswordUtility (password.pwm.util.operations.PasswordUtility)2 RestResultBean (password.pwm.ws.server.RestResultBean)2 BigDecimal (java.math.BigDecimal)1 Locale (java.util.Locale)1 TokenDestinationItem (password.pwm.bean.TokenDestinationItem)1 Configuration (password.pwm.config.Configuration)1 FormConfiguration (password.pwm.config.value.data.FormConfiguration)1 TokenPayload (password.pwm.svc.token.TokenPayload)1 Percent (password.pwm.util.java.Percent)1