Search in sources :

Example 1 with TargetType

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

the class LoadTargetsFromK8s method createTarget.

private TargetType createTarget(JSONObject item, String name) throws ProvisioningException {
    TargetType target = new TargetType();
    target.setName(name);
    target.setParams(new TargetConfigType());
    HttpCon nonwatchHttp = null;
    JSONObject spec = (JSONObject) item.get("spec");
    try {
        nonwatchHttp = this.k8sWatch.getK8s().createClient();
        String token = this.k8sWatch.getK8s().getAuthToken();
        StringBuffer b = new StringBuffer();
        b.setLength(0);
        OpenUnisonConfigLoader.integrateIncludes(b, (String) spec.get("className"));
        target.setClassName(b.toString());
        JSONArray params = (JSONArray) spec.get("params");
        for (Object o : params) {
            JSONObject param = (JSONObject) o;
            ParamType pt = new ParamType();
            b.setLength(0);
            OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("name"));
            pt.setName(b.toString());
            b.setLength(0);
            OpenUnisonConfigLoader.integrateIncludes(b, (String) param.get("value"));
            pt.setValue(b.toString());
            target.getParams().getParam().add(pt);
        }
        JSONArray secretParams = (JSONArray) spec.get("secretParams");
        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);
            target.getParams().getParam().add(pt);
        }
        JSONArray attrs = (JSONArray) spec.get("targetAttributes");
        for (Object o : attrs) {
            JSONObject attr = (JSONObject) o;
            TargetAttributeType ta = new TargetAttributeType();
            b.setLength(0);
            OpenUnisonConfigLoader.integrateIncludes(b, (String) attr.get("name"));
            ta.setName(b.toString());
            b.setLength(0);
            OpenUnisonConfigLoader.integrateIncludes(b, (String) attr.get("source"));
            ta.setSource(b.toString());
            ta.setSourceType((String) attr.get("sourceType"));
            ta.setTargetType((String) attr.get("targetType"));
            target.getTargetAttribute().add(ta);
        }
        synchronized (this.tremolo.getProvisioning().getTargets().getTarget()) {
            int found = -1;
            int ii = 0;
            for (TargetType tt : this.tremolo.getProvisioning().getTargets().getTarget()) {
                if (tt.getName().equals(target.getName())) {
                    found = ii;
                    break;
                }
                ii++;
            }
            if (found >= 0) {
                this.tremolo.getProvisioning().getTargets().getTarget().remove(found);
            }
            this.tremolo.getProvisioning().getTargets().getTarget().add(target);
        }
        return target;
    } catch (Exception e) {
        throw new ProvisioningException("Could not add target '" + name + "'", e);
    } finally {
        if (nonwatchHttp != null) {
            try {
                nonwatchHttp.getHttp().close();
            } catch (IOException e) {
            }
            nonwatchHttp.getBcm().close();
        }
    }
}
Also used : JSONArray(org.json.simple.JSONArray) IOException(java.io.IOException) ParamType(com.tremolosecurity.config.xml.ParamType) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException) TargetAttributeType(com.tremolosecurity.config.xml.TargetAttributeType) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JSONObject(org.json.simple.JSONObject) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) TargetType(com.tremolosecurity.config.xml.TargetType) TargetConfigType(com.tremolosecurity.config.xml.TargetConfigType) JSONObject(org.json.simple.JSONObject)

Example 2 with TargetType

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

the class LoadTargetsFromK8s 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 target '" + name + "'");
    TargetType target = createTarget(item, name);
    this.provisioningEngine.addDynamicTarget(cfgMgr, target);
}
Also used : JSONObject(org.json.simple.JSONObject) TargetType(com.tremolosecurity.config.xml.TargetType)

Example 3 with TargetType

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

the class LoadTargetsFromK8s 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 target '" + name + "'");
    TargetType target = this.createTarget(item, name);
    this.provisioningEngine.replaceTarget(cfgMgr, target);
}
Also used : JSONObject(org.json.simple.JSONObject) TargetType(com.tremolosecurity.config.xml.TargetType)

Example 4 with TargetType

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

the class ListClusters method getSourceList.

