Search in sources :

Example 1 with MatterMostProvider

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;
}
Also used : HttpCon(com.tremolosecurity.provisioning.util.HttpCon) JSONObject(org.json.simple.JSONObject) MatterMostProvider(com.tremolosecurity.provisioning.core.providers.MatterMostProvider) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) JSONParser(org.json.simple.parser.JSONParser) IOException(java.io.IOException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) IOException(java.io.IOException)

Aggregations

ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)1 MatterMostProvider (com.tremolosecurity.provisioning.core.providers.MatterMostProvider)1 HttpCon (com.tremolosecurity.provisioning.util.HttpCon)1 IOException (java.io.IOException)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1