use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class AttributeChange method deleteUser.
@Override
public void deleteUser(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 {
con = this.createClient();
this.callDelete(con, new StringBuilder().append("/users/").append(URLEncoder.encode(user.getUserID(), "UTf-8")).toString());
this.cfgMgr.getProvisioningEngine().logAction(this.name, true, ActionType.Delete, approvalID, workflow, "userPrincipalName", user.getUserID());
} catch (Exception e) {
throw new ProvisioningException("Could not delete user", e);
} finally {
try {
con.getHttp().close();
} catch (IOException e) {
}
con.getBcm().close();
}
}
use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class AttributeChange method findUser.
@Override
public User findUser(String userID, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
HttpCon con = null;
Set<String> attributesLocal = new HashSet<String>();
attributesLocal.addAll(attributes);
attributes = attributesLocal;
if (!attributes.contains("id")) {
attributes.add("id");
}
StringBuilder select = new StringBuilder();
for (String attr : attributes) {
select.append(attr).append(',');
}
String selectAttrs = select.toString();
selectAttrs.subSequence(0, selectAttrs.lastIndexOf(','));
try {
con = this.createClient();
String json = this.callWS(con, new StringBuilder().append("/users/").append(URLEncoder.encode(userID, "UTf-8")).append("?$select=").append(URLEncoder.encode(selectAttrs, "UTF-8")).toString());
JSONObject root = (JSONObject) new JSONParser().parse(json);
if (root.containsKey("error")) {
JSONObject error = (JSONObject) root.get("error");
String code = (String) error.get("code");
if (code.equalsIgnoreCase("Request_ResourceNotFound")) {
return null;
} else {
throw new ProvisioningException("Could not lookup user " + json);
}
}
User user = new User((String) root.get("userPrincipalName"));
for (String attributeName : attributes) {
if (root.get(attributeName) != null) {
String val = root.get(attributeName).toString();
user.getAttribs().put(attributeName, new Attribute(attributeName, val));
}
}
json = this.callWS(con, new StringBuilder().append("/users/").append(URLEncoder.encode(userID, "UTf-8")).append("/memberOf").toString());
root = (JSONObject) new JSONParser().parse(json);
if (root.containsKey("error")) {
JSONObject error = (JSONObject) root.get("error");
String code = (String) error.get("code");
throw new ProvisioningException("Could not lookup user " + json);
}
JSONArray values = (JSONArray) root.get("value");
for (Object o : values) {
JSONObject group = (JSONObject) o;
if (group.get("@odata.type").equals("#microsoft.graph.group")) {
user.getGroups().add((String) group.get("displayName"));
}
}
return user;
} catch (Exception e) {
throw new ProvisioningException("Could not find user", e);
} finally {
try {
con.getHttp().close();
} catch (IOException e) {
}
con.getBcm().close();
}
// return null;
}
use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class AttributeChange method synUser.
private void synUser(User user, boolean addOnly, Set<String> attributes, User fromAzure, int approvalID, Workflow workflow) throws ProvisioningException {
List<AttributeChange> changes = new ArrayList<AttributeChange>();
JSONObject patch = new JSONObject();
for (String attributeName : attributes) {
if (attributeName.equals("mail") || attributeName.equals("id")) {
continue;
}
Attribute fromUser = user.getAttribs().get(attributeName);
Attribute fromAd = fromAzure.getAttribs().get(attributeName);
if (fromUser != null && fromAd == null) {
patch.put(attributeName, getValue(fromUser));
changes.add(new AttributeChange(fromUser.getName(), fromUser.getValues().get(0), ActionType.Add));
} else if (fromUser != null && fromAd != null && !(fromUser.getValues().get(0).equals(fromAd.getValues().get(0)))) {
patch.put(attributeName, getValue(fromUser));
changes.add(new AttributeChange(fromUser.getName(), fromUser.getValues().get(0), ActionType.Replace));
} else if (fromUser == null && fromAd != null && !addOnly) {
patch.put(attributeName, null);
changes.add(new AttributeChange(fromAd.getName(), fromAd.getValues().get(0), ActionType.Delete));
}
}
String id;
if (fromAzure.getAttribs().get("id") != null) {
id = fromAzure.getAttribs().get("id").getValues().get(0);
} else {
id = user.getAttribs().get("id").getValues().get(0);
}
HttpCon con = null;
try {
con = this.createClient();
StringBuilder sb = new StringBuilder();
this.callWSPatchJson(con, sb.append("/users/").append(URLEncoder.encode(user.getUserID(), "UTf-8")).toString(), patch.toString());
for (AttributeChange change : changes) {
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, change.action, approvalID, workflow, change.name, change.value);
}
Map<String, String> groups = this.loadGroups(con);
Set<String> curentGroups = new HashSet<String>();
curentGroups.addAll(fromAzure.getGroups());
for (String group : user.getGroups()) {
if (!curentGroups.contains(group)) {
String uri = new StringBuilder().append("/groups/").append(groups.get(group)).append("/members/$ref").toString();
JSONObject root = new JSONObject();
root.put("@odata.id", new StringBuilder().append("https://graph.microsoft.com/v1.0/directoryObjects/").append(id).toString());
this.callWSPostJsonNoReesponseExpected(con, uri, root.toString());
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow, "group", group);
}
}
if (!addOnly) {
curentGroups = new HashSet<String>();
curentGroups.addAll(user.getGroups());
for (String group : fromAzure.getGroups()) {
if (!curentGroups.contains(group)) {
String uri = new StringBuilder().append("/groups/").append(groups.get(group)).append("/members/").append(id).append("/$ref").toString();
this.callDelete(con, uri);
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Delete, approvalID, workflow, "group", group);
}
}
}
} catch (Exception e) {
throw new ProvisioningException("Could not find user", e);
} finally {
try {
con.getHttp().close();
} catch (IOException e) {
}
con.getBcm().close();
}
}
use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class AddMatterMostTeam method doTask.
@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
MatterMostProvider mm = (MatterMostProvider) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(target).getProvider();
HttpCon con = null;
try {
con = mm.createClient();
StringBuilder sb = new StringBuilder();
sb.append("/api/v4/teams/name/").append(teamName);
String jsonResp = mm.callWS(con, sb.toString());
JSONObject team = (JSONObject) new JSONParser().parse(jsonResp);
String teamId = (String) team.get("id");
if (teamId == null) {
throw new ProvisioningException("Team '" + teamName + "' does not exist");
}
JSONObject userFromMM = mm.loadUserJson(user.getUserID(), con);
if (userFromMM == null) {
throw new ProvisioningException("User '" + user.getUserID() + "' does not exist");
}
String userId = (String) userFromMM.get("id");
if (userId == null) {
throw new ProvisioningException("User '" + user.getUserID() + "' does not exist");
}
JSONObject addTeam = new JSONObject();
addTeam.put("team_id", teamId);
addTeam.put("user_id", userId);
sb.setLength(0);
sb.append("/api/v4/teams/").append(teamId).append("/members");
mm.callWSPost(con, sb.toString(), addTeam.toString());
} catch (Exception e) {
throw new ProvisioningException("Could not add team", e);
} finally {
if (con != null) {
try {
con.getHttp().close();
} catch (IOException e) {
}
con.getBcm().close();
}
}
return true;
}
use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class UserPrincipal method createClient.
private HttpCon createClient(String lusername, String lpassword) throws Exception {
BasicHttpClientConnectionManager bhcm = new BasicHttpClientConnectionManager(cfgMgr.getHttpClientSocketRegistry());
RequestConfig rc = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
CloseableHttpClient http = HttpClients.custom().setConnectionManager(bhcm).setDefaultRequestConfig(rc).build();
http.execute(new HttpGet(this.url + "/ipa/session/login_kerberos")).close();
doLogin(lusername, lpassword, http);
HttpCon con = new HttpCon();
con.setBcm(bhcm);
con.setHttp(http);
return con;
}
Aggregations