use of password.pwm.config.StoredValue 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