Search in sources :

Example 1 with ProvisioningError

use of com.tremolosecurity.provisioning.service.util.ProvisioningError 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)

Example 2 with ProvisioningError

use of com.tremolosecurity.provisioning.service.util.ProvisioningError in project OpenUnison by TremoloSecurity.

the class ExecutedWorkflows method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String userKey = req.getParameter("user");
    Session session = null;
    try {
        session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getHibernateSessionFactory().openSession();
        // PreparedStatement ps = con.prepareStatement("select workflows.id,workflows.name from workflows inner join users on users.id=workflows.userid where workflows.completeTS IS NOT NULL AND userKey=?");
        Query query = session.createQuery("FROM Workflows WHERE Workflows.completeTS IS NOT NULL AND Workflows.users.userKey = :user_key");
        query.setParameter("user_key", userKey);
        List<com.tremolosecurity.provisioning.objects.Workflows> workflows = query.list();
        ArrayList<String> workflowids = new ArrayList<String>();
        for (Workflows wf : workflows) {
            if (wf.getApprovals().isEmpty()) {
                workflowids.add(wf.getName());
            } else {
                boolean approved = true;
                for (Approvals approval : wf.getApprovals()) {
                    approved = approved && (approval.getApproved() == 1 && approval.getApprovedTs() != null);
                }
            }
        }
        Gson gson = new Gson();
        ProvisioningResult resObj = new ProvisioningResult();
        resObj.setSuccess(true);
        resObj.setWorkflowIds(workflowids);
        resp.getOutputStream().println(gson.toJson(resObj));
    } catch (Exception e) {
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not load executed workflows : " + e.getMessage());
        ProvisioningResult res = new ProvisioningResult();
        res.setSuccess(false);
        res.setError(pe);
        Gson gson = new Gson();
        resp.getWriter().write(gson.toJson(res));
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : Query(org.hibernate.Query) Workflows(com.tremolosecurity.provisioning.objects.Workflows) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ArrayList(java.util.ArrayList) Approvals(com.tremolosecurity.provisioning.objects.Approvals) Gson(com.google.gson.Gson) ServletException(javax.servlet.ServletException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) Session(org.hibernate.Session)

Example 3 with ProvisioningError

use of com.tremolosecurity.provisioning.service.util.ProvisioningError in project OpenUnison by TremoloSecurity.

the class GenerateReport method doGet.

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    final Gson gson = new Gson();
    try {
        String name = req.getParameter("name");
        ReportType reportToRunTmp = null;
        boolean foundReport = false;
        for (ReportType report : GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getReports().getReport()) {
            if (report.getName().equalsIgnoreCase(name)) {
                reportToRunTmp = report;
                foundReport = true;
                break;
            }
        }
        if (!foundReport) {
            reportToRunTmp = null;
        }
        final ReportType reportToRun = reportToRunTmp;
        if (reportToRun == null) {
            throw new ProvisioningException("Could not find report");
        } else {
            Connection db = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            try {
                Session session = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getHibernateSessionFactory().openSession();
                session.doWork(new Work() {

                    public void execute(Connection connection) throws SQLException {
                        try {
                            generateReportData(req, resp, gson, reportToRun, connection);
                        } catch (IOException e) {
                            throw new SQLException("Could not run reports", e);
                        }
                    }
                });
            } finally {
            }
        }
    } catch (Exception e) {
        logger.error("Could not run report", e);
        resp.setStatus(500);
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not run report;" + e.getMessage());
        ProvisioningResult resObj = new ProvisioningResult();
        resObj.setSuccess(false);
        resObj.setError(pe);
        resp.getOutputStream().print(gson.toJson(resObj));
    }
}
Also used : SQLException(java.sql.SQLException) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) Connection(java.sql.Connection) Gson(com.google.gson.Gson) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ResultSet(java.sql.ResultSet) Work(org.hibernate.jdbc.Work) ReportType(com.tremolosecurity.config.xml.ReportType) Session(org.hibernate.Session)

Example 4 with ProvisioningError

use of com.tremolosecurity.provisioning.service.util.ProvisioningError in project OpenUnison by TremoloSecurity.

