Search in sources :

Example 26 with ParamType

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

the class LoadAuthMechsFromK8s method createAuthMech.

private MechanismType createAuthMech(JSONObject item, String name) throws Exception {
    MechanismType mechType = new MechanismType();
    JSONObject spec = (JSONObject) item.get("spec");
    mechType.setName(name);
    mechType.setClassName((String) spec.get("className"));
    mechType.setUri((String) spec.get("uri"));
    mechType.setInit(new ConfigType());
    mechType.setParams(new ParamListType());
    JSONObject params = (JSONObject) spec.get("init");
    for (Object o : params.keySet()) {
        String keyName = (String) o;
        Object v = params.get(keyName);
        if (v instanceof String) {
            String val = (String) v;
            ParamType pt = new ParamType();
            pt.setName(keyName);
            pt.setValue(val);
            mechType.getInit().getParam().add(pt);
        } else if (v instanceof JSONArray) {
            for (Object ov : ((JSONArray) v)) {
                ParamType pt = new ParamType();
                pt.setName(keyName);
                pt.setValue((String) ov);
                mechType.getInit().getParam().add(pt);
            }
        }
    }
    JSONArray secretParams = (JSONArray) spec.get("secretParams");
    if (secretParams != null) {
        HttpCon nonwatchHttp = this.k8sWatch.getK8s().createClient();
        String token = this.k8sWatch.getK8s().getAuthToken();
        try {
            for (Object o : secretParams) {
                JSONObject secretParam = (JSONObject) o;
                String paramName = (String) secretParam.get("name");
                String secretName = (String) secretParam.get("secretName");
                String secretKey = (String) secretParam.get("secretKey");
                String secretValue = this.k8sWatch.getSecretValue(secretName, secretKey, token, nonwatchHttp);
                ParamType pt = new ParamType();
                pt.setName(paramName);
                pt.setValue(secretValue);
                mechType.getInit().getParam().add(pt);
            }
        } finally {
            nonwatchHttp.getHttp().close();
            nonwatchHttp.getBcm().close();
        }
    }
    return mechType;
}
Also used : HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JSONObject(org.json.simple.JSONObject) ParamListType(com.tremolosecurity.config.xml.ParamListType) JSONArray(org.json.simple.JSONArray) MechanismType(com.tremolosecurity.config.xml.MechanismType) JSONObject(org.json.simple.JSONObject) ConfigType(com.tremolosecurity.config.xml.ConfigType) ParamType(com.tremolosecurity.config.xml.ParamType)

Example 27 with ParamType

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

the class LoadWorkflowsFromK8s method createWorkflow.

private WorkflowType createWorkflow(JSONObject item, String name) throws ProvisioningException {
    WorkflowType wft = new WorkflowType();
    JSONObject spec = (JSONObject) item.get("spec");
    String jsonString = spec.toJSONString();
    StringBuffer b = new StringBuffer();
    b.setLength(0);
    OpenUnisonConfigLoader.integrateIncludes(b, jsonString);
    try {
        spec = (JSONObject) new JSONParser().parse(b.toString());
    } catch (ParseException e1) {
        throw new ProvisioningException("Could not parse workflow", e1);
    }
    wft.setName(name);
    wft.setInList(((Boolean) spec.get("inList")));
    wft.setLabel((String) spec.get("label"));
    wft.setOrgid((String) spec.get("orgId"));
    wft.setDescription((String) spec.get("description"));
    JSONObject dynWfJson = (JSONObject) spec.get("dynamicConfiguration");
    if (dynWfJson != null) {
        DynamicWorkflowType dwt = new DynamicWorkflowType();
        wft.setDynamicConfiguration(dwt);
        Boolean isdyn = (Boolean) dynWfJson.get("dynamic");
        if (isdyn != null) {
            dwt.setDynamic(isdyn.booleanValue());
        }
        dwt.setClassName((String) dynWfJson.get("className"));
        JSONArray params = (JSONArray) dynWfJson.get("params");
        for (Object o : params) {
            JSONObject p = (JSONObject) o;
            ParamType pt = new ParamType();
            pt.setName((String) p.get("name"));
            pt.setValue((String) p.get("value"));
            dwt.getParam().add(pt);
        }
    }
    String wfJson = null;
    try {
        wfJson = convertYamlToJson((String) spec.get("tasks"));
        ParsedWorkflow pw = new ParseWorkflow().parseWorkflow(wfJson);
        if (pw.getError() != null) {
            throw new ProvisioningException("Invalid workflow '" + pw.getError() + "', path='" + pw.getErrorPath() + "'");
        }
        wft.setTasks(pw.getWft().getTasks());
    } catch (JsonProcessingException e) {
        throw new ProvisioningException("Could not parse workflow tasks for '" + name + "'", e);
    }
    return wft;
}
Also used : JSONArray(org.json.simple.JSONArray) DynamicWorkflowType(com.tremolosecurity.config.xml.DynamicWorkflowType) ParamType(com.tremolosecurity.config.xml.ParamType) JSONObject(org.json.simple.JSONObject) DynamicWorkflowType(com.tremolosecurity.config.xml.DynamicWorkflowType) WorkflowType(com.tremolosecurity.config.xml.WorkflowType) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

ParamType (com.tremolosecurity.config.xml.ParamType)27 HashMap (java.util.HashMap)17 Attribute (com.tremolosecurity.saml.Attribute)14 IOException (java.io.IOException)12 LDAPAttribute (com.novell.ldap.LDAPAttribute)8 AuthMechParamType (com.tremolosecurity.config.xml.AuthMechParamType)7 DynamicPortalUrlsType (com.tremolosecurity.config.xml.DynamicPortalUrlsType)7 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)7 FileNotFoundException (java.io.FileNotFoundException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 JAXBException (javax.xml.bind.JAXBException)7 JSONObject (org.json.simple.JSONObject)7 JSONArray (org.json.simple.JSONArray)6 ApplicationType (com.tremolosecurity.config.xml.ApplicationType)5 TrustType (com.tremolosecurity.config.xml.TrustType)5 ServletException (javax.servlet.ServletException)5 LDAPException (com.novell.ldap.LDAPException)4 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)4 KeyStoreException (java.security.KeyStoreException)4 UnrecoverableKeyException (java.security.UnrecoverableKeyException)4