use of password.pwm.config.SettingUIFunction 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;
}
Aggregations