Search in sources :

Example 1 with SettingUIFunction

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

Aggregations

ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ServletException (javax.servlet.ServletException)1 PwmSetting (password.pwm.config.PwmSetting)1 SettingUIFunction (password.pwm.config.SettingUIFunction)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmException (password.pwm.error.PwmException)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)1 RestResultBean (password.pwm.ws.server.RestResultBean)1