Search in sources :

Example 1 with AuthLockoutType

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

the class LoadAuthChainsFromK8s method createAuthChain.

private AuthChainType createAuthChain(JSONObject item, String name) throws Exception {
    AuthChainType act = new AuthChainType();
    act.setName(name);
    JSONObject spec = (JSONObject) item.get("spec");
    act.setLevel(((Long) spec.get("level")).intValue());
    Boolean finishOnRequiredSucess = (Boolean) spec.get("finishOnRequiredSucess");
    if (finishOnRequiredSucess != null) {
        act.setFinishOnRequiredSucess(finishOnRequiredSucess);
    } else {
        act.setFinishOnRequiredSucess(false);
    }
    String root = (String) spec.get("root");
    if (root != null) {
        act.setRoot(root);
    }
    JSONObject jsonCompliance = (JSONObject) spec.get("compliance");
    if (jsonCompliance != null) {
        AuthLockoutType alt = new AuthLockoutType();
        alt.setEnabled((Boolean) jsonCompliance.get("enabled"));
        alt.setMaxFailedAttempts(((Integer) jsonCompliance.get("maxLockoutTime")));
        alt.setNumFailedAttribute((String) jsonCompliance.get("numFailedAttribute"));
        alt.setLastFailedAttribute((String) jsonCompliance.get("lastFailedAttribute"));
        alt.setLastSucceedAttribute((String) jsonCompliance.get("lastSucceedAttribute"));
        alt.setUpdateAttributesWorkflow((String) jsonCompliance.get("updateAttributesWorkflow"));
        alt.setUidAttributeName((String) jsonCompliance.get("uidAttributeName"));
        act.setCompliance(alt);
    }
    JSONArray mechs = (JSONArray) spec.get("authMechs");
    for (Object o : mechs) {
        JSONObject mech = (JSONObject) o;
        AuthMechType amt = new AuthMechType();
        amt.setName((String) mech.get("name"));
        amt.setRequired((String) mech.get("required"));
        amt.setParams(new AuthMechParamType());
        JSONObject jsonObj = (JSONObject) mech.get("params");
        for (Object ok : jsonObj.keySet()) {
            String paramName = (String) ok;
            Object val = jsonObj.get(paramName);
            if (val instanceof String) {
                ParamWithValueType pt = new ParamWithValueType();
                pt.setName(paramName);
                pt.setValue((String) val);
                amt.getParams().getParam().add(pt);
            } else {
                JSONArray vals = (JSONArray) val;
                for (Object ov : vals) {
                    ParamWithValueType pt = new ParamWithValueType();
                    pt.setName(paramName);
                    pt.setValue((String) ov);
                    amt.getParams().getParam().add(pt);
                }
            }
        }
        JSONArray secretParams = (JSONArray) mech.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);
                    ParamWithValueType pt = new ParamWithValueType();
                    pt.setName(paramName);
                    pt.setValue(secretValue);
                    amt.getParams().getParam().add(pt);
                }
            } finally {
                nonwatchHttp.getHttp().close();
                nonwatchHttp.getBcm().close();
            }
        }
        act.getAuthMech().add(amt);
    }
    return act;
}
Also used : AuthLockoutType(com.tremolosecurity.config.xml.AuthLockoutType) AuthMechParamType(com.tremolosecurity.config.xml.AuthMechParamType) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) AuthMechType(com.tremolosecurity.config.xml.AuthMechType) JSONObject(org.json.simple.JSONObject) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType) AuthChainType(com.tremolosecurity.config.xml.AuthChainType)

Aggregations

AuthChainType (com.tremolosecurity.config.xml.AuthChainType)1 AuthLockoutType (com.tremolosecurity.config.xml.AuthLockoutType)1 AuthMechParamType (com.tremolosecurity.config.xml.AuthMechParamType)1 AuthMechType (com.tremolosecurity.config.xml.AuthMechType)1 ParamWithValueType (com.tremolosecurity.config.xml.ParamWithValueType)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1