public static void saveConfiguration( final PwmRequest pwmRequest, final StoredConfigurationImpl storedConfiguration) throws PwmUnrecoverableException { { final List<String> errorStrings = storedConfiguration.validateValues(); if (errorStrings != null && !errorStrings.isEmpty()) { final String errorString = errorStrings.get(0); throw new PwmUnrecoverableException( new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] {errorString})); } } try { ContextManager contextManager = ContextManager.getContextManager( pwmRequest.getHttpServletRequest().getSession().getServletContext()); contextManager .getConfigReader() .saveConfiguration( storedConfiguration, contextManager.getPwmApplication(), pwmRequest.getSessionLabel()); contextManager.requestPwmApplicationRestart(); } catch (Exception e) { final String errorString = "error saving file: " + e.getMessage(); LOGGER.error(pwmRequest, errorString); throw new PwmUnrecoverableException( new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] {errorString})); } }
private void restBrowseLdap(final PwmRequest pwmRequest, final ConfigGuideBean configGuideBean) throws IOException, ServletException, PwmUnrecoverableException { final StoredConfigurationImpl storedConfiguration = StoredConfigurationImpl.copy(configGuideBean.getStoredConfiguration()); if (configGuideBean.getStep() == STEP.LDAP_ADMIN) { storedConfiguration.resetSetting(PwmSetting.LDAP_PROXY_USER_DN, LDAP_PROFILE_KEY, null); storedConfiguration.resetSetting(PwmSetting.LDAP_PROXY_USER_PASSWORD, LDAP_PROFILE_KEY, null); } final Date startTime = new Date(); final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation); final String profile = inputMap.get("profile"); final String dn = inputMap.containsKey("dn") ? inputMap.get("dn") : ""; final LdapBrowser ldapBrowser = new LdapBrowser(storedConfiguration); final LdapBrowser.LdapBrowseResult result = ldapBrowser.doBrowse(profile, dn); ldapBrowser.close(); LOGGER.trace( pwmRequest, "performed ldapBrowse operation in " + TimeDuration.fromCurrent(startTime).asCompactString() + ", result=" + JsonUtil.serialize(result)); pwmRequest.outputJsonResult(new RestResultBean(result)); }
protected static void restValidateForm( final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException { boolean success = true; String userMessage = Message.getLocalizedMessage( pwmRequest.getLocale(), Message.Success_UpdateForm, pwmRequest.getConfig()); final Map<FormConfiguration, String> formValues = updateProfileBean.getFormData(); try { // read in the responses from the request readFromJsonRequest(pwmRequest, updateProfileBean); // verify form meets the form requirements verifyFormAttributes(pwmRequest, formValues, true); } 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)); }
public static String makeClientEtag(final PwmRequest pwmRequest) throws PwmUnrecoverableException { return makeClientEtag( pwmRequest.getPwmApplication(), pwmRequest.getPwmSession(), pwmRequest.getHttpServletRequest()); }
private void restUpdateLdapForm( final PwmRequest pwmRequest, final ConfigGuideBean configGuideBean) throws IOException, PwmUnrecoverableException { final StoredConfigurationImpl storedConfiguration = configGuideBean.getStoredConfiguration(); final Map<String, String> incomingFormData = pwmRequest.readBodyAsJsonStringMap(); if (incomingFormData != null) { configGuideBean.getFormData().putAll(incomingFormData); } if (incomingFormData != null && incomingFormData.get(PARAM_TEMPLATE_NAME) != null && !incomingFormData.get(PARAM_TEMPLATE_NAME).isEmpty()) { try { final PwmSettingTemplate template = PwmSettingTemplate.valueOf(incomingFormData.get(PARAM_TEMPLATE_NAME)); if (configGuideBean.getSelectedTemplate() != template) { LOGGER.debug( pwmRequest, "resetting form defaults using " + template.toString() + " template"); final Map<String, String> defaultForm = defaultForm(template); configGuideBean.getFormData().putAll(defaultForm); configGuideBean.setSelectedTemplate(template); storedConfiguration.setTemplate(template); } } catch (Exception e) { LOGGER.error("unknown template set request: " + e.getMessage()); } } final RestResultBean restResultBean = new RestResultBean(); pwmRequest.outputJsonResult(restResultBean); convertFormToConfiguration( storedConfiguration, configGuideBean.getFormData(), incomingFormData); // LOGGER.info("config: " + storedConfiguration.toString()); }
private void handleEnterCodeRequest( final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean) throws PwmUnrecoverableException, IOException, ServletException, ChaiUnavailableException { final PwmApplication pwmApplication = pwmRequest.getPwmApplication(); final PwmSession pwmSession = pwmRequest.getPwmSession(); final String userEnteredCode = pwmRequest.readParameterAsString(PwmConstants.PARAM_TOKEN); boolean tokenPassed = false; ErrorInformation errorInformation = null; try { final TokenPayload tokenPayload = pwmApplication .getTokenService() .processUserEnteredCode( pwmSession, pwmRequest.getUserInfoIfLoggedIn(), null, userEnteredCode); if (tokenPayload != null) { if (TokenType.UPDATE_EMAIL.matchesName(tokenPayload.getName())) { LOGGER.debug(pwmRequest, "email token passed"); updateProfileBean .getTokenVerificationProgress() .getPassedTokens() .add(TokenVerificationProgress.TokenChannel.EMAIL); updateProfileBean .getTokenVerificationProgress() .getIssuedTokens() .add(TokenVerificationProgress.TokenChannel.EMAIL); updateProfileBean.getTokenVerificationProgress().setPhase(null); tokenPassed = true; } else if (TokenType.UPDATE_SMS.matchesName(tokenPayload.getName())) { LOGGER.debug(pwmRequest, "SMS token passed"); updateProfileBean .getTokenVerificationProgress() .getPassedTokens() .add(TokenVerificationProgress.TokenChannel.SMS); updateProfileBean .getTokenVerificationProgress() .getIssuedTokens() .add(TokenVerificationProgress.TokenChannel.SMS); updateProfileBean.getTokenVerificationProgress().setPhase(null); tokenPassed = true; } else { final String errorMsg = "token name/type is not recognized: " + tokenPayload.getName(); errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT, errorMsg); } } } catch (PwmOperationalException e) { final String errorMsg = "token incorrect: " + e.getMessage(); errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT, errorMsg); } if (!tokenPassed) { if (errorInformation == null) { errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT); } LOGGER.debug(pwmSession, errorInformation.toDebugStr()); pwmRequest.setResponseError(errorInformation); } }
private void showSummary(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException { final StoredConfigurationImpl storedConfiguration = readCurrentConfiguration(pwmRequest); final LinkedHashMap<String, Object> outputMap = new LinkedHashMap<>(storedConfiguration.toOutputMap(pwmRequest.getLocale())); pwmRequest.setAttribute(PwmRequest.Attribute.ConfigurationSummaryOutput, outputMap); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.CONFIG_MANAGER_EDITOR_SUMMARY); }
protected void forwardToConfirmForm(final PwmRequest pwmRequest) throws ServletException, PwmUnrecoverableException, IOException { final List<FormConfiguration> form = pwmRequest.getConfig().readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM); final Map<FormConfiguration, String> formData = pwmRequest.getPwmSession().getUpdateProfileBean().getFormData(); pwmRequest.addFormInfoToRequestAttr(form, formData, true, false); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.UPDATE_ATTRIBUTES_CONFIRM); }
private void showPermissions(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException { final StoredConfigurationImpl storedConfiguration = readCurrentConfiguration(pwmRequest); LDAPPermissionCalculator ldapPermissionCalculator = new LDAPPermissionCalculator(storedConfiguration); pwmRequest.setAttribute( PwmRequest.Attribute.ConfigurationSummaryOutput, ldapPermissionCalculator); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.CONFIG_MANAGER_PERMISSIONS); }
protected void processAction(final PwmRequest pwmRequest) throws ServletException, IOException, ChaiUnavailableException, PwmUnrecoverableException { final PwmApplication pwmApplication = pwmRequest.getPwmApplication(); final UpdateAttributesProfile updateAttributesProfile = pwmRequest.getPwmSession().getSessionManager().getUpdateAttributeProfile(pwmApplication); final UpdateProfileBean updateProfileBean = pwmApplication.getSessionStateService().getBean(pwmRequest, UpdateProfileBean.class); if (!pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_ENABLE)) { pwmRequest.respondWithError( new ErrorInformation( PwmError.ERROR_SERVICE_NOT_AVAILABLE, "Setting " + PwmSetting.UPDATE_PROFILE_ENABLE.toMenuLocationDebug(null, null) + " is not enabled.")); return; } if (updateAttributesProfile == null) { pwmRequest.respondWithError(new ErrorInformation(PwmError.ERROR_NO_PROFILE_ASSIGNED)); return; } final UpdateProfileAction action = readProcessAction(pwmRequest); if (action != null) { pwmRequest.validatePwmFormID(); switch (action) { case updateProfile: handleUpdateRequest(pwmRequest, updateAttributesProfile, updateProfileBean); break; case agree: handleAgreeRequest(pwmRequest, updateProfileBean); break; case confirm: updateProfileBean.setConfirmationPassed(true); break; case unConfirm: handleUnconfirm(updateProfileBean); break; case validate: restValidateForm(pwmRequest, updateAttributesProfile, updateProfileBean); return; case enterCode: handleEnterCodeRequest(pwmRequest, updateProfileBean); break; } } advanceToNextStep(pwmRequest, updateAttributesProfile, updateProfileBean); }
void initRequestAttributes(final PwmRequest pwmRequest) throws PwmUnrecoverableException { final ConfigurationReader configurationReader = pwmRequest.getContextManager().getConfigReader(); pwmRequest.setAttribute( PwmRequest.Attribute.PageTitle, LocaleHelper.getLocalizedMessage(Config.Title_ConfigManager, pwmRequest)); pwmRequest.setAttribute( PwmRequest.Attribute.ApplicationPath, pwmRequest.getPwmApplication().getPwmEnvironment().getApplicationPath().getAbsolutePath()); pwmRequest.setAttribute( PwmRequest.Attribute.ConfigFilename, configurationReader.getConfigFile().getAbsolutePath()); { final Date lastModifyTime = configurationReader.getStoredConfiguration().modifyTime(); final String output = lastModifyTime == null ? LocaleHelper.getLocalizedMessage(Display.Value_NotApplicable, pwmRequest) : PwmConstants.DEFAULT_DATETIME_FORMAT.format(lastModifyTime); pwmRequest.setAttribute(PwmRequest.Attribute.ConfigLastModified, output); } pwmRequest.setAttribute( PwmRequest.Attribute.ConfigHasPassword, LocaleHelper.booleanString( configurationReader.getStoredConfiguration().hasPassword(), pwmRequest.getLocale(), pwmRequest.getConfig())); }
static Set<TokenVerificationProgress.TokenChannel> determineTokenPhaseRequired( final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean, final UpdateAttributesProfile updateAttributesProfile) throws PwmUnrecoverableException { final Set<TokenVerificationProgress.TokenChannel> returnObj = new HashSet<>(); final Map<String, String> userFormData = updateProfileBean.getFormData(); Map<String, String> ldapData = null; if (updateAttributesProfile.readSettingAsBoolean( PwmSetting.UPDATE_PROFILE_EMAIL_VERIFICATION)) { final String emailAddressAttribute = pwmRequest.getConfig().readSettingAsString(PwmSetting.EMAIL_USER_MAIL_ATTRIBUTE); if (userFormData.containsKey(emailAddressAttribute)) { ldapData = formDataFromLdap(pwmRequest, updateAttributesProfile); if (userFormData.get(emailAddressAttribute) != null && !userFormData .get(emailAddressAttribute) .equalsIgnoreCase(ldapData.get(emailAddressAttribute))) { returnObj.add(TokenVerificationProgress.TokenChannel.EMAIL); } } else { LOGGER.warn( pwmRequest, "email verification enabled, but email attribute '" + emailAddressAttribute + "' is not in update form"); } } if (updateAttributesProfile.readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_SMS_VERIFICATION)) { final String phoneNumberAttribute = pwmRequest.getConfig().readSettingAsString(PwmSetting.SMS_USER_PHONE_ATTRIBUTE); if (userFormData.containsKey(phoneNumberAttribute)) { if (ldapData == null) { ldapData = formDataFromLdap(pwmRequest, updateAttributesProfile); } if (userFormData.get(phoneNumberAttribute) != null && !userFormData .get(phoneNumberAttribute) .equalsIgnoreCase(ldapData.get(phoneNumberAttribute))) { returnObj.add(TokenVerificationProgress.TokenChannel.SMS); } } else { LOGGER.warn( pwmRequest, "sms verification enabled, but phone attribute '" + phoneNumberAttribute + "' is not in update form"); } } return returnObj; }
static void forwardToConfirmForm( final PwmRequest pwmRequest, final UpdateAttributesProfile updateAttributesProfile, final UpdateProfileBean updateProfileBean) throws ServletException, PwmUnrecoverableException, IOException { final List<FormConfiguration> form = updateAttributesProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM); final Map<FormConfiguration, String> formValueMap = formMapFromBean(updateAttributesProfile, updateProfileBean); pwmRequest.addFormInfoToRequestAttr(form, formValueMap, true, false); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.UPDATE_ATTRIBUTES_CONFIRM); }
private void forwardToJSP( final PwmRequest pwmRequest, final GuestRegistrationBean guestRegistrationBean) throws IOException, ServletException, PwmUnrecoverableException { calculateFutureDateFlags(pwmRequest, guestRegistrationBean); if (Page.search == guestRegistrationBean.getCurrentPage()) { pwmRequest.addFormInfoToRequestAttr(PwmSetting.GUEST_UPDATE_FORM, false, false); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.GUEST_UPDATE_SEARCH); } else { pwmRequest.addFormInfoToRequestAttr(PwmSetting.GUEST_FORM, false, false); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.GUEST_REGISTRATION); } }
private void readFormParametersFromRequest( final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean) throws PwmUnrecoverableException, PwmDataValidationException, ChaiUnavailableException { final List<FormConfiguration> formFields = pwmRequest.getConfig().readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM); final Map<FormConfiguration, String> existingForm = updateProfileBean.getFormData(); // read the values from the request existingForm.putAll( FormUtility.readFormValuesFromRequest(pwmRequest, formFields, pwmRequest.getLocale())); }
private void restExtendSchema(final PwmRequest pwmRequest, final ConfigGuideBean configGuideBean) throws IOException { try { SchemaOperationResult schemaOperationResult = extendSchema(configGuideBean, true); pwmRequest.outputJsonResult(new RestResultBean(schemaOperationResult.getOperationLog())); } catch (Exception e) { ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage()); pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest)); LOGGER.error(pwmRequest, e.getMessage(), e); } }
static void forwardToJSP(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException { final HttpServletRequest req = pwmRequest.getHttpServletRequest(); final ServletContext servletContext = req.getSession().getServletContext(); final ConfigGuideBean configGuideBean = pwmRequest.getPwmSession().getSessionBean(ConfigGuideBean.class); String destURL = '/' + PwmConstants.URL_JSP_CONFIG_GUIDE; destURL = destURL.replace("%1%", configGuideBean.getStep().toString().toLowerCase()); servletContext .getRequestDispatcher(destURL) .forward(req, pwmRequest.getPwmResponse().getHttpServletResponse()); }
private static void forwardToJsp(final PwmRequest pwmRequest) throws ServletException, PwmUnrecoverableException, IOException { final int persistentSeconds = figureMaxLoginSeconds(pwmRequest); final String time = new TimeDuration(persistentSeconds * 1000).asLongString(pwmRequest.getLocale()); final ConfigLoginHistory configLoginHistory = readConfigLoginHistory(pwmRequest); pwmRequest.setAttribute(PwmConstants.REQUEST_ATTR.ConfigLoginHistory, configLoginHistory); pwmRequest.setAttribute(PwmConstants.REQUEST_ATTR.ConfigPasswordRememberTime, time); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.CONFIG_MANAGER_LOGIN); }
protected void processAction(final PwmRequest pwmRequest) throws ServletException, IOException, ChaiUnavailableException, PwmUnrecoverableException { final PwmSession pwmSession = pwmRequest.getPwmSession(); final ConfigManagerBean configManagerBean = pwmRequest .getPwmApplication() .getSessionStateService() .getBean(pwmRequest, ConfigManagerBean.class); final ConfigManagerAction processAction = readProcessAction(pwmRequest); if (processAction != null) { switch (processAction) { case lockConfiguration: restLockConfiguration(pwmRequest); break; case startEditing: doStartEditing(pwmRequest); break; case downloadConfig: doDownloadConfig(pwmRequest); break; case generateSupportZip: doGenerateSupportZip(pwmRequest); break; case uploadConfig: ConfigGuideServlet.restUploadConfig(pwmRequest); return; case uploadWordlist: restUploadWordlist(pwmRequest); return; case summary: showSummary(pwmRequest); return; case permissions: showPermissions(pwmRequest); return; } return; } initRequestAttributes(pwmRequest); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.CONFIG_MANAGER_MODE_CONFIGURATION); }
private void restUseConfiguredCerts( final PwmRequest pwmRequest, final ConfigGuideBean configGuideBean) throws PwmUnrecoverableException, IOException { final boolean value = Boolean.parseBoolean(pwmRequest.readParameterAsString("value")); configGuideBean.setUseConfiguredCerts(value); final StoredValue newStoredValue = value ? new X509CertificateValue(configGuideBean.getLdapCertificates()) : new X509CertificateValue(new X509Certificate[0]); configGuideBean .getStoredConfiguration() .writeSetting(PwmSetting.LDAP_SERVER_CERTS, LDAP_PROFILE_KEY, newStoredValue, null); pwmRequest.outputJsonResult(new RestResultBean()); }
private static void readFromJsonRequest( final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean) throws PwmDataValidationException, PwmUnrecoverableException, IOException { final List<FormConfiguration> formFields = pwmRequest.getConfig().readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM); final Map<FormConfiguration, String> existingForm = updateProfileBean.getFormData(); final Map<String, String> clientValues = pwmRequest.readBodyAsJsonStringMap(); if (clientValues != null) { existingForm.putAll( FormUtility.readFormValuesFromMap(clientValues, formFields, pwmRequest.getLocale())); } }
@Override void processFilter(PwmRequest pwmRequest, PwmFilterChain filterChain) throws PwmException, IOException, ServletException { final PwmApplication.MODE appMode = pwmRequest.getPwmApplication().getApplicationMode(); if (appMode == PwmApplication.MODE.NEW) { filterChain.doFilter(); return; } final ConfigManagerBean configManagerBean = pwmRequest.getPwmSession().getConfigManagerBean(); if (!checkAuthentication(pwmRequest, configManagerBean)) { filterChain.doFilter(); } }
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); }
private void forwardToUpdateJSP( final PwmRequest pwmRequest, final GuestRegistrationBean guestRegistrationBean) throws IOException, ServletException, PwmUnrecoverableException { calculateFutureDateFlags(pwmRequest, guestRegistrationBean); final List<FormConfiguration> guestUpdateForm = pwmRequest.getConfig().readSettingAsForm(PwmSetting.GUEST_UPDATE_FORM); final Map<FormConfiguration, String> formValueMap = new LinkedHashMap<>(); for (final FormConfiguration formConfiguration : guestUpdateForm) { final String value = guestRegistrationBean.getFormValues().get(formConfiguration.getName()); formValueMap.put(formConfiguration, value); } pwmRequest.addFormInfoToRequestAttr(guestUpdateForm, formValueMap, false, false); pwmRequest.forwardToJsp(PwmConstants.JSP_URL.GUEST_UPDATE); }
protected void processAction(final PwmRequest pwmRequest) throws ServletException, ChaiUnavailableException, IOException, PwmUnrecoverableException { // Fetch the session state bean. final PwmSession pwmSession = pwmRequest.getPwmSession(); final PwmApplication pwmApplication = pwmRequest.getPwmApplication(); final GuestRegistrationBean guestRegistrationBean = pwmApplication.getSessionStateService().getBean(pwmRequest, GuestRegistrationBean.class); final Configuration config = pwmApplication.getConfig(); if (!config.readSettingAsBoolean(PwmSetting.GUEST_ENABLE)) { pwmRequest.respondWithError(PwmError.ERROR_SERVICE_NOT_AVAILABLE.toInfo()); return; } if (!pwmSession .getSessionManager() .checkPermission(pwmApplication, Permission.GUEST_REGISTRATION)) { pwmRequest.respondWithError(PwmError.ERROR_UNAUTHORIZED.toInfo()); return; } checkConfiguration(config); final GuestRegistrationAction action = readProcessAction(pwmRequest); if (action != null) { pwmRequest.validatePwmFormID(); switch (action) { case create: handleCreateRequest(pwmRequest, guestRegistrationBean); return; case search: handleSearchRequest(pwmRequest, guestRegistrationBean); return; case update: handleUpdateRequest(pwmRequest, guestRegistrationBean); return; case selectPage: handleSelectPageRequest(pwmRequest, guestRegistrationBean); return; } } this.forwardToJSP(pwmRequest, guestRegistrationBean); }
private void doGenerateSupportZip(final PwmRequest pwmRequest) throws IOException, ServletException { final PwmResponse resp = pwmRequest.getPwmResponse(); resp.setHeader( PwmConstants.HttpHeader.ContentDisposition, "attachment;filename=" + PwmConstants.PWM_APP_NAME + "-Support.zip"); resp.setContentType(PwmConstants.ContentTypeValue.zip); final String pathPrefix = PwmConstants.PWM_APP_NAME + "-Support" + "/"; ZipOutputStream zipOutput = null; try { zipOutput = new ZipOutputStream(resp.getOutputStream(), PwmConstants.DEFAULT_CHARSET); DebugItemGenerator.outputZipDebugFile(pwmRequest, zipOutput, pathPrefix); } catch (Exception e) { LOGGER.error(pwmRequest, "error during zip debug building: " + e.getMessage()); } finally { if (zipOutput != null) { try { zipOutput.close(); } catch (Exception e) { LOGGER.error(pwmRequest, "error during zip debug closing: " + e.getMessage()); } } } }
private static Date readExpirationFromRequest(final PwmRequest pwmRequest) throws PwmOperationalException, ChaiUnavailableException, ChaiOperationException, PwmUnrecoverableException { final PwmApplication pwmApplication = pwmRequest.getPwmApplication(); final Configuration config = pwmApplication.getConfig(); final long durationValueDays = config.readSettingAsLong(PwmSetting.GUEST_MAX_VALID_DAYS); final String expirationAttribute = config.readSettingAsString(PwmSetting.GUEST_EXPIRATION_ATTRIBUTE); if (durationValueDays == 0 || expirationAttribute == null || expirationAttribute.length() <= 0) { return null; } final String expirationDateStr = pwmRequest.readParameterAsString(HTTP_PARAM_EXPIRATION_DATE); Date expirationDate; try { expirationDate = new SimpleDateFormat("yyyy-MM-dd").parse(expirationDateStr); } catch (ParseException e) { final String errorMsg = "unable to read expiration date value: " + e.getMessage(); throw new PwmOperationalException( new ErrorInformation( PwmError.ERROR_FIELD_REQUIRED, errorMsg, new String[] {"expiration date"})); } if (expirationDate.before(new Date())) { final String errorMsg = "expiration date must be in the future"; throw new PwmOperationalException( new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMsg)); } final long durationValueMs = durationValueDays * 24 * 60 * 60 * 1000; final long futureDateMs = System.currentTimeMillis() + durationValueMs; final Date futureDate = new Date(futureDateMs); if (expirationDate.after(futureDate)) { final String errorMsg = "expiration date must be sooner than " + futureDate.toString(); throw new PwmOperationalException( new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMsg)); } LOGGER.trace(pwmRequest, "read expiration date as " + expirationDate.toString()); return expirationDate; }
private static ConfigLoginHistory readConfigLoginHistory(final PwmRequest pwmRequest) { ConfigLoginHistory configLoginHistory = pwmRequest .getPwmApplication() .readAppAttribute( PwmApplication.AppAttribute.CONFIG_LOGIN_HISTORY, ConfigLoginHistory.class); return configLoginHistory == null ? new ConfigLoginHistory() : configLoginHistory; }
protected void processAction(final PwmRequest pwmRequest) throws ServletException, IOException, ChaiUnavailableException, PwmUnrecoverableException { final PwmSession pwmSession = pwmRequest.getPwmSession(); final PwmApplication pwmApplication = pwmRequest.getPwmApplication(); final UpdateProfileBean updateProfileBean = pwmSession.getUpdateProfileBean(); if (!pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_ENABLE)) { pwmRequest.respondWithError(new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE)); return; } if (!pwmSession .getSessionManager() .checkPermission(pwmApplication, Permission.PROFILE_UPDATE)) { pwmRequest.respondWithError(new ErrorInformation(PwmError.ERROR_UNAUTHORIZED)); return; } final UpdateProfileAction action = readProcessAction(pwmRequest); if (action != null) { pwmRequest.validatePwmFormID(); switch (action) { case updateProfile: handleUpdateRequest(pwmRequest, updateProfileBean); break; case agree: handleAgreeRequest(pwmRequest, updateProfileBean); break; case confirm: updateProfileBean.setConfirmationPassed(true); break; case unConfirm: handleUnconfirm(updateProfileBean); break; case validate: restValidateForm(pwmRequest, updateProfileBean); return; } } advanceToNextStep(pwmRequest, updateProfileBean); }
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; }