Search in sources :

Example 1 with SugarEntry

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

the class ModuleType method createUser.

@Override
public void createUser(User user, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
    ModuleType mt = this.getModuleType(request);
    int userID = 0;
    int approvalID = 0;
    int workflow = 0;
    if (request.containsKey("TREMOLO_USER_ID")) {
        userID = (Integer) request.get("TREMOLO_USER_ID");
    }
    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }
    if (request.containsKey("WORKFLOW_ID")) {
        workflow = (Integer) request.get("WORKFLOW_ID");
    }
    try {
        String sessionId = sugarLogin();
        Gson gson = new Gson();
        SugarEntry newContact = new SugarEntry();
        newContact.setSession(sessionId);
        newContact.setModule(mt.name);
        Map<String, String> nvps = new HashMap<String, String>();
        for (String attrName : user.getAttribs().keySet()) {
            if (!attributes.contains(attrName) || attrName.equalsIgnoreCase("userName")) {
                continue;
            }
            if (attrName.equalsIgnoreCase("account_name")) {
                String id = this.getAccountId(user.getAttribs().get(attrName).getValues().get(0), sessionId);
                nvps.put("account_id", id);
            }
            nvps.put(attrName, user.getAttribs().get(attrName).getValues().get(0));
        }
        newContact.setName_value_list(nvps);
        String createUserJSON = gson.toJson(newContact);
        execJson(createUserJSON, "set_entry");
    } catch (Exception e) {
        throw new ProvisioningException("Could not find user", e);
    }
}
Also used : HashMap(java.util.HashMap) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) 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)

Example 2 with SugarEntry

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

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

the class ModuleType method syncUser.

@Override
public void syncUser(User user, boolean addOnly, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
    ModuleType mt = this.getModuleType(request);
    int userID = 0;
    int approvalID = 0;
    int workflow = 0;
    if (request.containsKey("TREMOLO_USER_ID")) {
        userID = (Integer) request.get("TREMOLO_USER_ID");
    }
    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }
    if (request.containsKey("WORKFLOW_ID")) {
        workflow = (Integer) request.get("WORKFLOW_ID");
    }
    try {
        String sessionId = sugarLogin();
        Map<String, String> toAdd = new HashMap<String, String>();
        Map<String, String> toReplace = new HashMap<String, String>();
        Map<String, String> toDelete = new HashMap<String, String>();
        Gson gson = new Gson();
        Set<String> nattribs = new HashSet<String>();
        nattribs.addAll(attributes);
        nattribs.add("id");
        User foundUser = null;
        try {
            foundUser = this.findUser(user.getUserID(), nattribs, request);
        } catch (Exception e) {
            this.createUser(user, attributes, request);
            return;
        }
        Map<String, String> nvps = new HashMap<String, String>();
        nvps.put("id", foundUser.getAttribs().get("id").getValues().get(0));
        for (String attrName : user.getAttribs().keySet()) {
            if (!attributes.contains(attrName)) {
                continue;
            }
            if (attrName.equalsIgnoreCase("account_name")) {
                String id = this.getAccountId(user.getAttribs().get(attrName).getValues().get(0), sessionId);
                nvps.put("account_id", id);
            }
            foundUser.getAttribs().put(attrName, new Attribute(attrName, user.getAttribs().get(attrName).getValues().get(0)));
        }
        if (!addOnly) {
            for (String attrName : foundUser.getAttribs().keySet()) {
                if (!user.getAttribs().containsKey(attrName) && !attributes.contains(attrName) && !attrName.equalsIgnoreCase("id")) {
                    foundUser.getAttribs().put(attrName, new Attribute(attrName, ""));
                }
            }
        }
        for (String attrName : foundUser.getAttribs().keySet()) {
            nvps.put(attrName, foundUser.getAttribs().get(attrName).getValues().get(0));
        }
        SugarEntry newContact = new SugarEntry();
        newContact.setSession(sessionId);
        newContact.setModule(mt.name);
        newContact.setName_value_list(nvps);
        String createUserJSON = gson.toJson(newContact);
        execJson(createUserJSON, "set_entry");
    } catch (Exception e) {
        throw new ProvisioningException("Could not sync user", e);
    }
}
Also used : User(com.tremolosecurity.provisioning.core.User) HashMap(java.util.HashMap) Attribute(com.tremolosecurity.saml.Attribute) 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) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) HashSet(java.util.HashSet)

Example 4 with SugarEntry

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

the class ModuleType method deleteAccount.

public void deleteAccount(String name) throws ProvisioningException {
    try {
        DefaultHttpClient http = new DefaultHttpClient();
        String sessionId = sugarLogin();
        Gson gson = new Gson();
        String id = this.getAccountId(name, sessionId);
        SugarEntry newContact = new SugarEntry();
        newContact.setSession(sessionId);
        newContact.setModule("Accounts");
        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) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) SugarEntry(com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry) Gson(com.google.gson.Gson) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) 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)

Example 5 with SugarEntry

use of com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry 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)5 SugarEntry (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarEntry)5 HashMap (java.util.HashMap)5 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)4 IOException (java.io.IOException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 MalformedURLException (java.net.MalformedURLException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 ClientProtocolException (org.apache.http.client.ClientProtocolException)4 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)4 SugarGetEntryList (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarGetEntryList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 User (com.tremolosecurity.provisioning.core.User)1 SugarID (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarID)1 SugarResult (com.tremolosecurity.provisioning.core.providers.sugarcrm.SugarResult)1 Attribute (com.tremolosecurity.saml.Attribute)1 HashSet (java.util.HashSet)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 JSONArray (org.json.simple.JSONArray)1