use of com.tremolosecurity.provisioning.core.providers.MatterMostProvider 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;
}
Aggregations