protected static void restValidateForm( final PwmRequest pwmRequest, final UpdateAttributesProfile updateAttributesProfile, final UpdateProfileBean updateProfileBean) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException { boolean success = true; String userMessage = Message.getLocalizedMessage( pwmRequest.getLocale(), Message.Success_UpdateForm, pwmRequest.getConfig()); try { // read in the responses from the request final Map<FormConfiguration, String> formValues = readFromJsonRequest(pwmRequest, updateAttributesProfile, updateProfileBean); // verify form meets the form requirements verifyFormAttributes(pwmRequest, formValues, true); updateProfileBean.getFormData().putAll(FormUtility.asStringMap(formValues)); } catch (PwmOperationalException e) { success = false; userMessage = e.getErrorInformation() .toUserStr(pwmRequest.getPwmSession(), pwmRequest.getPwmApplication()); } final LinkedHashMap<String, String> outputMap = new LinkedHashMap<>(); outputMap.put("version", "1"); outputMap.put("message", userMessage); outputMap.put("success", String.valueOf(success)); pwmRequest.outputJsonResult(new RestResultBean(outputMap)); }
static Map<String, String> formDataFromLdap( final PwmRequest pwmRequest, UpdateAttributesProfile updateAttributesProfile) throws PwmUnrecoverableException { final UserDataReader userDataReader = pwmRequest .getPwmSession() .getSessionManager() .getUserDataReader(pwmRequest.getPwmApplication()); final List<FormConfiguration> formFields = updateAttributesProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM); final Map<FormConfiguration, String> formMap = new HashMap<>(); FormUtility.populateFormMapFromLdap( formFields, pwmRequest.getSessionLabel(), formMap, userDataReader); return FormUtility.asStringMap(formMap); }
static Map<FormConfiguration, String> readFromJsonRequest( final PwmRequest pwmRequest, final UpdateAttributesProfile updateAttributesProfile, final UpdateProfileBean updateProfileBean) throws PwmDataValidationException, PwmUnrecoverableException, IOException { final List<FormConfiguration> formFields = updateAttributesProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM); final Map<FormConfiguration, String> formValueMap = FormUtility.readFormValuesFromMap( pwmRequest.readBodyAsJsonStringMap(), formFields, pwmRequest.getLocale()); updateProfileBean.getFormData().clear(); updateProfileBean.getFormData().putAll(FormUtility.asStringMap(formValueMap)); return formValueMap; }
final Map<FormConfiguration, String> readFormParametersFromRequest( final PwmRequest pwmRequest, final UpdateAttributesProfile updateAttributesProfile, final UpdateProfileBean updateProfileBean) throws PwmUnrecoverableException, PwmDataValidationException, ChaiUnavailableException { final List<FormConfiguration> formFields = updateAttributesProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM); // read the values from the request final Map<FormConfiguration, String> formValueMap = FormUtility.readFormValuesFromRequest(pwmRequest, formFields, pwmRequest.getLocale()); updateProfileBean.getFormData().clear(); updateProfileBean.getFormData().putAll(FormUtility.asStringMap(formValueMap)); return formValueMap; }