Search in sources :

Example 1 with ApprovalData

use of com.tremolosecurity.provisioning.workflow.ApprovalData in project OpenUnison by TremoloSecurity.

the class ExecuteWorkflow method doPost.

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Gson gson = new Gson();
    String wfcall = req.getParameter("wfcall");
    if (wfcall == null) {
        logger.error("Could not get workflow call");
        resp.setStatus(500);
        ProvisioningError pe = new ProvisioningError();
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(false);
        pres.setError(pe);
        pe.setError("Could not get workflow call");
        gson = new Gson();
        resp.getOutputStream().print(gson.toJson(pres));
        return;
    }
    String line;
    StringBuffer json = new StringBuffer();
    BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(wfcall.getBytes("UTF-8"))));
    while ((line = in.readLine()) != null) {
        json.append(line).append('\n');
    }
    WFCall wfCall = gson.fromJson(json.toString(), WFCall.class);
    if (wfCall == null) {
        logger.error("Could not get workflow call");
        resp.setStatus(500);
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not get workflow call");
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(false);
        pres.setError(pe);
        gson = new Gson();
        resp.getOutputStream().print(gson.toJson(pres));
        return;
    }
    List<ApprovalData> autoApprovals = null;
    try {
        // TremoloContext.getContext().getConfigManager("proxy").getProvisioningEngine().getWorkFlow(wfCall.getName()).executeWorkflow(wfCall);
        com.tremolosecurity.provisioning.workflow.ExecuteWorkflow exec = new com.tremolosecurity.provisioning.workflow.ExecuteWorkflow();
        exec.execute(wfCall, GlobalEntries.getGlobalEntries().getConfigManager());
        ProvisioningResult res = new ProvisioningResult();
        res.setSuccess(true);
        resp.getOutputStream().print(gson.toJson(res));
    } catch (Throwable t) {
        logger.error("Error executing workflow", t);
        resp.setStatus(500);
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Error executing workflow");
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(false);
        pres.setError(pe);
        gson = new Gson();
        resp.getOutputStream().print(gson.toJson(pres));
    }
}
Also used : WFCall(com.tremolosecurity.provisioning.service.util.WFCall) InputStreamReader(java.io.InputStreamReader) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) Gson(com.google.gson.Gson) ApprovalData(com.tremolosecurity.provisioning.workflow.ApprovalData) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader)

Aggregations

Gson (com.google.gson.Gson)1 ProvisioningError (com.tremolosecurity.provisioning.service.util.ProvisioningError)1 ProvisioningResult (com.tremolosecurity.provisioning.service.util.ProvisioningResult)1 WFCall (com.tremolosecurity.provisioning.service.util.WFCall)1 ApprovalData (com.tremolosecurity.provisioning.workflow.ApprovalData)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1