Search in sources :

Example 1 with NVP

use of com.tremolosecurity.util.NVP 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 2 with NVP

use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.

the class LoadGroupsFromOkta method getSourceList.

@Override
public List<NVP> getSourceList(HttpFilterRequest request) throws Exception {
    if (targetName == null) {
        throw new Exception("targetName not configured");
    }
    OktaTarget okta = (OktaTarget) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
    if (okta == null) {
        throw new Exception("The target " + targetName + " does not exist");
    }
    Client client = okta.getOkta();
    if (request.getParameter("search") == null) {
        ArrayList<NVP> toReturn = new ArrayList<NVP>();
        GroupList groupList = client.listGroups();
        int i = 0;
        for (Group group : groupList) {
            toReturn.add(new NVP(group.getProfile().getName(), group.getProfile().getName()));
            if (this.dynSearch && i >= this.maxEntries) {
                break;
            }
        }
        Collections.sort(toReturn, new Comparator<NVP>() {

            @Override
            public int compare(NVP arg0, NVP arg1) {
                return arg0.getName().compareTo(arg1.getName());
            }
        });
        return toReturn;
    } else {
        int i = 0;
        ArrayList<NVP> toReturn = new ArrayList<NVP>();
        GroupList groupList = client.listGroups(request.getParameter("search").getValues().get(0), null, null);
        for (Group group : groupList) {
            toReturn.add(new NVP(group.getProfile().getName(), group.getProfile().getName()));
            i++;
            if (i >= this.maxEntries) {
                break;
            }
        }
        Collections.sort(toReturn, new Comparator<NVP>() {

            @Override
            public int compare(NVP arg0, NVP arg1) {
                return arg0.getName().compareTo(arg1.getName());
            }
        });
        return toReturn;
    }
}
Also used : Group(com.okta.sdk.resource.group.Group) GroupList(com.okta.sdk.resource.group.GroupList) OktaTarget(com.tremolosecurity.unison.okta.provisioning.OktaTarget) ArrayList(java.util.ArrayList) NVP(com.tremolosecurity.util.NVP) Client(com.okta.sdk.client.Client)

Example 3 with NVP

use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.

the class LoadFromDatabaseTarget method getSourceList.

