Search in sources :

Example 1 with SugarEntrySet

use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntrySet 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

Gson (com.google.gson.Gson)1 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 User (com.tremolosecurity.provisioning.core.User)1 SugarContactEntry (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarContactEntry)1 SugarEntrySet (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntrySet)1 SugarGetEntry (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntry)1 SugarGetEntryList (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList)1 Attribute (com.tremolosecurity.saml.Attribute)1 NVP (com.tremolosecurity.util.NVP)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1