Search in sources :

Example 1 with TargetAttributeType

use of com.tremolosecurity.config.xml.TargetAttributeType 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 TargetAttributeType

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

the class FullMappingAuthMech method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response, AuthStep step) throws IOException, ServletException {
    HttpSession session = ((HttpServletRequest) request).getSession();
    UrlHolder holder = (UrlHolder) request.getAttribute(ProxyConstants.AUTOIDM_CFG);
    if (holder == null) {
        throw new ServletException("Holder is null");
    }
    RequestHolder reqHolder = ((AuthController) session.getAttribute(ProxyConstants.AUTH_CTL)).getHolder();
    HashMap<String, Attribute> authParams = (HashMap<String, Attribute>) session.getAttribute(ProxyConstants.AUTH_MECH_PARAMS);
    TargetType tt = new TargetType();
    Attribute map = authParams.get("map");
    for (String mapping : map.getValues()) {
        int firstPipe = mapping.indexOf('|');
        int secondPipe = mapping.indexOf('|', firstPipe + 1);
        String destAttr = mapping.substring(0, firstPipe);
        String type = mapping.substring(firstPipe + 1, secondPipe);
        String value = mapping.substring(secondPipe + 1);
        TargetAttributeType tat = new TargetAttributeType();
        tat.setName(destAttr);
        tat.setSourceType(type);
        tat.setSource(value);
        tt.getTargetAttribute().add(tat);
    }
    try {
        MapIdentity mapper = new MapIdentity(tt);
        AuthController ac = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL));
        User orig = new User(ac.getAuthInfo().getUserDN());
        orig.getAttribs().putAll(ac.getAuthInfo().getAttribs());
        User mapped = mapper.mapUser(orig);
        ac.getAuthInfo().getAttribs().clear();
        ac.getAuthInfo().getAttribs().putAll(mapped.getAttribs());
    } catch (ProvisioningException e) {
        throw new ServletException("Could not map user", e);
    }
    step.setSuccess(true);
    holder.getConfig().getAuthManager().nextAuth(request, response, session, false);
}
Also used : User(com.tremolosecurity.provisioning.core.User) Attribute(com.tremolosecurity.saml.Attribute) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) MapIdentity(com.tremolosecurity.provisioning.mapping.MapIdentity) HttpServletRequest(javax.servlet.http.HttpServletRequest) UrlHolder(com.tremolosecurity.config.util.UrlHolder) ServletException(javax.servlet.ServletException) TargetAttributeType(com.tremolosecurity.config.xml.TargetAttributeType) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) TargetType(com.tremolosecurity.config.xml.TargetType)

Aggregations

TargetAttributeType (com.tremolosecurity.config.xml.TargetAttributeType)2 TargetType (com.tremolosecurity.config.xml.TargetType)2 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)2 UrlHolder (com.tremolosecurity.config.util.UrlHolder)1 ParamType (com.tremolosecurity.config.xml.ParamType)1 TargetConfigType (com.tremolosecurity.config.xml.TargetConfigType)1 User (com.tremolosecurity.provisioning.core.User)1 MapIdentity (com.tremolosecurity.provisioning.mapping.MapIdentity)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1 Attribute (com.tremolosecurity.saml.Attribute)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1