@Override
public List<NVP> getSourceList(HttpFilterRequest request) throws Exception {
    if (request.getParameter("search") == null) {
        BasicDB db = (BasicDB) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
        Connection con = db.getDS().getConnection();
        try {
            ArrayList<NVP> toReturn = new ArrayList<NVP>();
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(noParamSQL);
            while (rs.next()) {
                toReturn.add(new NVP(rs.getString(nameField), rs.getString(valueField)));
                if (this.maxEntries > 0 && toReturn.size() > this.maxEntries) {
                    rs.close();
                    stmt.close();
                    break;
                }
            }
            return toReturn;
        } finally {
            if (con != null) {
                con.close();
            }
        }
    } else {
        BasicDB db = (BasicDB) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
        Connection con = db.getDS().getConnection();
        try {
            ArrayList<NVP> toReturn = new ArrayList<NVP>();
            PreparedStatement stmt = con.prepareStatement(this.paramSQL);
            stmt.setString(1, "%" + request.getParameter("search").getValues().get(0) + "%");
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                toReturn.add(new NVP(rs.getString(nameField), rs.getString(valueField)));
                if (this.maxEntries > 0 && toReturn.size() > this.maxEntries) {
                    rs.close();
                    stmt.close();
                    break;
                }
            }
            return toReturn;
        } finally {
            if (con != null) {
                con.close();
            }
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) NVP(com.tremolosecurity.util.NVP) PreparedStatement(java.sql.PreparedStatement) BasicDB(com.tremolosecurity.provisioning.core.providers.BasicDB)

Example 4 with NVP

use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.

the class LoadFromLDAP method getSourceList.

@Override
public List<NVP> getSourceList(HttpFilterRequest request) throws Exception {
    if (request.getParameter("search") == null) {
        ArrayList<NVP> toReturn = new ArrayList<NVP>();
        LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(this.searchBase, 2, and(equal("objectClass", this.objectClass), present(this.searchAttribute)).toString(), new ArrayList<String>());
        int num = 0;
        while (res.hasMore()) {
            if ((this.dynSearch && num < this.maxEntries) || !this.dynSearch) {
                LDAPEntry entry = res.next();
                String name = entry.getAttribute(this.nameField).getStringValue();
                String value = entry.getAttribute(this.valueField).getStringValue();
                toReturn.add(new NVP(name, value));
            } else {
                res.next();
            }
            num++;
        }
        if (this.sort) {
            Collections.sort(toReturn, new Comparator<NVP>() {

                @Override
                public int compare(NVP arg0, NVP arg1) {
                    return arg0.getName().compareTo(arg1.getName());
                }
            });
        }
        return toReturn;
    } else {
        ArrayList<NVP> toReturn = new ArrayList<NVP>();
        LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(this.searchBase, 2, and(equal("objectClass", this.objectClass), contains(this.searchAttribute, request.getParameter("search").getValues().get(0))).toString(), new ArrayList<String>());
        int num = 0;
        while (res.hasMore() && num < this.maxEntries) {
            LDAPEntry entry = res.next();
            String name = entry.getAttribute(this.nameField).getStringValue();
            String value = entry.getAttribute(this.valueField).getStringValue();
            toReturn.add(new NVP(name, value));
            num++;
        }
        while (res.hasMore()) res.next();
        if (this.sort) {
            Collections.sort(toReturn, new Comparator<NVP>() {

                @Override
                public int compare(NVP arg0, NVP arg1) {
                    return arg0.getName().compareTo(arg1.getName());
                }
            });
        }
        return toReturn;
    }
}
Also used : LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) ArrayList(java.util.ArrayList) NVP(com.tremolosecurity.util.NVP)

Example 5 with NVP

use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.

the class ScaleRegister method initFilter.

