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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations