use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class AttributeChange method getIdFromEmail.
public String getIdFromEmail(String email) throws ProvisioningException {
HttpCon con = null;
try {
con = this.createClient();
email = email.replace("'", "''");
String json = this.callWS(con, new StringBuilder().append("/users?$filter=").append(URLEncoder.encode(new StringBuilder().append("mail eq '").append(email).append("'").toString(), "UTf-8")).toString());
JSONObject root = (JSONObject) new JSONParser().parse(json);
JSONArray vals = (JSONArray) root.get("value");
if (vals.size() == 0) {
return null;
} else if (vals.size() > 1) {
throw new ProvisioningException("Multiple entries for " + email);
} else {
return ((JSONObject) vals.get(0)).get("userPrincipalName").toString();
}
} 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 MatterMostProvider 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");
HashSet<String> attrs = new HashSet<String>();
attrs.add("id");
attrs.add("username");
User fromServer = this.findUser(user.getUserID(), attrs, request);
if (fromServer == null) {
logger.warn("User '" + user.getUserID() + "' not found");
return;
}
String id = fromServer.getAttribs().get("id").getValues().get(0);
StringBuilder sb = new StringBuilder();
sb.append("/api/v4/users/").append(id);
HttpCon con = null;
try {
con = this.createClient();
String jsonFromMatterMost = this.callDeleteWS(con, sb.toString());
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Replace, approvalID, workflow, "delete_at", "0");
} catch (Exception e) {
throw new ProvisioningException("Could not delete '" + user.getUserID() + "'", e);
} finally {
if (con != null) {
try {
con.getHttp().close();
} catch (IOException e) {
}
con.getBcm().close();
}
}
}
use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class MatterMostProvider method createClient.
public HttpCon createClient() throws Exception {
ArrayList<Header> defheaders = new ArrayList<Header>();
defheaders.add(new BasicHeader("X-Csrf-Token", "1"));
BasicHttpClientConnectionManager bhcm = new BasicHttpClientConnectionManager(cfgMgr.getHttpClientSocketRegistry());
RequestConfig rc = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).setRedirectsEnabled(false).build();
CloseableHttpClient http = HttpClients.custom().setConnectionManager(bhcm).setDefaultHeaders(defheaders).setDefaultRequestConfig(rc).build();
HttpCon con = new HttpCon();
con.setBcm(bhcm);
con.setHttp(http);
return con;
}
use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class MatterMostProvider method createUser.
@Override
public void createUser(User user, 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");
String userID = user.getUserID();
HttpCon con = null;
try {
con = this.createClient();
JSONObject newUser = new JSONObject();
for (String attribute : attributes) {
Attribute attr = user.getAttribs().get(attribute);
if (attr != null) {
newUser.put(attr.getName(), attr.getValues().get(0));
}
}
StringBuilder sb = new StringBuilder();
for (String group : user.getGroups()) {
sb.append(group).append(' ');
}
String groups = sb.toString().trim();
if (!groups.isEmpty()) {
newUser.put("roles", groups);
}
if (user.getPassword() != null) {
// user.setPassword(new GenPasswd(25,true,true,true,true).getPassword());
newUser.put("password", user.getPassword());
}
this.callWSPost(con, "/api/v4/users", newUser.toString());
this.cfgMgr.getProvisioningEngine().logAction(this.name, true, ActionType.Add, approvalID, workflow, "username", userID);
for (String attribute : attributes) {
Attribute attr = user.getAttribs().get(attribute);
if (attr != null) {
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow, attr.getName(), attr.getValues().get(0));
}
}
if (user.getPassword() != null) {
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow, "password", "*******");
}
for (String group : user.getGroups()) {
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Add, approvalID, workflow, "role", group);
}
} catch (Exception e) {
throw new ProvisioningException("Could create '" + userID + "'", e);
} finally {
if (con != null) {
try {
con.getHttp().close();
} catch (IOException e) {
}
con.getBcm().close();
}
}
}
use of com.tremolosecurity.provisioning.util.HttpCon in project OpenUnison by TremoloSecurity.
the class MatterMostProvider method findUser.
@Override
public User findUser(String userID, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
userID = userID.toLowerCase();
HttpCon con = null;
try {
con = this.createClient();
JSONObject mmUser = loadUserJson(userID, con);
if (mmUser == null) {
return null;
}
User user = new User(userID);
for (String attribute : attributes) {
Object val = mmUser.get(attribute);
if (val != null) {
user.getAttribs().put(attribute, new Attribute(attribute, val.toString()));
}
}
String groups = (String) mmUser.get("roles");
if (groups != null) {
StringTokenizer toker = new StringTokenizer(groups, " ", false);
while (toker.hasMoreTokens()) {
user.getGroups().add(toker.nextToken());
}
}
return user;
} catch (Exception e) {
throw new ProvisioningException("Could not load '" + userID + "'", e);
} finally {
if (con != null) {
try {
con.getHttp().close();
} catch (IOException e) {
}
con.getBcm().close();
}
}
}
Aggregations