Search in sources :

Example 11 with ConfigGuideBean

use of password.pwm.http.bean.ConfigGuideBean in project pwm by pwm-project.

the class ConfigGuideServlet method restGotoStep.

@ActionHandler(action = "gotoStep")
private ProcessStatus restGotoStep(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final String requestedStep = pwmRequest.readParameterAsString("step");
    GuideStep step = GuideStep.START;
    if (requestedStep != null && requestedStep.length() > 0) {
        try {
            step = GuideStep.valueOf(requestedStep);
        } catch (IllegalArgumentException e) {
            final String errorMsg = "unknown goto step request: " + requestedStep;
            LOGGER.error(pwmRequest, errorMsg);
        }
    }
    if (step == GuideStep.START) {
        configGuideBean.getFormData().clear();
        configGuideBean.getFormData().putAll(ConfigGuideForm.defaultForm());
    } else if (step == GuideStep.NEXT) {
        step = configGuideBean.getStep().next();
        while (step != GuideStep.FINISH && !step.visible(configGuideBean)) {
            step = step.next();
        }
    } else if (step == GuideStep.PREVIOUS) {
        step = configGuideBean.getStep().previous();
        while (step != GuideStep.START && !step.visible(configGuideBean)) {
            step = step.previous();
        }
    }
    if (step == GuideStep.FINISH) {
        final ContextManager contextManager = ContextManager.getContextManager(pwmRequest);
        try {
            ConfigGuideUtils.writeConfig(contextManager, configGuideBean);
            pwmRequest.getPwmSession().getSessionStateBean().setTheme(null);
        } catch (PwmException e) {
            final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
            pwmRequest.outputJsonResult(restResultBean);
            return ProcessStatus.Halt;
        } catch (Exception e) {
            final RestResultBean restResultBean = RestResultBean.fromError(new ErrorInformation(PwmError.ERROR_UNKNOWN, "error during save: " + e.getMessage()), pwmRequest);
            pwmRequest.outputJsonResult(restResultBean);
            return ProcessStatus.Halt;
        }
        final HashMap<String, String> resultData = new HashMap<>();
        resultData.put("serverRestart", "true");
        pwmRequest.outputJsonResult(RestResultBean.withData(resultData));
        pwmRequest.invalidateSession();
    } else {
        configGuideBean.setStep(step);
        pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
        LOGGER.trace("setting current step to: " + step);
    }
    return ProcessStatus.Continue;
}
Also used : PwmException(password.pwm.error.PwmException) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) ErrorInformation(password.pwm.error.ErrorInformation) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ContextManager(password.pwm.http.ContextManager) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 12 with ConfigGuideBean

use of password.pwm.http.bean.ConfigGuideBean in project pwm by pwm-project.

the class ConfigGuideServlet method restUseConfiguredCerts.

@ActionHandler(action = "useConfiguredCerts")
private ProcessStatus restUseConfiguredCerts(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final boolean value = Boolean.parseBoolean(pwmRequest.readParameterAsString("value"));
    configGuideBean.setUseConfiguredCerts(value);
    pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
    return ProcessStatus.Halt;
}
Also used : ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean)

Example 13 with ConfigGuideBean

use of password.pwm.http.bean.ConfigGuideBean in project pwm by pwm-project.

the class ConfigGuideServlet method restBrowseLdap.

@ActionHandler(action = "browseLdap")
private ProcessStatus restBrowseLdap(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfiguration = ConfigGuideForm.generateStoredConfig(configGuideBean);
    if (configGuideBean.getStep() == GuideStep.LDAP_PROXY) {
        storedConfiguration.resetSetting(PwmSetting.LDAP_PROXY_USER_DN, LDAP_PROFILE_KEY, null);
        storedConfiguration.resetSetting(PwmSetting.LDAP_PROXY_USER_PASSWORD, LDAP_PROFILE_KEY, null);
    }
    final Instant startTime = Instant.now();
    final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
    final String profile = inputMap.get("profile");
    final String dn = inputMap.getOrDefault("dn", "");
    final LdapBrowser ldapBrowser = new LdapBrowser(pwmRequest.getPwmApplication().getLdapConnectionService().getChaiProviderFactory(), 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(RestResultBean.withData(result));
    return ProcessStatus.Halt;
}
Also used : ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Instant(java.time.Instant) LdapBrowser(password.pwm.ldap.LdapBrowser)

Aggregations

ConfigGuideBean (password.pwm.http.bean.ConfigGuideBean)13 PwmException (password.pwm.error.PwmException)7 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)6 IOException (java.io.IOException)6 ServletException (javax.servlet.ServletException)6 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)6 PwmOperationalException (password.pwm.error.PwmOperationalException)6 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)6 LinkedHashMap (java.util.LinkedHashMap)5 ErrorInformation (password.pwm.error.ErrorInformation)4 RestResultBean (password.pwm.ws.server.RestResultBean)4 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 PwmApplication (password.pwm.PwmApplication)2 PwmSetting (password.pwm.config.PwmSetting)2 UserMatchViewerFunction (password.pwm.config.function.UserMatchViewerFunction)2 URI (java.net.URI)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1