Search in sources :

Example 11 with ConfigManagerBean

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

the class ConfigEditorServlet method preProcessCheck.

@Override
public ProcessStatus preProcessCheck(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    if (configManagerBean.getStoredConfiguration() == null) {
        final StoredConfigurationImpl loadedConfig = ConfigManagerServlet.readCurrentConfiguration(pwmRequest);
        configManagerBean.setConfiguration(loadedConfig);
    }
    return ProcessStatus.Continue;
}
Also used : ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl)

Example 12 with ConfigManagerBean

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

the class ConfigEditorServlet method restCopyProfile.

@ActionHandler(action = "copyProfile")
private ProcessStatus restCopyProfile(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
    final String settingKey = inputMap.get("setting");
    final PwmSetting setting = PwmSetting.forKey(settingKey);
    PwmSettingCategory category = null;
    for (final PwmSettingCategory loopCategory : PwmSettingCategory.values()) {
        if (loopCategory.hasProfiles()) {
            if (loopCategory.getProfileSetting() == setting) {
                category = loopCategory;
            }
        }
    }
    final String sourceID = inputMap.get("sourceID");
    final String destinationID = inputMap.get("destinationID");
    try {
        configManagerBean.getStoredConfiguration().copyProfileID(category, sourceID, destinationID, pwmRequest.getUserInfoIfLoggedIn());
        pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
    } catch (PwmUnrecoverableException e) {
        pwmRequest.outputJsonResult(RestResultBean.fromError(e.getErrorInformation(), pwmRequest));
    }
    return ProcessStatus.Halt;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) PwmSettingCategory(password.pwm.config.PwmSettingCategory) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 13 with ConfigManagerBean

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

the class ConfigEditorServlet method restLdapHealthCheck.

@ActionHandler(action = "ldapHealthCheck")
private ProcessStatus restLdapHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restLdapHealthCheck");
    final String profileID = pwmRequest.readParameterAsString("profile");
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    final HealthData healthData = LDAPStatusChecker.healthForNewConfiguration(pwmRequest.getPwmApplication(), config, pwmRequest.getLocale(), profileID, true, true);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restLdapHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) Configuration(password.pwm.config.Configuration) Instant(java.time.Instant) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 14 with ConfigManagerBean

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

the class ConfigEditorServlet method restExecuteSettingFunction.

@ActionHandler(action = "executeSettingFunction")
private ProcessStatus restExecuteSettingFunction(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final String bodyString = pwmRequest.readRequestBodyAsString();
    final Map<String, String> requestMap = JsonUtil.deserializeStringMap(bodyString);
    final PwmSetting pwmSetting = PwmSetting.forKey(requestMap.get("setting"));
    final String functionName = requestMap.get("function");
    final String profileID = pwmSetting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
    final String extraData = requestMap.get("extraData");
    try {
        final Class implementingClass = Class.forName(functionName);
        final SettingUIFunction function = (SettingUIFunction) implementingClass.newInstance();
        final Serializable result = function.provideFunction(pwmRequest, configManagerBean.getStoredConfiguration(), pwmSetting, profileID, extraData);
        final RestResultBean restResultBean = RestResultBean.forSuccessMessage(result, pwmRequest, Message.Success_Unknown);
        pwmRequest.outputJsonResult(restResultBean);
    } catch (Exception e) {
        final RestResultBean restResultBean;
        if (e instanceof PwmException) {
            restResultBean = RestResultBean.fromError(((PwmException) e).getErrorInformation(), pwmRequest, true);
        } else {
            final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error performing user search: " + e.getMessage());
            restResultBean = RestResultBean.fromError(errorInformation, pwmRequest);
        }
        pwmRequest.outputJsonResult(restResultBean);
    }
    return ProcessStatus.Halt;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) PwmException(password.pwm.error.PwmException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ErrorInformation(password.pwm.error.ErrorInformation) Serializable(java.io.Serializable) SettingUIFunction(password.pwm.config.SettingUIFunction) 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 15 with ConfigManagerBean

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

the class ConfigEditorServlet method restWriteSetting.

@ActionHandler(action = "writeSetting")
private ProcessStatus restWriteSetting(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfig = configManagerBean.getStoredConfiguration();
    final String key = pwmRequest.readParameterAsString("key");
    final String bodyString = pwmRequest.readRequestBodyAsString();
    final PwmSetting setting = PwmSetting.forKey(key);
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
    final UserIdentity loggedInUser = pwmRequest.getPwmSession().isAuthenticated() ? pwmRequest.getPwmSession().getUserInfo().getUserIdentity() : null;
    if (key.startsWith("localeBundle")) {
        final StringTokenizer st = new StringTokenizer(key, "-");
        st.nextToken();
        final PwmLocaleBundle bundleName = PwmLocaleBundle.valueOf(st.nextToken());
        final String keyName = st.nextToken();
        final Map<String, String> valueMap = JsonUtil.deserializeStringMap(bodyString);
        final Map<String, String> outputMap = new LinkedHashMap<>(valueMap);
        storedConfig.writeLocaleBundleMap(bundleName.getTheClass().getName(), keyName, outputMap);
        returnMap.put("isDefault", outputMap.isEmpty());
        returnMap.put("key", key);
    } else {
        final String profileID = setting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
        try {
            final StoredValue storedValue = ValueFactory.fromJson(setting, bodyString);
            final List<String> errorMsgs = storedValue.validateValue(setting);
            if (errorMsgs != null && !errorMsgs.isEmpty()) {
                returnMap.put("errorMessage", setting.getLabel(pwmRequest.getLocale()) + ": " + errorMsgs.get(0));
            }
            storedConfig.writeSetting(setting, profileID, storedValue, loggedInUser);
        } catch (Exception e) {
            final String errorMsg = "error writing default value for setting " + setting.toString() + ", error: " + e.getMessage();
            LOGGER.error(errorMsg, e);
            throw new IllegalStateException(errorMsg, e);
        }
        returnMap.put("key", key);
        returnMap.put("category", setting.getCategory().toString());
        returnMap.put("syntax", setting.getSyntax().toString());
        returnMap.put("isDefault", storedConfig.isDefaultValue(setting, profileID));
    }
    pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
    return ProcessStatus.Halt;
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) UserIdentity(password.pwm.bean.UserIdentity) StoredValue(password.pwm.config.StoredValue) 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) LinkedHashMap(java.util.LinkedHashMap) PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) StringTokenizer(java.util.StringTokenizer)

Aggregations

ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)21 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)10 PwmException (password.pwm.error.PwmException)9 RestResultBean (password.pwm.ws.server.RestResultBean)9 PwmSetting (password.pwm.config.PwmSetting)7 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)7 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)6 IOException (java.io.IOException)6 Instant (java.time.Instant)6 LinkedHashMap (java.util.LinkedHashMap)6 ServletException (javax.servlet.ServletException)6 ErrorInformation (password.pwm.error.ErrorInformation)6 PwmOperationalException (password.pwm.error.PwmOperationalException)6 Configuration (password.pwm.config.Configuration)5 PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)5 HealthData (password.pwm.ws.server.rest.bean.HealthData)5 StringTokenizer (java.util.StringTokenizer)4 UserIdentity (password.pwm.bean.UserIdentity)4 HealthRecord (password.pwm.health.HealthRecord)4 ArrayList (java.util.ArrayList)3