Search in sources :

Example 1 with WorkflowType

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

the class LoadWorkflowsFromK8s method addObject.

@Override
public void addObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
    JSONObject metadata = (JSONObject) item.get("metadata");
    String name = (String) metadata.get("name");
    logger.info("Creating workflow '" + name + "'");
    WorkflowType newWorkflow = this.createWorkflow(item, name);
    synchronized (this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow()) {
        int index = -1;
        int i = 0;
        for (WorkflowType wt : this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow()) {
            if (wt.getName().equals(name)) {
                index = i;
                break;
            }
            i++;
        }
        if (index != -1) {
            this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow().remove(index);
        }
        this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow().add(newWorkflow);
    }
    try {
        this.provisioningEngine.addDynamicWorkflow(newWorkflow);
    } catch (Throwable e) {
        logger.warn("Could not add workflow '" + name + "'", e);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) DynamicWorkflowType(com.tremolosecurity.config.xml.DynamicWorkflowType) WorkflowType(com.tremolosecurity.config.xml.WorkflowType)

Example 2 with WorkflowType

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

the class LoadWorkflowsFromK8s method modifyObject.

@Override
public void modifyObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
    JSONObject metadata = (JSONObject) item.get("metadata");
    String name = (String) metadata.get("name");
    logger.info("Replacing workflow '" + name + "'");
    WorkflowType newWorkflow = this.createWorkflow(item, name);
    synchronized (this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow()) {
        int index = -1;
        int i = 0;
        for (WorkflowType wt : this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow()) {
            if (wt.getName().equals(name)) {
                index = i;
                break;
            }
            i++;
        }
        if (index != -1) {
            this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow().remove(index);
        }
        this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow().add(newWorkflow);
    }
    this.provisioningEngine.replaceDynamicWorkflow(newWorkflow);
}
Also used : JSONObject(org.json.simple.JSONObject) DynamicWorkflowType(com.tremolosecurity.config.xml.DynamicWorkflowType) WorkflowType(com.tremolosecurity.config.xml.WorkflowType)

Example 3 with WorkflowType

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

the class LoadWorkflowsFromK8s method deleteObject.

@Override
public void deleteObject(TremoloType cfg, JSONObject item) throws ProvisioningException {
    JSONObject metadata = (JSONObject) item.get("metadata");
    String name = (String) metadata.get("name");
    logger.info("Deleting workflow '" + name + "'");
    synchronized (this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow()) {
        int index = -1;
        int i = 0;
        for (WorkflowType wt : this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow()) {
            if (wt.getName().equals(name)) {
                index = i;
                break;
            }
            i++;
        }
        if (index != -1) {
            this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow().remove(index);
        }
    }
    this.provisioningEngine.removeDynamicWorkflow(name);
}
Also used : JSONObject(org.json.simple.JSONObject) DynamicWorkflowType(com.tremolosecurity.config.xml.DynamicWorkflowType) WorkflowType(com.tremolosecurity.config.xml.WorkflowType)

Example 4 with WorkflowType

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

the class SendMessageThread method generateWorkflows.

private void generateWorkflows() throws ProvisioningException {
    if (cfgMgr.getCfg().getProvisioning() == null) {
        return;
    }
    for (WorkflowType wt : this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Processing call workflow - '" + wt.getName() + "'");
        }
        if (logger.isDebugEnabled()) {
            logger.debug(jaxbObjectToXML(wt));
        }
    }
    Iterator<WorkflowType> it = this.cfgMgr.getCfg().getProvisioning().getWorkflows().getWorkflow().iterator();
    while (it.hasNext()) {
        WorkflowType wft = it.next();
        String name = wft.getName();
        logger.info("Processing workflow - '" + name + "'");
        WorkflowImpl wf = new WorkflowImpl(this.cfgMgr, wft);
        this.workflows.put(name, wf);
    }
}
Also used : WorkflowType(com.tremolosecurity.config.xml.WorkflowType)

Example 5 with WorkflowType

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

the class ScaleMain method loadWorkflows.

