Search in sources :

Example 1 with ProvisionMappingType

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

the class ParseWorkflow method createMappingTask.

private void createMappingTask(JSONObject node, String path, List<WorkflowTaskType> parent, ParsedWorkflow pw) {
    MappingType task = new MappingType();
    OptionType[] options = new OptionType[] { new OptionType("strict", false, OptionType.OptionValueType.BOOLEAN) };
    for (OptionType ot : options) {
        setAttribute(node, ot, task, MappingType.class, pw, path);
        if (pw.getError() != null) {
            return;
        }
    }
    task.setMap(new ProvisionMappingsType());
    Object o = node.get("map");
    node.remove("map");
    if (o == null) {
        pw.setError("map required and must be an array");
        pw.setErrorPath(path);
        return;
    }
    if (!(o instanceof JSONArray)) {
        pw.setError("map must be an array");
        pw.setErrorPath(path);
        return;
    }
    int ii = 0;
    JSONArray map = (JSONArray) o;
    for (Object oo : map) {
        if (!(oo instanceof JSONObject)) {
            pw.setError("All map entries must be objects");
            pw.setErrorPath(path + ".map[" + ii + "]");
            ii++;
            return;
        }
        JSONObject mapNode = (JSONObject) oo;
        options = new OptionType[] { new OptionType("targetAttributeName", true, OptionType.OptionValueType.STRING), new OptionType("sourceType", true, OptionType.OptionValueType.STRING), new OptionType("targetAttributeSource", true, OptionType.OptionValueType.STRING) };
        ProvisionMappingType pmt = new ProvisionMappingType();
        for (OptionType ot : options) {
            setAttribute(mapNode, ot, pmt, ProvisionMappingType.class, pw, path);
            if (pw.getError() != null) {
                return;
            }
        }
        if (!mapNode.isEmpty()) {
            pw.setError("Extra JSON keys : " + mapNode.toString());
            pw.setErrorPath(path + ".map[" + ii + "]");
            return;
        }
        task.getMap().getMapping().add(pmt);
    }
    loadSubTasks(node, path, pw, task);
    if (pw.getError() != null) {
        return;
    }
    if (!node.isEmpty()) {
        pw.setError("Extra JSON keys : " + node.toString());
        pw.setErrorPath(path);
        return;
    }
    parent.add(task);
}
Also used : ProvisionMappingType(com.tremolosecurity.config.xml.ProvisionMappingType) MappingType(com.tremolosecurity.config.xml.MappingType) ProvisionMappingsType(com.tremolosecurity.config.xml.ProvisionMappingsType) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) ProvisionMappingType(com.tremolosecurity.config.xml.ProvisionMappingType)

Example 2 with ProvisionMappingType

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

the class LoadApplicationsFromK8s method createIdpOnUrl.

