use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.
the class NewUserServlet method nextStep.
@Override
protected void nextStep(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException {
final NewUserBean newUserBean = getNewUserBean(pwmRequest);
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
if (newUserBean.getProfileID() == null) {
final Set<String> newUserProfileIDs = pwmApplication.getConfig().getNewUserProfiles().keySet();
if (newUserProfileIDs.isEmpty()) {
pwmRequest.respondWithError(new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, "no new user profiles are defined"));
return;
}
final LinkedHashMap<String, String> visibleProfiles = new LinkedHashMap<>(NewUserUtils.figureDisplayableProfiles(pwmRequest));
if (visibleProfiles.size() == 1) {
final String singleID = newUserProfileIDs.iterator().next();
LOGGER.trace(pwmRequest, "only one new user profile is defined, auto-selecting profile " + singleID);
newUserBean.setProfileID(singleID);
} else {
LOGGER.trace(pwmRequest, "new user profile not yet selected, redirecting to choice page");
pwmRequest.setAttribute(PwmRequestAttribute.NewUser_VisibleProfiles, visibleProfiles);
pwmRequest.forwardToJsp(JspUrl.NEW_USER_PROFILE_CHOICE);
return;
}
}
final NewUserProfile newUserProfile = getNewUserProfile(pwmRequest);
if (newUserBean.getCreateStartTime() != null) {
forwardToWait(pwmRequest, newUserProfile);
return;
}
// try to read the new user policy to make sure it's readable, that way an exception is thrown here instead of by the jsp
newUserProfile.getNewUserPasswordPolicy(pwmApplication, pwmSession.getSessionStateBean().getLocale());
if (!newUserBean.isFormPassed()) {
if (showFormPage(newUserProfile)) {
forwardToFormPage(pwmRequest, newUserBean);
return;
} else {
NewUserFormUtils.injectRemoteValuesIntoForm(newUserBean, newUserProfile);
try {
verifyForm(pwmRequest, newUserBean.getNewUserForm(), false);
} catch (PwmDataValidationException e) {
throw new PwmUnrecoverableException(e.getErrorInformation());
}
newUserBean.setFormPassed(true);
}
}
if (NewUserUtils.checkForTokenVerificationProgress(pwmRequest, newUserBean, newUserProfile) == ProcessStatus.Halt) {
return;
}
final String newUserAgreementText = newUserProfile.readSettingAsLocalizedString(PwmSetting.NEWUSER_AGREEMENT_MESSAGE, pwmSession.getSessionStateBean().getLocale());
if (!StringUtil.isEmpty(newUserAgreementText)) {
if (!newUserBean.isAgreementPassed()) {
final MacroMachine macroMachine = NewUserUtils.createMacroMachineForNewUser(pwmApplication, pwmRequest.getSessionLabel(), newUserBean.getNewUserForm(), null);
final String expandedText = macroMachine.expandMacros(newUserAgreementText);
pwmRequest.setAttribute(PwmRequestAttribute.AgreementText, expandedText);
pwmRequest.forwardToJsp(JspUrl.NEW_USER_AGREEMENT);
return;
}
}
// success so create the new user.
final String newUserDN = NewUserUtils.determineUserDN(pwmRequest, newUserBean.getNewUserForm());
try {
NewUserUtils.createUser(newUserBean.getNewUserForm(), pwmRequest, newUserDN);
newUserBean.setCreateStartTime(Instant.now());
forwardToWait(pwmRequest, newUserProfile);
} catch (PwmOperationalException e) {
LOGGER.error(pwmRequest, "error during user creation: " + e.getMessage());
if (newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_DELETE_ON_FAIL)) {
NewUserUtils.deleteUserAccount(newUserDN, pwmRequest);
}
LOGGER.error(pwmSession, e.getErrorInformation().toDebugStr());
pwmRequest.respondWithError(e.getErrorInformation());
}
}
use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.
the class NewUserServlet method handleEnterCodeRequest.
@ActionHandler(action = "enterCode")
private ProcessStatus handleEnterCodeRequest(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException, ChaiUnavailableException {
final PwmSession pwmSession = pwmRequest.getPwmSession();
final NewUserBean newUserBean = getNewUserBean(pwmRequest);
final NewUserProfile newUserProfile = getNewUserProfile(pwmRequest);
final String userEnteredCode = pwmRequest.readParameterAsString(PwmConstants.PARAM_TOKEN);
final TokenDestinationItem tokenDestinationItem = NewUserUtils.tokenDestinationItemForCurrentValidation(pwmRequest, newUserBean, newUserProfile);
ErrorInformation errorInformation = null;
TokenPayload tokenPayload = null;
try {
tokenPayload = TokenUtil.checkEnteredCode(pwmRequest, userEnteredCode, tokenDestinationItem, null, TokenType.NEWUSER, TokenService.TokenEntryType.unauthenticated);
} catch (PwmUnrecoverableException e) {
LOGGER.debug(pwmRequest, "error while checking entered token: ");
errorInformation = e.getErrorInformation();
}
if (tokenPayload != null) {
try {
final NewUserTokenData newUserTokenData = NewUserFormUtils.fromTokenPayload(pwmRequest, tokenPayload);
newUserBean.setProfileID(newUserTokenData.getProfileID());
final NewUserForm newUserFormFromToken = newUserTokenData.getFormData();
final TokenDestinationItem.Type tokenType = tokenPayload.getDestination().getType();
if (tokenType == TokenDestinationItem.Type.email) {
try {
verifyForm(pwmRequest, newUserFormFromToken, false);
newUserBean.setRemoteInputData(newUserTokenData.getInjectionData());
newUserBean.setNewUserForm(newUserFormFromToken);
newUserBean.setProfileID(newUserTokenData.getProfileID());
newUserBean.setFormPassed(true);
newUserBean.getCompletedTokenFields().addAll(newUserTokenData.getCompletedTokenFields());
newUserBean.setCurrentTokenField(newUserTokenData.getCurrentTokenField());
} catch (PwmUnrecoverableException | PwmOperationalException e) {
LOGGER.error(pwmRequest, "while reading stored form data in token payload, form validation error occurred: " + e.getMessage());
errorInformation = e.getErrorInformation();
}
} else if (tokenType == TokenDestinationItem.Type.sms) {
if (newUserBean.getNewUserForm() == null || !newUserBean.getNewUserForm().isConsistentWith(newUserFormFromToken)) {
LOGGER.debug(pwmRequest, "token value is valid, but form data does not match current session form data");
final String errorMsg = "sms token does not match current session";
errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT, errorMsg);
}
}
} catch (PwmOperationalException e) {
errorInformation = e.getErrorInformation();
}
}
if (errorInformation != null) {
LOGGER.debug(pwmSession, errorInformation.toDebugStr());
setLastError(pwmRequest, errorInformation);
return ProcessStatus.Continue;
}
LOGGER.debug(pwmRequest, "marking token as passed " + JsonUtil.serialize(tokenDestinationItem));
newUserBean.getCompletedTokenFields().add(newUserBean.getCurrentTokenField());
newUserBean.setTokenSent(false);
newUserBean.setCurrentTokenField(null);
if (pwmRequest.getConfig().readSettingAsBoolean(PwmSetting.DISPLAY_TOKEN_SUCCESS_BUTTON)) {
pwmRequest.setAttribute(PwmRequestAttribute.TokenDestItems, tokenPayload.getDestination());
pwmRequest.forwardToJsp(JspUrl.NEW_USER_TOKEN_SUCCESS);
return ProcessStatus.Halt;
}
return ProcessStatus.Continue;
}
use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.
the class NewUserServlet method handleComplete.
@ActionHandler(action = "complete")
private ProcessStatus handleComplete(final PwmRequest pwmRequest) throws ServletException, IOException, PwmUnrecoverableException, ChaiUnavailableException {
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);
// be sure minimum wait time has passed
if (Instant.now().isBefore(completeTime)) {
pwmRequest.forwardToJsp(JspUrl.NEW_USER_WAIT);
return ProcessStatus.Halt;
}
// -- process complete -- \\
pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, NewUserBean.class);
final String configuredRedirectUrl = newUserProfile.readSettingAsString(PwmSetting.NEWUSER_REDIRECT_URL);
if (!StringUtil.isEmpty(configuredRedirectUrl) && StringUtil.isEmpty(pwmRequest.getPwmSession().getSessionStateBean().getForwardURL())) {
final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
final String macroedUrl = macroMachine.expandMacros(configuredRedirectUrl);
pwmRequest.sendRedirect(macroedUrl);
return ProcessStatus.Halt;
}
pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_CreateUser);
return ProcessStatus.Halt;
}
use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.
the class NewUserServlet method handleProcessFormRequest.
@ActionHandler(action = "processForm")
private ProcessStatus handleProcessFormRequest(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException, IOException, ServletException {
final NewUserBean newUserBean = getNewUserBean(pwmRequest);
if (CaptchaUtility.captchaEnabledForRequest(pwmRequest)) {
if (!CaptchaUtility.verifyReCaptcha(pwmRequest)) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_BAD_CAPTCHA_RESPONSE);
LOGGER.debug(pwmRequest, errorInfo);
setLastError(pwmRequest, errorInfo);
forwardToFormPage(pwmRequest, newUserBean);
return ProcessStatus.Halt;
}
}
newUserBean.setFormPassed(false);
newUserBean.setNewUserForm(null);
try {
final NewUserForm newUserForm = NewUserFormUtils.readFromRequest(pwmRequest, newUserBean);
final PasswordUtility.PasswordCheckInfo passwordCheckInfo = verifyForm(pwmRequest, newUserForm, true);
NewUserUtils.passwordCheckInfoToException(passwordCheckInfo);
newUserBean.setNewUserForm(newUserForm);
newUserBean.setFormPassed(true);
} catch (PwmOperationalException e) {
setLastError(pwmRequest, e.getErrorInformation());
forwardToFormPage(pwmRequest, newUserBean);
return ProcessStatus.Halt;
}
return ProcessStatus.Continue;
}
use of password.pwm.http.bean.NewUserBean in project pwm by pwm-project.
the class NewUserServlet method handleProfileChoiceRequest.
@ActionHandler(action = "profileChoice")
private ProcessStatus handleProfileChoiceRequest(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException, IOException, ServletException {
final Set<String> profileIDs = pwmRequest.getConfig().getNewUserProfiles().keySet();
final String requestedProfileID = pwmRequest.readParameterAsString("profile");
final NewUserBean newUserBean = getNewUserBean(pwmRequest);
if (requestedProfileID == null || requestedProfileID.isEmpty()) {
newUserBean.setProfileID(null);
}
if (profileIDs.contains(requestedProfileID)) {
newUserBean.setProfileID(requestedProfileID);
}
return ProcessStatus.Continue;
}
Aggregations