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());
}
}
}
}
}
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();
}
}
}
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());
}
}
Aggregations