private void createIdpOnUrl(JSONObject jsonUrl, UrlType url) throws ProvisioningException, Exception {
    IdpType idp = new IdpType();
    JSONObject jsonIdp = (JSONObject) jsonUrl.get("idp");
    url.setIdp(idp);
    idp.setClassName((String) jsonIdp.get("className"));
    JSONObject params = (JSONObject) jsonIdp.get("params");
    if (params != null) {
        for (Object x : params.keySet()) {
            String paramName = (String) x;
            Object z = params.get(paramName);
            if (z instanceof String) {
                ParamType pt = new ParamType();
                pt.setName(paramName);
                pt.setValue((String) z);
                idp.getParams().add(pt);
            } else {
                JSONArray values = (JSONArray) z;
                for (Object y : values) {
                    ParamType pt = new ParamType();
                    pt.setName(paramName);
                    pt.setValue((String) y);
                    idp.getParams().add(pt);
                }
            }
        }
    }
    JSONArray secretParams = (JSONArray) jsonIdp.get("secretParams");
    if (secretParams != null) {
        HttpCon nonwatchHttp = this.k8sWatch.getK8s().createClient();
        String token = this.k8sWatch.getK8s().getAuthToken();
        try {
            for (Object ox : secretParams) {
                JSONObject secretParam = (JSONObject) ox;
                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);
                idp.getParams().add(pt);
            }
        } finally {
            nonwatchHttp.getHttp().close();
            nonwatchHttp.getBcm().close();
        }
    }
    JSONObject mappings = (JSONObject) jsonIdp.get("mappings");
    if (mappings != null) {
        IdpMappingType idpMappingType = new IdpMappingType();
        idpMappingType.setStrict(getBoolValue(mappings.get("strict"), true));
        JSONArray jsonMap = (JSONArray) mappings.get("map");
        if (jsonMap != null) {
            for (Object x : jsonMap) {
                JSONObject map = (JSONObject) x;
                ProvisionMappingType pmt = new ProvisionMappingType();
                pmt.setTargetAttributeName((String) map.get("targetAttributeName"));
                pmt.setTargetAttributeSource((String) map.get("targetAttributeSource"));
                pmt.setSourceType((String) map.get("sourceType"));
                idpMappingType.getMapping().add(pmt);
            }
        }
        idp.setMappings(idpMappingType);
    }
    JSONArray jsonTrusts = (JSONArray) jsonIdp.get("trusts");
    if (jsonTrusts != null) {
        TrustsType tt = new TrustsType();
        for (Object o : jsonTrusts) {
            JSONObject jsonTrust = (JSONObject) o;
            TrustType trust = new TrustType();
            trust.setName((String) jsonTrust.get("name"));
            params = (JSONObject) jsonTrust.get("params");
            if (params != null) {
                for (Object x : params.keySet()) {
                    String paramName = (String) x;
                    Object z = params.get(paramName);
                    if (z instanceof String) {
                        ParamType pt = new ParamType();
                        pt.setName(paramName);
                        pt.setValue((String) z);
                        trust.getParam().add(pt);
                    } else {
                        JSONArray values = (JSONArray) z;
                        for (Object y : values) {
                            ParamType pt = new ParamType();
                            pt.setName(paramName);
                            pt.setValue((String) y);
                            trust.getParam().add(pt);
                        }
                    }
                }
            }
            secretParams = (JSONArray) jsonTrust.get("secretParams");
            if (secretParams != null) {
                HttpCon nonwatchHttp = this.k8sWatch.getK8s().createClient();
                String token = this.k8sWatch.getK8s().getAuthToken();
                try {
                    for (Object ox : secretParams) {
                        JSONObject secretParam = (JSONObject) ox;
                        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);
                        trust.getParam().add(pt);
                    }
                } finally {
                    nonwatchHttp.getHttp().close();
                    nonwatchHttp.getBcm().close();
                }
            }
            tt.getTrust().add(trust);
        }
        idp.setTrusts(tt);
    }
}
Also used : IdpType(com.tremolosecurity.config.xml.IdpType) TrustsType(com.tremolosecurity.config.xml.TrustsType) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) TrustType(com.tremolosecurity.config.xml.TrustType) JSONObject(org.json.simple.JSONObject) ProvisionMappingType(com.tremolosecurity.config.xml.ProvisionMappingType) IdpMappingType(com.tremolosecurity.config.xml.IdpMappingType) AuthMechParamType(com.tremolosecurity.config.xml.AuthMechParamType) ParamType(com.tremolosecurity.config.xml.ParamType)

Aggregations

ProvisionMappingType (com.tremolosecurity.config.xml.ProvisionMappingType)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 AuthMechParamType (com.tremolosecurity.config.xml.AuthMechParamType)1 IdpMappingType (com.tremolosecurity.config.xml.IdpMappingType)1 IdpType (com.tremolosecurity.config.xml.IdpType)1 MappingType (com.tremolosecurity.config.xml.MappingType)1 ParamType (com.tremolosecurity.config.xml.ParamType)1 ProvisionMappingsType (com.tremolosecurity.config.xml.ProvisionMappingsType)1 TrustType (com.tremolosecurity.config.xml.TrustType)1 TrustsType (com.tremolosecurity.config.xml.TrustsType)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1