Search in sources :

Example 36 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class ChangePasswordServlet method nextStep.

public void nextStep(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException, ServletException {
    final ChangePasswordBean changePasswordBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ChangePasswordBean.class);
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final Configuration config = pwmApplication.getConfig();
    if (changePasswordBean.getChangeProgressTracker() != null) {
        forwardToWaitPage(pwmRequest);
        return;
    }
    if (ChangePasswordServletUtil.warnPageShouldBeShown(pwmRequest, changePasswordBean)) {
        LOGGER.trace(pwmRequest, "password expiration is within password warn period, forwarding user to warning page");
        pwmRequest.forwardToJsp(JspUrl.PASSWORD_WARN);
        return;
    }
    final String agreementMsg = pwmApplication.getConfig().readSettingAsLocalizedString(PwmSetting.PASSWORD_CHANGE_AGREEMENT_MESSAGE, pwmRequest.getLocale());
    if (agreementMsg != null && agreementMsg.length() > 0 && !changePasswordBean.isAgreementPassed()) {
        final MacroMachine macroMachine = pwmSession.getSessionManager().getMacroMachine(pwmApplication);
        final String expandedText = macroMachine.expandMacros(agreementMsg);
        pwmRequest.setAttribute(PwmRequestAttribute.AgreementText, expandedText);
        pwmRequest.forwardToJsp(JspUrl.PASSWORD_AGREEMENT);
        return;
    }
    if (ChangePasswordServletUtil.determineIfCurrentPasswordRequired(pwmApplication, pwmSession) && !changePasswordBean.isCurrentPasswordPassed()) {
        forwardToFormPage(pwmRequest);
        return;
    }
    if (!config.readSettingAsForm(PwmSetting.PASSWORD_REQUIRE_FORM).isEmpty() && !changePasswordBean.isFormPassed()) {
        forwardToFormPage(pwmRequest);
        return;
    }
    changePasswordBean.setAllChecksPassed(true);
    forwardToChangePage(pwmRequest);
}
Also used : ChangePasswordBean(password.pwm.http.bean.ChangePasswordBean) PwmApplication(password.pwm.PwmApplication) FormConfiguration(password.pwm.config.value.data.FormConfiguration) Configuration(password.pwm.config.Configuration) MacroMachine(password.pwm.util.macro.MacroMachine) PwmSession(password.pwm.http.PwmSession)

Example 37 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class CommandServlet method processNext.

@ActionHandler(action = "next")
private ProcessStatus processNext(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException, ServletException {
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final Configuration config = pwmApplication.getConfig();
    if (pwmRequest.isAuthenticated()) {
        if (AuthenticationFilter.forceRequiredRedirects(pwmRequest) == ProcessStatus.Halt) {
            return ProcessStatus.Halt;
        }
        // log the user out if our finish action is currently set to log out.
        final boolean forceLogoutOnChange = config.readSettingAsBoolean(PwmSetting.LOGOUT_AFTER_PASSWORD_CHANGE);
        if (forceLogoutOnChange && pwmSession.getSessionStateBean().isPasswordModified()) {
            LOGGER.trace(pwmSession, "logging out user; password has been modified");
            pwmRequest.sendRedirect(PwmServletDefinition.Logout);
            return ProcessStatus.Halt;
        }
    }
    redirectToForwardURL(pwmRequest);
    return ProcessStatus.Halt;
}
Also used : PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) PwmSession(password.pwm.http.PwmSession)

Example 38 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class ConfigEditorServlet method restSmsHealthCheck.