@Override
public void initFilter(HttpFilterConfig config) throws Exception {
    this.scaleConfig = new ScaleJSRegisterConfig();
    scaleConfig.getFrontPage().setTitle(this.loadAttributeValue("frontPage.title", "Front Page Title", config));
    scaleConfig.getFrontPage().setText(this.loadAttributeValue("frontPage.text", "Front Page Text", config));
    scaleConfig.setHomeURL(this.loadAttributeValue("homeURL", "Home URL", config));
    scaleConfig.setLogoutURL(this.loadAttributeValue("logoutURL", "Logout URL", config));
    scaleConfig.setUidAttributeName(this.loadAttributeValue("uidAttributeName", "UID Attribute Name", config));
    scaleConfig.setWorkflowName(this.loadAttributeValue("workflowName", "Workflow Name", config));
    String val = this.loadOptionalAttributeValue("requireReason", "Require Reason", config);
    scaleConfig.setRequireReason(val != null && val.equals("true"));
    val = this.loadOptionalAttributeValue("preSetPassword", "Pre-Set Password", config);
    scaleConfig.setPreSetPassword(val != null && val.equals("true"));
    Attribute attr = config.getAttribute("attributeNames");
    if (attr == null) {
        throw new Exception("Attribute names not found");
    }
    val = this.loadOptionalAttributeValue("requireReCaptcha", "ReCaptcha Required", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setRequireReCaptcha(val.equalsIgnoreCase("true"));
    if (scaleConfig.isRequireReCaptcha()) {
        scaleConfig.setRcSiteKey(this.loadAttributeValue("rcSiteKey", "ReCaptcha Site Key", config));
        scaleConfig.setRcSecretKey(this.loadAttributeValue("rcSecret", "ReCaptcha Secret Key", config));
    }
    val = this.loadOptionalAttributeValue("submitButtonText", "submitButtonText", config);
    if (val == null) {
        val = "Submit Registration";
    }
    scaleConfig.setSubmitButtonText(val);
    val = this.loadOptionalAttributeValue("submittedText", "submittedText", config);
    if (val == null) {
        val = "Thank you for registering, your request has been submitted and you will be notified once approved";
    }
    scaleConfig.setSubmittedText(val);
    val = this.loadOptionalAttributeValue("reasonIsList", "reasonIsList", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setReasonIsList(val.equalsIgnoreCase("true"));
    if (scaleConfig.isReasonIsList()) {
        Attribute reasons = config.getAttribute("reasons");
        if (reasons != null) {
            scaleConfig.getReasons().addAll(reasons.getValues());
        }
    }
    val = this.loadOptionalAttributeValue("requireTermsAndConditions", "Require Terms and Conditions", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setRequireTermsAndConditions(val.equalsIgnoreCase("true"));
    if (scaleConfig.isRequireTermsAndConditions()) {
        scaleConfig.setTermsAndConditionsText(this.loadAttributeValue("termsAndConditionsText", "Terms and Conditions", config));
    }
    for (String attributeName : attr.getValues()) {
        scaleConfig.getAttributeNameList().add(attributeName);
        ScaleAttribute scaleAttr = new ScaleAttribute();
        scaleAttr.setName(attributeName);
        scaleAttr.setDisplayName(this.loadAttributeValue(attributeName + ".displayName", attributeName + " Display Name", config));
        scaleAttr.setReadOnly(false);
        scaleAttr.setRequired(true);
        val = this.loadOptionalAttributeValue(attributeName + ".required", attributeName + " Required", config);
        if (val != null) {
            scaleAttr.setRequired(val.equalsIgnoreCase("true"));
        }
        val = this.loadOptionalAttributeValue(attributeName + ".regEx", attributeName + " Reg Ex", config);
        if (val != null) {
            scaleAttr.setRegEx(val);
        }
        val = this.loadOptionalAttributeValue(attributeName + ".regExFailedMsg", attributeName + " Reg Ex Failed Message", config);
        if (val != null) {
            scaleAttr.setRegExFailedMsg(val);
        }
        val = this.loadOptionalAttributeValue(attributeName + ".minChars", attributeName + " Minimum Characters", config);
        if (val != null) {
            scaleAttr.setMinChars(Integer.parseInt(val));
        }
        val = this.loadOptionalAttributeValue(attributeName + ".maxChars", attributeName + " Maximum Characters", config);
        if (val != null) {
            scaleAttr.setMaxChars(Integer.parseInt(val));
        }
        val = this.loadOptionalAttributeValue(attributeName + ".unique", attributeName + " Attribute Value Must Be Unique", config);
        if (val != null) {
            scaleAttr.setUnique(val.equalsIgnoreCase("true"));
        }
        val = this.loadOptionalAttributeValue(attributeName + ".type", attributeName + " Attribute Type", config);
        if (val != null) {
            scaleAttr.setType(val);
        }
        Attribute attrVals = config.getAttribute(attributeName + ".values");
        if (attrVals != null) {
            for (String attrVal : attrVals.getValues()) {
                String valLabel = attrVal.substring(0, attrVal.indexOf('='));
                String valValue = attrVal.substring(attrVal.indexOf('=') + 1);
                scaleAttr.getValues().add(new NVP(valLabel, valValue));
            }
        }
        if (config.getAttribute(attributeName + ".dynamicValueSource.className") != null && config.getAttribute(attributeName + ".dynamicValueSource.className").getValues() != null && config.getAttribute(attributeName + ".dynamicValueSource.className").getValues().size() != 0 && config.getAttribute(attributeName + ".dynamicValueSource.className").getValues().get(0) != null && !config.getAttribute(attributeName + ".dynamicValueSource.className").getValues().get(0).equalsIgnoreCase("")) {
            String className = config.getAttribute(attributeName + ".dynamicValueSource.className").getValues().get(0);
            scaleAttr.setDynamicSourceClassName(className);
            Attribute cfgOptions = config.getAttribute(attributeName + ".dynamicValueSource.config");
            Map<String, Attribute> dynConfig = new HashMap<String, Attribute>();
            if (cfgOptions != null) {
                for (String attrVal : cfgOptions.getValues()) {
                    String valLabel = attrVal.substring(0, attrVal.indexOf('='));
                    String valValue = attrVal.substring(attrVal.indexOf('=') + 1);
                    Attribute cfgattr = dynConfig.get(valLabel);
                    if (cfgattr == null) {
                        cfgattr = new Attribute(valLabel);
                        dynConfig.put(valLabel, cfgattr);
                    }
                    cfgattr.getValues().add(valValue);
                    Attribute dcfgattr = scaleAttr.getDynamicSourceConfig().get(valLabel);
                    if (dcfgattr == null) {
                        dcfgattr = new Attribute(valLabel);
                        scaleAttr.getDynamicSourceConfig().put(valLabel, dcfgattr);
                    }
                    dcfgattr.getValues().add(valValue);
                }
            }
            scaleAttr.setDynamicSource((SourceList) Class.forName(className).newInstance());
            scaleAttr.getDynamicSource().init(scaleAttr, dynConfig);
        }
        val = this.loadOptionalAttributeValue(attributeName + ".editJavaScriptFunction", "editJavaScriptFunction", config);
        if (val != null) {
            scaleAttr.setEditJavaScriptFunction(val);
        }
        val = this.loadOptionalAttributeValue(attributeName + ".show", "show", config);
        if (val != null) {
            scaleAttr.setShow(val.equalsIgnoreCase("true"));
        } else {
            scaleAttr.setShow(true);
        }
        scaleConfig.getAttributes().put(attributeName, scaleAttr);
    }
    val = loadOptionalAttributeValue("useCallWorkflowClass", "Use Custom Submission", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setUseCustomSubmission(val.equalsIgnoreCase("true"));
    val = loadOptionalAttributeValue("submitLoggedInUser", "Submit logged in user as subject", config);
    if (val == null) {
        val = "false";
    }
    scaleConfig.setSubmitLoggedInUser(val.equalsIgnoreCase("true"));
    if (scaleConfig.isUseCustomSubmission()) {
        scaleConfig.setCustomSubmissionClassName(this.loadAttributeValue("callWorkflowClassName", "Custom Submission Class", config));
        Attribute tattr = config.getAttribute("callWorkflowInit");
        scaleConfig.setCustomSubmissionConfig(new HashMap<String, Attribute>());
        if (tattr != null) {
            for (String value : tattr.getValues()) {
                String n = value.substring(0, value.indexOf('='));
                String v = value.substring(value.indexOf('=') + 1);
                Attribute tmpa = scaleConfig.getCustomSubmissionConfig().get(n);
                if (tmpa == null) {
                    tmpa = new Attribute(n);
                    scaleConfig.getCustomSubmissionConfig().put(n, tmpa);
                }
                tmpa.getValues().add(v);
            }
        }
        this.cru = (CreateRegisterUser) Class.forName(scaleConfig.getCustomSubmissionClassName()).newInstance();
        this.cru.init(this.scaleConfig);
    }
}
Also used : ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) Attribute(com.tremolosecurity.saml.Attribute) ScaleAttribute(com.tremolosecurity.scalejs.cfg.ScaleAttribute) HashMap(java.util.HashMap) ScaleJSRegisterConfig(com.tremolosecurity.scalejs.register.cfg.ScaleJSRegisterConfig) NVP(com.tremolosecurity.util.NVP) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException)

Aggregations

NVP (com.tremolosecurity.util.NVP)16 ArrayList (java.util.ArrayList)9 Attribute (com.tremolosecurity.saml.Attribute)5 HashMap (java.util.HashMap)5 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)4 ScaleAttribute (com.tremolosecurity.scalejs.cfg.ScaleAttribute)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 List (java.util.List)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 Gson (com.google.gson.Gson)2 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)2 ScaleJSRegisterConfig (com.tremolosecurity.scalejs.register.cfg.ScaleJSRegisterConfig)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 HttpResponse (org.apache.http.HttpResponse)2 NameValuePair (org.apache.http.NameValuePair)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPEntry (com.novell.ldap.LDAPEntry)1