use of password.pwm.config.profile.NewUserProfile in project pwm by pwm-project.
the class TokenService method healthCheck.
public List<HealthRecord> healthCheck() {
final List<HealthRecord> returnRecords = new ArrayList<>();
if (tokensAreUsedInConfig(configuration)) {
if (errorInformation != null) {
returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, errorInformation.toDebugStr()));
}
}
if (storageMethod == TokenStorageMethod.STORE_LDAP) {
if (configuration.readSettingAsBoolean(PwmSetting.NEWUSER_ENABLE)) {
for (final NewUserProfile newUserProfile : configuration.getNewUserProfiles().values()) {
if (newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_EMAIL_VERIFICATION)) {
final String label = PwmSetting.NEWUSER_EMAIL_VERIFICATION.toMenuLocationDebug(newUserProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE);
final String label2 = PwmSetting.TOKEN_STORAGEMETHOD.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE);
returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, label, label2));
}
if (newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_SMS_VERIFICATION)) {
final String label = PwmSetting.NEWUSER_SMS_VERIFICATION.toMenuLocationDebug(newUserProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE);
final String label2 = PwmSetting.TOKEN_STORAGEMETHOD.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE);
returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, label, label2));
}
}
}
}
return returnRecords;
}
use of password.pwm.config.profile.NewUserProfile in project pwm by pwm-project.
the class NewUserServlet method forwardToFormPage.
private void forwardToFormPage(final PwmRequest pwmRequest, final NewUserBean newUserBean) throws ServletException, PwmUnrecoverableException, IOException {
final List<FormConfiguration> formConfigurations = getFormDefinition(pwmRequest);
final NewUserProfile newUserProfile = getNewUserProfile(pwmRequest);
final boolean promptForPassword = newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_PROMPT_FOR_PASSWORD);
final Map<FormConfiguration, String> formData = new HashMap<>();
if (newUserBean.getRemoteInputData() != null) {
final Map<String, String> remoteData = newUserBean.getRemoteInputData();
for (final FormConfiguration formConfiguration : formConfigurations) {
if (remoteData.containsKey(formConfiguration.getName())) {
formData.put(formConfiguration, remoteData.get(formConfiguration.getName()));
}
}
}
pwmRequest.addFormInfoToRequestAttr(formConfigurations, formData, false, promptForPassword);
{
final boolean showBack = !newUserBean.isUrlSpecifiedProfile() && pwmRequest.getConfig().getNewUserProfiles().keySet().size() > 1;
pwmRequest.setAttribute(PwmRequestAttribute.NewUser_FormShowBackButton, showBack);
}
pwmRequest.forwardToJsp(JspUrl.NEW_USER);
}
use of password.pwm.config.profile.NewUserProfile 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.config.profile.NewUserProfile 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);
}
}
use of password.pwm.config.profile.NewUserProfile in project pwm by pwm-project.
the class NewUserUtils method determineUserDN.
static String determineUserDN(final PwmRequest pwmRequest, final NewUserForm formValues) throws PwmUnrecoverableException, ChaiUnavailableException {
final MacroMachine macroMachine = createMacroMachineForNewUser(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), formValues, null);
final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
final List<String> configuredNames = newUserProfile.readSettingAsStringArray(PwmSetting.NEWUSER_USERNAME_DEFINITION);
final List<String> failedValues = new ArrayList<>();
final String configuredContext = newUserProfile.readSettingAsString(PwmSetting.NEWUSER_CONTEXT);
final String expandedContext = macroMachine.expandMacros(configuredContext);
if (configuredNames == null || configuredNames.isEmpty() || configuredNames.iterator().next().isEmpty()) {
final String namingAttribute = pwmRequest.getConfig().getDefaultLdapProfile().readSettingAsString(PwmSetting.LDAP_NAMING_ATTRIBUTE);
String namingValue = null;
for (final String formKey : formValues.getFormData().keySet()) {
if (formKey.equals(namingAttribute)) {
namingValue = formValues.getFormData().get(formKey);
}
}
if (namingValue == null || namingValue.isEmpty()) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_NEW_USER_FAILURE, "username definition not set, and naming attribute is not present in form"));
}
final String escapedName = StringUtil.escapeLdapDN(namingValue);
final String generatedDN = namingAttribute + "=" + escapedName + "," + expandedContext;
NewUserUtils.LOGGER.debug(pwmRequest, "generated dn for new user: " + generatedDN);
return generatedDN;
}
int attemptCount = 0;
final String generatedDN;
while (attemptCount < configuredNames.size()) {
final String expandedName;
{
{
final String configuredName = configuredNames.get(attemptCount);
expandedName = macroMachine.expandMacros(configuredName);
}
if (!testIfEntryNameExists(pwmRequest, expandedName)) {
NewUserUtils.LOGGER.trace(pwmRequest, "generated entry name for new user is unique: " + expandedName);
final String namingAttribute = pwmRequest.getConfig().getDefaultLdapProfile().readSettingAsString(PwmSetting.LDAP_NAMING_ATTRIBUTE);
final String escapedName = StringUtil.escapeLdapDN(expandedName);
generatedDN = namingAttribute + "=" + escapedName + "," + expandedContext;
NewUserUtils.LOGGER.debug(pwmRequest, "generated dn for new user: " + generatedDN);
return generatedDN;
} else {
failedValues.add(expandedName);
}
}
NewUserUtils.LOGGER.debug(pwmRequest, "generated entry name for new user is not unique, will try again");
attemptCount++;
}
NewUserUtils.LOGGER.error(pwmRequest, "failed to generate new user DN after " + attemptCount + " attempts, failed values: " + JsonUtil.serializeCollection(failedValues));
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_NEW_USER_FAILURE, "unable to generate a unique DN value"));
}
Aggregations