private void loadWorkflows(HttpFilterRequest request, HttpFilterResponse response, Gson gson) throws Exception {
    String orgid = request.getRequestURI().substring(request.getRequestURI().lastIndexOf('/') + 1);
    ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
    HashSet<String> allowedOrgs = new HashSet<String>();
    AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
    OrgType ot = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
    AzSys az = new AzSys();
    this.checkOrg(allowedOrgs, ot, az, userData, request.getSession());
    if (!allowedOrgs.contains(orgid)) {
        response.setStatus(401);
        response.setContentType("application/json");
        ScaleError error = new ScaleError();
        error.getErrors().add("Unauthorized");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().print(gson.toJson(error).trim());
        response.getWriter().flush();
    } else {
        List<WorkflowType> wfs = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getWorkflows().getWorkflow();
        ArrayList<WFDescription> workflows = new ArrayList<WFDescription>();
        for (WorkflowType wf : wfs) {
            if (wf.isInList() != null && wf.isInList().booleanValue()) {
                if (wf.getOrgid() == null || wf.getOrgid().equalsIgnoreCase(orgid)) {
                    if (wf.getDynamicConfiguration() != null && wf.getDynamicConfiguration().isDynamic()) {
                        HashMap<String, Attribute> params = new HashMap<String, Attribute>();
                        if (wf.getDynamicConfiguration().getParam() != null) {
                            for (ParamType p : wf.getDynamicConfiguration().getParam()) {
                                Attribute attr = params.get(p.getName());
                                if (attr == null) {
                                    attr = new Attribute(p.getName());
                                    params.put(p.getName(), attr);
                                }
                                attr.getValues().add(p.getValue());
                            }
                        }
                        DynamicWorkflow dwf = (DynamicWorkflow) Class.forName(wf.getDynamicConfiguration().getClassName()).newInstance();
                        List<Map<String, String>> wfParams = dwf.generateWorkflows(wf, cfgMgr, params, userData);
                        StringBuffer b = new StringBuffer();
                        b.append('/').append(URLEncoder.encode(wf.getName(), "UTF-8"));
                        String uri = b.toString();
                        for (Map<String, String> wfParamSet : wfParams) {
                            DateTime now = new DateTime();
                            DateTime expires = now.plusHours(1);
                            LastMile lm = new LastMile(uri, now, expires, 0, "");
                            for (String key : wfParamSet.keySet()) {
                                String val = wfParamSet.get(key);
                                Attribute attr = new Attribute(key, val);
                                lm.getAttributes().add(attr);
                            }
                            WFDescription desc = new WFDescription();
                            desc.setUuid(UUID.randomUUID().toString());
                            desc.setName(wf.getName());
                            ST st = new ST(wf.getLabel(), '$', '$');
                            for (String key : wfParamSet.keySet()) {
                                st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key));
                            }
                            desc.setLabel(st.render());
                            st = new ST(wf.getDescription(), '$', '$');
                            for (String key : wfParamSet.keySet()) {
                                st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key));
                            }
                            desc.setDescription(st.render());
                            desc.setEncryptedParams(lm.generateLastMileToken(cfgMgr.getSecretKey(cfgMgr.getCfg().getProvisioning().getApprovalDB().getEncryptionKey())));
                            workflows.add(desc);
                        }
                    } else {
                        WFDescription desc = new WFDescription();
                        desc.setUuid(UUID.randomUUID().toString());
                        desc.setName(wf.getName());
                        desc.setLabel(wf.getLabel());
                        desc.setDescription(wf.getDescription());
                        workflows.add(desc);
                    }
                }
            }
        }
        ScaleJSUtils.addCacheHeaders(response);
        response.setContentType("application/json");
        response.getWriter().println(gson.toJson(workflows).trim());
        response.getWriter().flush();
    }
}
Also used : Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) DateTime(org.joda.time.DateTime) WFDescription(com.tremolosecurity.provisioning.service.util.WFDescription) DynamicWorkflow(com.tremolosecurity.provisioning.util.DynamicWorkflow) HashSet(java.util.HashSet) ST(org.stringtemplate.v4.ST) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) ScaleError(com.tremolosecurity.scalejs.data.ScaleError) AuthController(com.tremolosecurity.proxy.auth.AuthController) ConfigManager(com.tremolosecurity.config.util.ConfigManager) ParamType(com.tremolosecurity.config.xml.ParamType) LastMile(com.tremolosecurity.lastmile.LastMile) OrgType(com.tremolosecurity.config.xml.OrgType) WorkflowType(com.tremolosecurity.config.xml.WorkflowType) AzSys(com.tremolosecurity.proxy.auth.AzSys) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

WorkflowType (com.tremolosecurity.config.xml.WorkflowType)11 DynamicWorkflowType (com.tremolosecurity.config.xml.DynamicWorkflowType)4 ParamType (com.tremolosecurity.config.xml.ParamType)4 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)4 Attribute (com.tremolosecurity.saml.Attribute)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 OrgType (com.tremolosecurity.config.xml.OrgType)3 LastMile (com.tremolosecurity.lastmile.LastMile)3 AuthController (com.tremolosecurity.proxy.auth.AuthController)3 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)3 AzSys (com.tremolosecurity.proxy.auth.AzSys)3 IOException (java.io.IOException)3 JSONObject (org.json.simple.JSONObject)3 Gson (com.google.gson.Gson)2 LDAPAttribute (com.novell.ldap.LDAPAttribute)2 LDAPException (com.novell.ldap.LDAPException)2 ConfigManager (com.tremolosecurity.config.util.ConfigManager)2 AzRuleType (com.tremolosecurity.config.xml.AzRuleType)2 PortalUrlType (com.tremolosecurity.config.xml.PortalUrlType)2