Search in sources :

Example 16 with NVP

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

the class ModuleType method findUser.

@Override
public User findUser(String userID, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
    try {
        ModuleType mt = this.getModuleType(request);
        String sessionId = sugarLogin();
        Gson gson = new Gson();
        SugarGetEntryList sgel = new SugarGetEntryList();
        sgel.setSession(sessionId);
        sgel.setModule_name(mt.name);
        StringBuffer b = new StringBuffer();
        b.append(mt.lookupByEmail).append(userID).append("')");
        sgel.setQuery(b.toString());
        sgel.setOrder_by("");
        sgel.setOffset(0);
        ArrayList<String> reqFields = new ArrayList<String>();
        reqFields.add("id");
        sgel.setSelect_fields(reqFields);
        sgel.setMax_results(-1);
        sgel.setDeleted(false);
        sgel.setLink_name_to_fields_array(new HashMap<String, List<String>>());
        String searchJson = gson.toJson(sgel);
        String respJSON = execJson(searchJson, "get_entry_list");
        JSONObject jsonObj = (JSONObject) JSONValue.parse(respJSON);
        JSONArray jsonArray = (JSONArray) jsonObj.get("entry_list");
        String id = (String) ((JSONObject) jsonArray.get(0)).get("id");
        SugarGetEntry sge = new SugarGetEntry();
        sge.setId(id);
        sge.setSession(sessionId);
        sge.setSelect_fields(new ArrayList<String>());
        sge.setModule_name(mt.name);
        sge.setLink_name_to_fields_array(new HashMap<String, List<String>>());
        searchJson = gson.toJson(sge);
        respJSON = execJson(searchJson, "get_entry");
        // System.out.println(respJSON);
        SugarEntrySet res = gson.fromJson(respJSON, SugarEntrySet.class);
        User user = new User(userID);
        SugarContactEntry sce = res.getEntry_list().get(0);
        for (String attrName : sce.getName_value_list().keySet()) {
            NVP nvp = sce.getName_value_list().get(attrName);
            if (attributes.size() > 0 && !attributes.contains(nvp.getName())) {
                continue;
            }
            if (nvp.getValue() != null && !nvp.getValue().isEmpty()) {
                Attribute attr = new Attribute(nvp.getName(), nvp.getValue());
                user.getAttribs().put(nvp.getName(), attr);
            }
        }
        return user;
    } catch (Exception e) {
        throw new ProvisioningException("Could not find user", e);
    }
}
Also used : User(com.tremolosecurity.provisioning.core.User) SugarGetEntry(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntry) SugarContactEntry(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarContactEntry) Attribute(com.tremolosecurity.saml.Attribute) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) Gson(com.google.gson.Gson) NVP(com.tremolosecurity.util.NVP) SugarEntrySet(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntrySet) MalformedCookieException(org.apache.http.cookie.MalformedCookieException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JSONObject(org.json.simple.JSONObject) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) SugarGetEntryList(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList) SugarGetEntryList(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList) List(java.util.List) ArrayList(java.util.ArrayList)

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