Search in sources :

Example 1 with CustomTaskType

use of com.tremolosecurity.config.xml.CustomTaskType in project OpenUnison by TremoloSecurity.

the class CustomTask method init.

@Override
public void init(WorkflowTaskType taskConfig) throws ProvisioningException {
    CustomTaskType taskCfg = (CustomTaskType) taskConfig;
    this.className = taskCfg.getClassName();
    params = new HashMap<String, Attribute>();
    for (ParamWithValueType pt : taskCfg.getParam()) {
        Attribute attr = params.get(pt.getName());
        if (attr == null) {
            attr = new Attribute(pt.getName());
            params.put(pt.getName(), attr);
        }
        if (pt.getValueAttribute() != null) {
            attr.getValues().add(pt.getValueAttribute());
        } else {
            attr.getValues().add(pt.getValue());
        }
    }
    try {
        this.task = (com.tremolosecurity.provisioning.util.CustomTask) Class.forName(this.className).newInstance();
        this.task.init(this, params);
    } catch (Exception e) {
        throw new ProvisioningException("Could not initialize custom task", e);
    }
}
Also used : Attribute(com.tremolosecurity.saml.Attribute) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) CustomTaskType(com.tremolosecurity.config.xml.CustomTaskType)

Example 2 with CustomTaskType

use of com.tremolosecurity.config.xml.CustomTaskType in project OpenUnison by TremoloSecurity.

the class ParseWorkflow method createCustomTask.

private void createCustomTask(JSONObject node, String path, List<WorkflowTaskType> parent, ParsedWorkflow pw) {
    CustomTaskType task = new CustomTaskType();
    OptionType[] options = new OptionType[] { new OptionType("className", true, OptionType.OptionValueType.STRING) };
    for (OptionType ot : options) {
        setAttribute(node, ot, task, CustomTaskType.class, pw, path);
        if (pw.getError() != null) {
            return;
        }
    }
    Object op = node.get("params");
    if (op != null) {
        if (!(op instanceof JSONObject)) {
            pw.setError("params must be an object");
            pw.setErrorPath(path + ".params");
            return;
        }
        int ii = 0;
        JSONObject params = (JSONObject) op;
        for (Object key : params.keySet()) {
            if (!(key instanceof String)) {
                pw.setError("parameter key must be a string");
                pw.setErrorPath(path + ".params[" + ii + "]");
                return;
            }
            String paramName = (String) key;
            Object vals = params.get(paramName);
            if (vals instanceof String) {
                ParamWithValueType pt = new ParamWithValueType();
                pt.setName(paramName);
                pt.setValue((String) vals);
                task.getParam().add(pt);
            } else if (vals instanceof JSONArray) {
                JSONArray jsonVals = (JSONArray) vals;
                int ll = 0;
                for (Object v : jsonVals) {
                    if (!(v instanceof String)) {
                        pw.setError("all values of a parameter must be a string");
                        pw.setErrorPath(path + ".params[" + ii + "][" + ll + "]");
                        return;
                    }
                    ParamWithValueType pt = new ParamWithValueType();
                    pt.setName(paramName);
                    pt.setValue((String) v);
                    task.getParam().add(pt);
                    ll++;
                }
            } else {
                pw.setError("parameter value must be a string or a list of strings");
                pw.setErrorPath(path + ".params[" + ii + "]");
                return;
            }
            ii++;
        }
        node.remove("params");
    }
    if (!node.isEmpty()) {
        pw.setError("Extra JSON keys : " + node.toString());
        pw.setErrorPath(path);
        return;
    }
    parent.add(task);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType) CustomTaskType(com.tremolosecurity.config.xml.CustomTaskType)

Aggregations

CustomTaskType (com.tremolosecurity.config.xml.CustomTaskType)2 ParamWithValueType (com.tremolosecurity.config.xml.ParamWithValueType)2 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 Attribute (com.tremolosecurity.saml.Attribute)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1