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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations