Search in sources :

Example 1 with AuthMechParamType

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

Example 2 with AuthMechParamType

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

the class OpenUnisonUtils method importMetaData.

private static void importMetaData(Options options, CommandLine cmd, String unisonXMLFile, TremoloType ttRead, TremoloType ttWrite, String ksPath, KeyStore ks) throws Exception, Base64DecodingException, CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException, FileNotFoundException, JAXBException, PropertyException {
    logger.info("Finding mechanism...");
    String mechanismName = loadOption(cmd, "mechanismName", options);
    MechanismType saml2Mech = loadMechanismType(mechanismName, ttWrite);
    logger.info("...found");
    logger.info("Finding chain...");
    String chainName = loadOption(cmd, "chainName", options);
    AuthChainType act = loadChainType(chainName, ttWrite);
    boolean createDefault = cmd.hasOption("createDefault");
    logger.info("Create default configuration? : " + createDefault);
    logger.info("Loading metadata...");
    String pathToMetaData = loadOption(cmd, "pathToMetaData", options);
    logger.info("...loaded");
    EntityDescriptor ed = loadIdPMetaData(pathToMetaData, ks, ttRead);
    IDPSSODescriptor idp = ed.getIDPSSODescriptor("urn:oasis:names:tc:SAML:2.0:protocol");
    logger.info("Looking for correct mechanism on the chain...");
    AuthMechType currentMechanism = null;
    for (AuthMechType amt : act.getAuthMech()) {
        if (amt.getName().equalsIgnoreCase(mechanismName)) {
            currentMechanism = amt;
            break;
        }
    }
    boolean newMech = true;
    if (currentMechanism != null) {
        logger.info("Updating existing mechanism");
        newMech = false;
    } else {
        logger.info("Creating new mechanism");
        currentMechanism = new AuthMechType();
        currentMechanism.setName(mechanismName);
        currentMechanism.setRequired("required");
        currentMechanism.setParams(new AuthMechParamType());
        act.getAuthMech().add(currentMechanism);
        newMech = true;
    }
    HashMap<String, ParamWithValueType> params = new HashMap<String, ParamWithValueType>();
    for (ParamWithValueType pt : currentMechanism.getParams().getParam()) {
        params.put(pt.getName(), pt);
    }
    importMetaData(ks, ed, idp, currentMechanism, params);
    if (newMech && createDefault) {
        setDefaults(ks, ed, idp, currentMechanism, params);
    }
    storeMethod(unisonXMLFile, ttWrite, ksPath, ks);
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) AuthMechParamType(com.tremolosecurity.config.xml.AuthMechParamType) IDPSSODescriptor(org.opensaml.saml.saml2.metadata.IDPSSODescriptor) HashMap(java.util.HashMap) AuthMechType(com.tremolosecurity.config.xml.AuthMechType) MechanismType(com.tremolosecurity.config.xml.MechanismType) ParamWithValueType(com.tremolosecurity.config.xml.ParamWithValueType) AuthChainType(com.tremolosecurity.config.xml.AuthChainType)

Example 3 with AuthMechParamType

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

the class UnisonConfigManagerImpl method loadAuthMechs.

/* (non-Javadoc)
	 * @see com.tremolosecurity.config.util.ConfigManager#loadAuthMechs()
	 */
/* (non-Javadoc)
	 * @see com.tremolosecurity.config.util.UnisonConfigManager#loadAuthMechs()
	 */
