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