the class ListApprovals method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String approver = req.getParameter("approver");
    int approvalID = Integer.parseInt(req.getParameter("approvalID"));
    Connection con = null;
    Gson gson = new Gson();
    if (approvalID == 0) {
        // list all approvals
        try {
            ProvisioningResult pres = new ProvisioningResult();
            pres.setSuccess(true);
            pres.setSummaries(ServiceActions.listOpenApprovals(approver, GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getApprovalDB().getUserIdAttribute(), GlobalEntries.getGlobalEntries().getConfigManager()));
            resp.getOutputStream().print(gson.toJson(pres));
        } catch (ProvisioningException e) {
            ProvisioningError pe = new ProvisioningError();
            pe.setError("Could not load executed workflows : " + e.getMessage());
            ProvisioningResult res = new ProvisioningResult();
            res.setSuccess(false);
            res.setError(pe);
            resp.getWriter().write(gson.toJson(res));
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                }
            }
        }
    } else {
        try {
            ProvisioningResult pres = new ProvisioningResult();
            pres.setSuccess(true);
            pres.setApprovalDetail(ServiceActions.loadApprovalDetails(approver, approvalID));
            resp.getOutputStream().print(gson.toJson(pres));
        } catch (Throwable e) {
            logger.error("Could not load approval", e);
            ProvisioningError pe = new ProvisioningError();
            pe.setError("Could not load executed approval : " + e.getMessage());
            ProvisioningResult res = new ProvisioningResult();
            res.setSuccess(false);
            res.setError(pe);
            resp.getWriter().write(gson.toJson(res));
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) SQLException(java.sql.SQLException) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Connection(java.sql.Connection) Gson(com.google.gson.Gson)

Example 5 with ProvisioningError

use of com.tremolosecurity.provisioning.service.util.ProvisioningError in project OpenUnison by TremoloSecurity.

the class ListOrgs method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String userID = req.getParameter("uid");
    String uidAttr = req.getParameter("uidAttr");
    try {
        StringBuffer b = new StringBuffer();
        b.append("(").append(uidAttr).append("=").append(userID).append(")");
        LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(uidAttr, userID).toString(), new ArrayList<String>());
        if (!res.hasMore()) {
            throw new ProvisioningException("Could not locate user '" + userID + "'");
        }
        LDAPEntry entry = res.next();
        AuthInfo auinfo = new AuthInfo();
        auinfo.setUserDN(entry.getDN());
        LDAPAttributeSet attrs = entry.getAttributeSet();
        for (Object obj : attrs) {
            LDAPAttribute attr = (LDAPAttribute) obj;
            Attribute attrib = new Attribute(attr.getName());
            String[] vals = attr.getStringValueArray();
            for (String val : vals) {
                attrib.getValues().add(val);
            }
            auinfo.getAttribs().put(attrib.getName(), attrib);
        }
        AzSys az = new AzSys();
        OrgType ot = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
        Organization org = new Organization();
        copyOrg(org, ot, az, auinfo);
        Gson gson = new Gson();
        ProvisioningResult pres = new ProvisioningResult();
        pres.setSuccess(true);
        pres.setOrg(org);
        resp.getOutputStream().print(gson.toJson(pres));
    } catch (Exception e) {
        ProvisioningError pe = new ProvisioningError();
        pe.setError("Could not load orgs : " + e.getMessage());
        ProvisioningResult res = new ProvisioningResult();
        res.setSuccess(false);
        res.setError(pe);
        Gson gson = new Gson();
        resp.getWriter().write(gson.toJson(res));
        logger.error("Could not load orgs", e);
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) Organization(com.tremolosecurity.provisioning.service.util.Organization) LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) ProvisioningResult(com.tremolosecurity.provisioning.service.util.ProvisioningResult) Gson(com.google.gson.Gson) LDAPException(com.novell.ldap.LDAPException) ServletException(javax.servlet.ServletException) MalformedURLException(java.net.MalformedURLException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) ProvisioningError(com.tremolosecurity.provisioning.service.util.ProvisioningError) OrgType(com.tremolosecurity.config.xml.OrgType) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) AzSys(com.tremolosecurity.proxy.auth.AzSys)

Aggregations

Gson (com.google.gson.Gson)10 ProvisioningError (com.tremolosecurity.provisioning.service.util.ProvisioningError)10 ProvisioningResult (com.tremolosecurity.provisioning.service.util.ProvisioningResult)10 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)8 IOException (java.io.IOException)6 ServletException (javax.servlet.ServletException)6 Attribute (com.tremolosecurity.saml.Attribute)5 LDAPAttribute (com.novell.ldap.LDAPAttribute)4 LDAPEntry (com.novell.ldap.LDAPEntry)4 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)4 ArrayList (java.util.ArrayList)4 LDAPAttributeSet (com.novell.ldap.LDAPAttributeSet)3 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)3 AzSys (com.tremolosecurity.proxy.auth.AzSys)3 SQLException (java.sql.SQLException)3 ConfigManager (com.tremolosecurity.config.util.ConfigManager)2 OrgType (com.tremolosecurity.config.xml.OrgType)2 ReportType (com.tremolosecurity.config.xml.ReportType)2 MalformedURLException (java.net.MalformedURLException)2 Connection (java.sql.Connection)2