@Override
public List<NVP> getSourceList(HttpFilterRequest request) throws Exception {
    List<TargetType> targets = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getTargets().getTarget();
    List<NVP> k8sTargets = new ArrayList<NVP>();
    for (TargetType tt : targets) {
        if (tt.getClassName().equalsIgnoreCase("com.tremolosecurity.unison.openshiftv3.OpenShiftTarget")) {
            OpenShiftTarget target = (OpenShiftTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(tt.getName()).getProvider();
            k8sTargets.add(new NVP(target.getLabel(), tt.getName()));
        }
    }
    return k8sTargets;
}
Also used : TargetType(com.tremolosecurity.config.xml.TargetType) ArrayList(java.util.ArrayList) NVP(com.tremolosecurity.util.NVP) OpenShiftTarget(com.tremolosecurity.unison.openshiftv3.OpenShiftTarget)

Example 5 with TargetType

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

the class SendMessageThread method generateTargets.

private void generateTargets(ConfigManager cfgMgr) throws ProvisioningException {
    if (cfgMgr.getCfg().getProvisioning() == null) {
        return;
    }
    this.targetIDs = new HashMap<String, Targets>();
    Iterator<TargetType> it = cfgMgr.getCfg().getProvisioning().getTargets().getTarget().iterator();
    while (it.hasNext()) {
        TargetType targetCfg = it.next();
        addTarget(cfgMgr, targetCfg);
    }
    if (cfgMgr.getCfg().getProvisioning().getTargets().getDynamicTargets() != null && cfgMgr.getCfg().getProvisioning().getTargets().getDynamicTargets().isEnabled()) {
        DynamicPortalUrlsType dynamicTargets = cfgMgr.getCfg().getProvisioning().getTargets().getDynamicTargets();
        String className = dynamicTargets.getClassName();
        HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
        for (ParamType pt : dynamicTargets.getParams()) {
            Attribute attr = cfgAttrs.get(pt.getName());
            if (attr == null) {
                attr = new Attribute(pt.getName());
                cfgAttrs.put(pt.getName(), attr);
            }
            attr.getValues().add(pt.getValue());
        }
        try {
            DynamicTargets dynTargets = (DynamicTargets) Class.forName(className).newInstance();
            dynTargets.loadDynamicTargets(cfgMgr, this, cfgAttrs);
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new ProvisioningException("Could not initialize dynamic targets", e);
        }
    }
}
Also used : DynamicTargets(com.tremolosecurity.provisioning.targets.DynamicTargets) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute) HashMap(java.util.HashMap) DynamicTargets(com.tremolosecurity.provisioning.targets.DynamicTargets) Targets(com.tremolosecurity.provisioning.objects.Targets) ParamType(com.tremolosecurity.config.xml.ParamType) DynamicPortalUrlsType(com.tremolosecurity.config.xml.DynamicPortalUrlsType) TargetType(com.tremolosecurity.config.xml.TargetType)

Aggregations

TargetType (com.tremolosecurity.config.xml.TargetType)8 JSONObject (org.json.simple.JSONObject)4 HashMap (java.util.HashMap)3 ParamType (com.tremolosecurity.config.xml.ParamType)2 TargetAttributeType (com.tremolosecurity.config.xml.TargetAttributeType)2 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)2 Attribute (com.tremolosecurity.saml.Attribute)2 OpenShiftTarget (com.tremolosecurity.unison.openshiftv3.OpenShiftTarget)2 ArrayList (java.util.ArrayList)2 LDAPAttribute (com.novell.ldap.LDAPAttribute)1 UrlHolder (com.tremolosecurity.config.util.UrlHolder)1 DynamicPortalUrlsType (com.tremolosecurity.config.xml.DynamicPortalUrlsType)1 TargetConfigType (com.tremolosecurity.config.xml.TargetConfigType)1 User (com.tremolosecurity.provisioning.core.User)1 MapIdentity (com.tremolosecurity.provisioning.mapping.MapIdentity)1 Targets (com.tremolosecurity.provisioning.objects.Targets)1 DynamicTargets (com.tremolosecurity.provisioning.targets.DynamicTargets)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1 NVP (com.tremolosecurity.util.NVP)1 IOException (java.io.IOException)1