@ActionHandler(action = "smsHealthCheck")
private ProcessStatus restSmsHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restSmsHealthCheck");
    final List<HealthRecord> returnRecords = new ArrayList<>();
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    if (!SmsQueueManager.smsIsConfigured(config)) {
        returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "SMS not configured"));
    } else {
        final Map<String, String> testParams = pwmRequest.readBodyAsJsonStringMap();
        final SmsItemBean testSmsItem = new SmsItemBean(testParams.get("to"), testParams.get("message"), pwmRequest.getSessionLabel());
        try {
            final String responseBody = SmsQueueManager.sendDirectMessage(pwmRequest.getPwmApplication(), config, pwmRequest.getSessionLabel(), testSmsItem);
            returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "message sent"));
            returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "response body: \n" + StringUtil.escapeHtml(responseBody)));
        } catch (PwmException e) {
            returnRecords.add(new HealthRecord(HealthStatus.WARN, HealthTopic.SMS, "unable to send message: " + e.getMessage()));
        }
    }
    final HealthData healthData = HealthRecord.asHealthDataBean(config, pwmRequest.getLocale(), returnRecords);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restSmsHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : PwmException(password.pwm.error.PwmException) HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) HealthRecord(password.pwm.health.HealthRecord) Configuration(password.pwm.config.Configuration) SmsItemBean(password.pwm.bean.SmsItemBean) Instant(java.time.Instant) ArrayList(java.util.ArrayList) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 39 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class ForgottenUsernameServlet method sendUsername.

private void sendUsername(final PwmApplication pwmApplication, final PwmSession pwmSession, final UserInfo forgottenUserInfo) throws PwmOperationalException, PwmUnrecoverableException {
    final Locale userLocale = pwmSession.getSessionStateBean().getLocale();
    final Configuration configuration = pwmApplication.getConfig();
    final MessageSendMethod messageSendMethod = configuration.readSettingAsEnum(PwmSetting.FORGOTTEN_USERNAME_SEND_USERNAME_METHOD, MessageSendMethod.class);
    final EmailItemBean emailItemBean = configuration.readSettingAsEmail(PwmSetting.EMAIL_SEND_USERNAME, userLocale);
    final String smsMessage = configuration.readSettingAsLocalizedString(PwmSetting.SMS_FORGOTTEN_USERNAME_TEXT, userLocale);
    if (messageSendMethod == null || messageSendMethod == MessageSendMethod.NONE) {
        return;
    }
    sendMessageViaMethod(pwmApplication, pwmSession.getLabel(), forgottenUserInfo, messageSendMethod, emailItemBean, smsMessage);
}
Also used : Locale(java.util.Locale) Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) SearchConfiguration(password.pwm.ldap.search.SearchConfiguration) EmailItemBean(password.pwm.bean.EmailItemBean) MessageSendMethod(password.pwm.config.option.MessageSendMethod)

Example 40 with Configuration

use of password.pwm.config.Configuration in project pwm by pwm-project.

the class ForgottenUsernameServlet method processAction.

protected void processAction(final PwmRequest pwmRequest) throws ServletException, IOException, PwmUnrecoverableException {
    final Configuration config = pwmRequest.getConfig();
    if (!config.readSettingAsBoolean(PwmSetting.FORGOTTEN_USERNAME_ENABLE)) {
        pwmRequest.respondWithError(PwmError.ERROR_SERVICE_NOT_AVAILABLE.toInfo());
        return;
    }
    final ForgottenUsernameAction action = readProcessAction(pwmRequest);
    if (action != null) {
        pwmRequest.validatePwmFormID();
        switch(action) {
            case search:
                handleSearchRequest(pwmRequest);
                return;
            default:
                JavaHelper.unhandledSwitchStatement(action);
        }
    }
    forwardToFormJsp(pwmRequest);
}
Also used : Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) SearchConfiguration(password.pwm.ldap.search.SearchConfiguration)

Aggregations

Configuration (password.pwm.config.Configuration)111 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)45 FormConfiguration (password.pwm.config.value.data.FormConfiguration)37 PwmApplication (password.pwm.PwmApplication)33 ErrorInformation (password.pwm.error.ErrorInformation)33 PwmOperationalException (password.pwm.error.PwmOperationalException)25 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)23 Locale (java.util.Locale)22 PwmSession (password.pwm.http.PwmSession)21 PwmException (password.pwm.error.PwmException)17 EmailItemBean (password.pwm.bean.EmailItemBean)16 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)16 UserInfo (password.pwm.ldap.UserInfo)15 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)14 IOException (java.io.IOException)14 ArrayList (java.util.ArrayList)13 MacroMachine (password.pwm.util.macro.MacroMachine)13 LinkedHashMap (java.util.LinkedHashMap)12 Instant (java.time.Instant)11 UserIdentity (password.pwm.bean.UserIdentity)10