Search in sources :

Example 76 with Workflow

use of com.tremolosecurity.provisioning.core.Workflow in project OpenUnison by TremoloSecurity.

the class OktaTarget method syncUser.

@Override
public void syncUser(User user, boolean addOnly, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
    int approvalID = 0;
    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }
    Workflow workflow = (Workflow) request.get("WORKFLOW");
    com.okta.sdk.resource.user.User fromOkta = null;
    try {
        fromOkta = okta.getUser(user.getUserID());
    } catch (ResourceException e) {
        if (e.getStatus() != 404) {
            throw new ProvisioningException("Could not lookup user", e);
        }
    }
    if (fromOkta == null) {
        this.createUser(user, attributes, request);
    } else {
        HashMap<String, String> changed = new HashMap<String, String>();
        for (String attrName : user.getAttribs().keySet()) {
            if (attributes.contains(attrName)) {
                if (fromOkta.getProfile().get(attrName) == null || !((String) fromOkta.getProfile().get(attrName)).equalsIgnoreCase(user.getAttribs().get(attrName).getValues().get(0))) {
                    changed.put(attrName, user.getAttribs().get(attrName).getValues().get(0));
                }
            }
        }
        for (String attrName : changed.keySet()) {
            fromOkta.getProfile().put(attrName, changed.get(attrName));
        }
        HashSet<String> groups = new HashSet<String>();
        List<String> groupsToAdd = new ArrayList<String>();
        for (Group group : fromOkta.listGroups()) {
            groups.add(group.getProfile().getName());
        }
        for (String group : user.getGroups()) {
            if (!groups.contains(group)) {
                groupsToAdd.add(group);
            }
        }
        for (String group : groupsToAdd) {
            GroupList gl = okta.listGroups(group, null, null);
            fromOkta.addToGroup(gl.iterator().next().getId());
        }
        for (String attrName : changed.keySet()) {
            this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Replace, approvalID, workflow, attrName, changed.get(attrName));
        }
        for (String group : groupsToAdd) {
            this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, "group", group);
        }
        fromOkta.update();
        List<Group> groupsToRemove = new ArrayList<Group>();
        if (!addOnly) {
            for (Group group : fromOkta.listGroups()) {
                if (!user.getGroups().contains(group.getProfile().getName())) {
                    groupsToRemove.add(group);
                }
            }
            for (Group g : groupsToRemove) {
                if (!g.getProfile().getName().equals("Everyone")) {
                    g.removeUser(fromOkta.getId());
                    this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Delete, approvalID, workflow, "group", g.getProfile().getName());
                }
            }
        }
    }
}
Also used : Group(com.okta.sdk.resource.group.Group) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Workflow(com.tremolosecurity.provisioning.core.Workflow) GroupList(com.okta.sdk.resource.group.GroupList) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ResourceException(com.okta.sdk.resource.ResourceException) HashSet(java.util.HashSet)

Example 77 with Workflow

use of com.tremolosecurity.provisioning.core.Workflow in project OpenUnison by TremoloSecurity.

the class OpenShiftTarget method deleteGroup.

@Override
public void deleteGroup(String name, User user, Map<String, Object> request) throws ProvisioningException {
    HttpCon con = null;
    int approvalID = 0;
    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }
    Workflow workflow = (Workflow) request.get("WORKFLOW");
    try {
        String token = this.getAuthToken();
        con = this.createClient();
        Gson gson = new Gson();
        StringBuffer b = new StringBuffer();
        b.append("/apis/user.openshift.io/v1/groups/").append(name);
        String json = this.callWSDelete(token, con, b.toString());
        Response resp = gson.fromJson(json, Response.class);
        if (resp.getStatus().equalsIgnoreCase("Success")) {
            this.cfgMgr.getProvisioningEngine().logAction(name, true, ActionType.Delete, approvalID, workflow, "group-object", name);
        } else {
            throw new ProvisioningException("Unknown response : '" + json + "'");
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not load group", e);
    } finally {
        if (con != null) {
            con.getBcm().close();
        }
    }
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Response(com.tremolosecurity.unison.openshiftv3.model.Response) HttpResponse(org.apache.http.HttpResponse) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Workflow(com.tremolosecurity.provisioning.core.Workflow) Gson(com.google.gson.Gson) KeyStoreException(java.security.KeyStoreException) StreamException(org.cryptacular.StreamException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) KeyManagementException(java.security.KeyManagementException) JoseException(org.jose4j.lang.JoseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ParseException(org.json.simple.parser.ParseException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) EncodingException(org.cryptacular.EncodingException) IOException(java.io.IOException)

Example 78 with Workflow

use of com.tremolosecurity.provisioning.core.Workflow in project OpenUnison by TremoloSecurity.

the class OpenShiftTarget method deleteUser.

@Override
public void deleteUser(User user, Map<String, Object> request) throws ProvisioningException {
    int approvalID = 0;
    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }
    Workflow workflow = (Workflow) request.get("WORKFLOW");
    user = this.findUser(user.getUserID(), new HashSet<String>(), request);
    try {
        String token = this.getAuthToken();
        HttpCon con = this.createClient();
        Gson gson = new Gson();
        try {
            StringBuffer b = new StringBuffer();
            b.append("/apis/user.openshift.io/v1/users/").append(user.getUserID());
            String json = this.callWSDelete(token, con, b.toString());
            Response resp = gson.fromJson(json, Response.class);
            if (resp.getStatus() != null && !resp.getStatus().equalsIgnoreCase("success")) {
                throw new Exception("Unable to delete " + user.getUserID() + " - " + resp.getReason());
            }
            this.cfgMgr.getProvisioningEngine().logAction(name, true, ActionType.Delete, approvalID, workflow, "name", user.getUserID());
            for (String group : user.getGroups()) {
                this.removeUserFromGroup(token, con, user.getUserID(), group, approvalID, workflow);
            }
        } finally {
            if (con != null) {
                con.getBcm().shutdown();
                con.getHttp().close();
            }
        }
    } catch (Exception e) {
        throw new ProvisioningException("Could not delete user " + user.getUserID());
    }
}
Also used : CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Response(com.tremolosecurity.unison.openshiftv3.model.Response) HttpResponse(org.apache.http.HttpResponse) HttpCon(com.tremolosecurity.provisioning.util.HttpCon) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Workflow(com.tremolosecurity.provisioning.core.Workflow) Gson(com.google.gson.Gson) KeyStoreException(java.security.KeyStoreException) StreamException(org.cryptacular.StreamException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) KeyManagementException(java.security.KeyManagementException) JoseException(org.jose4j.lang.JoseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ParseException(org.json.simple.parser.ParseException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) EncodingException(org.cryptacular.EncodingException) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

Workflow (com.tremolosecurity.provisioning.core.Workflow)78 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)68 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)32 IOException (java.io.IOException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)22 ClientProtocolException (org.apache.http.client.ClientProtocolException)21 Attribute (com.tremolosecurity.saml.Attribute)19 ArrayList (java.util.ArrayList)18 LDAPException (com.novell.ldap.LDAPException)17 HashMap (java.util.HashMap)17 User (com.tremolosecurity.provisioning.core.User)16 HashSet (java.util.HashSet)15 ParseException (org.json.simple.parser.ParseException)14 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)12 JSONObject (org.json.simple.JSONObject)12 Gson (com.google.gson.Gson)11 LDAPEntry (com.novell.ldap.LDAPEntry)11 LDAPAttribute (com.novell.ldap.LDAPAttribute)10 GitLabApiException (org.gitlab4j.api.GitLabApiException)10 SQLException (java.sql.SQLException)9