@Override
public void loadAuthMechs() throws ServletException {
    try {
        this.mechs = new HashMap<String, AuthMechanism>();
        // UnisonConfigManagerImpl tremoloCfg = (UnisonConfigManagerImpl) ctx.getAttribute(ConfigFilter.TREMOLO_CONFIG);
        if (getCfg().getAuthMechs() != null) {
            Iterator<MechanismType> mechs = getCfg().getAuthMechs().getMechanism().iterator();
            while (mechs.hasNext()) {
                MechanismType mt = mechs.next();
                initializeAuthenticationMechanism(mt);
            }
        }
    } catch (Exception e) {
        throw new ServletException("Could not initialize Auth Mechanism Filter", e);
    }
    for (String key : this.authChains.keySet()) {
        AuthChainType act = this.authChains.get(key);
        if (act.getLevel() == 0) {
            this.anonAct = act;
            String mechName = act.getAuthMech().get(0).getName();
            this.anonAuthMech = (AnonAuth) this.getAuthMech(this.authMechs.get(mechName).getUri());
        }
    }
    if (this.anonAuthMech == null) {
        this.anonAct = new AuthChainType();
        this.anonAct.setFinishOnRequiredSucess(true);
        this.anonAct.setLevel(0);
        this.anonAct.setName("anon");
        this.anonAuthMech = new AnonAuth();
    }
    if (this.alwaysFailAuth == null) {
        this.alwaysFailAuth = new AlwaysFail();
        String failAuthUri = this.ctxPath + "/fail";
        this.mechs.put(failAuthUri, alwaysFailAuth);
        MechanismType fmt = new MechanismType();
        fmt.setClassName("com.tremolosecurity.proxy.auth.AlwaysFail");
        fmt.setInit(new ConfigType());
        fmt.setParams(new ParamListType());
        fmt.setName("fail");
        fmt.setUri(failAuthUri);
        if (this.cfg.getAuthMechs() == null) {
            this.cfg.setAuthMechs(new AuthMechTypes());
        }
        this.cfg.getAuthMechs().getMechanism().add(fmt);
        this.alwaysFailAuthMech = fmt;
    }
    for (String key : this.authChains.keySet()) {
        AuthChainType act = this.authChains.get(key);
        for (AuthMechType amt : act.getAuthMech()) {
            if (amt.getName().equals(this.alwaysFailAuthMech.getName())) {
                this.authFailChain = act;
                break;
            }
        }
    }
    if (this.authFailChain == null) {
        this.authFailChain = new AuthChainType();
        this.authFailChain.setLevel(0);
        this.authFailChain.setName("alwaysfail");
        AuthMechType amt = new AuthMechType();
        amt.setName(this.alwaysFailAuthMech.getName());
        amt.setRequired("required");
        amt.setParams(new AuthMechParamType());
        this.authFailChain.getAuthMech().add(amt);
    }
    try {
        if (this.getCfg().getAuthMechs() != null && this.getCfg().getAuthMechs().getDynamicAuthMechs() != null && this.getCfg().getAuthMechs().getDynamicAuthMechs().isEnabled()) {
            DynamicPortalUrlsType dynamicAuthMechs = this.getCfg().getAuthMechs().getDynamicAuthMechs();
            String className = dynamicAuthMechs.getClassName();
            HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
            for (ParamType pt : dynamicAuthMechs.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());
            }
            DynamicAuthMechs dynCustomAuMechs = (DynamicAuthMechs) Class.forName(className).newInstance();
            dynCustomAuMechs.loadDynamicAuthMechs(this, this.getProvisioningEngine(), cfgAttrs);
        }
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ProvisioningException e) {
        throw new ServletException("Could not initialize authentication mechanisms", e);
    }
}
Also used : AuthMechParamType(com.tremolosecurity.config.xml.AuthMechParamType) AnonAuth(com.tremolosecurity.proxy.auth.AnonAuth) Attribute(com.tremolosecurity.saml.Attribute) HashMap(java.util.HashMap) ServletException(javax.servlet.ServletException) DynamicAuthMechs(com.tremolosecurity.proxy.dynamicloaders.DynamicAuthMechs) AuthMechanism(com.tremolosecurity.proxy.auth.AuthMechanism) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) MechanismType(com.tremolosecurity.config.xml.MechanismType) AuthChainType(com.tremolosecurity.config.xml.AuthChainType) ConfigType(com.tremolosecurity.config.xml.ConfigType) ParamListType(com.tremolosecurity.config.xml.ParamListType) AuthMechTypes(com.tremolosecurity.config.xml.AuthMechTypes) AuthMechType(com.tremolosecurity.config.xml.AuthMechType) KeyStoreException(java.security.KeyStoreException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LDAPException(com.novell.ldap.LDAPException) AzException(com.tremolosecurity.proxy.az.AzException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException) AuthMechParamType(com.tremolosecurity.config.xml.AuthMechParamType) ParamType(com.tremolosecurity.config.xml.ParamType) AlwaysFail(com.tremolosecurity.proxy.auth.AlwaysFail) DynamicPortalUrlsType(com.tremolosecurity.config.xml.DynamicPortalUrlsType)

Aggregations

AuthChainType (com.tremolosecurity.config.xml.AuthChainType)3 AuthMechParamType (com.tremolosecurity.config.xml.AuthMechParamType)3 AuthMechType (com.tremolosecurity.config.xml.AuthMechType)3 MechanismType (com.tremolosecurity.config.xml.MechanismType)2 ParamWithValueType (com.tremolosecurity.config.xml.ParamWithValueType)2 HashMap (java.util.HashMap)2 LDAPException (com.novell.ldap.LDAPException)1 AuthLockoutType (com.tremolosecurity.config.xml.AuthLockoutType)1 AuthMechTypes (com.tremolosecurity.config.xml.AuthMechTypes)1 ConfigType (com.tremolosecurity.config.xml.ConfigType)1 DynamicPortalUrlsType (com.tremolosecurity.config.xml.DynamicPortalUrlsType)1 ParamListType (com.tremolosecurity.config.xml.ParamListType)1 ParamType (com.tremolosecurity.config.xml.ParamType)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1 AlwaysFail (com.tremolosecurity.proxy.auth.AlwaysFail)1 AnonAuth (com.tremolosecurity.proxy.auth.AnonAuth)1 AuthMechanism (com.tremolosecurity.proxy.auth.AuthMechanism)1 AzException (com.tremolosecurity.proxy.az.AzException)1 DynamicAuthMechs (com.tremolosecurity.proxy.dynamicloaders.DynamicAuthMechs)1