Search in sources :

Example 1 with SugarGetEntryList

use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList in project OpenUnison by TremoloSecurity.

the class ModuleType method getAccountId.

private String getAccountId(String name, String sessionId) throws UnsupportedEncodingException, ClientProtocolException, IOException, ProvisioningException {
    Gson gson = new Gson();
    SugarGetEntryList sgel = new SugarGetEntryList();
    sgel.setSession(sessionId);
    sgel.setModule_name("Accounts");
    StringBuffer b = new StringBuffer();
    b.append("accounts.name='").append(name).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 companyLookupJSON = gson.toJson(sgel);
    String respJSON = execJson(companyLookupJSON, "get_entry_list");
    SugarResult sr = gson.fromJson(respJSON, SugarResult.class);
    if (sr.getResult_count() == 0) {
        SugarEntry newContact = new SugarEntry();
        newContact.setSession(sessionId);
        newContact.setModule("Accounts");
        Map<String, String> nvps = new HashMap<String, String>();
        nvps.put("name", name);
        newContact.setName_value_list(nvps);
        String createUserJSON = gson.toJson(newContact);
        respJSON = execJson(createUserJSON, "set_entry");
        SugarID id = gson.fromJson(respJSON, SugarID.class);
        return id.getId();
    } else {
        return sr.getEntry_list().get(0).getId();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SugarEntry(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry) Gson(com.google.gson.Gson) SugarID(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarID) SugarGetEntryList(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList) SugarResult(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarResult) SugarGetEntryList(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with SugarGetEntryList

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

Example 3 with SugarGetEntryList

use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList in project OpenUnison by TremoloSecurity.

the class ModuleType method deleteUser.

@Override
public void deleteUser(User user, 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(user.getUserID()).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");
        if (jsonArray.size() == 0) {
            throw new Exception("User " + user.getUserID() + " not found");
        }
        String id = (String) ((JSONObject) jsonArray.get(0)).get("id");
        SugarEntry newContact = new SugarEntry();
        newContact.setSession(sessionId);
        newContact.setModule(mt.name);
        Map<String, String> nvps = new HashMap<String, String>();
        nvps.put("id", id);
        nvps.put("deleted", "1");
        newContact.setName_value_list(nvps);
        String createUserJSON = gson.toJson(newContact);
        execJson(createUserJSON, "set_entry");
    } catch (Exception e) {
        throw new ProvisioningException("Could not delete user", e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) SugarEntry(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry) Gson(com.google.gson.Gson) 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)3 SugarGetEntryList (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)2 SugarEntry (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HashMap (java.util.HashMap)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 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 SugarID (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarID)1