use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.
the class UserPrincipal method deleteUser.
public void deleteUser(User user, Map<String, Object> request) throws ProvisioningException {
UserPrincipal principal = new UserPrincipal(user.getUserID(), multiDomain, primaryDomain);
int approvalID = 0;
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
Workflow workflow = (Workflow) request.get("WORKFLOW");
try {
HttpCon con = this.createClient();
try {
if (principal.isPrimaryDomain()) {
IPACall deleteUser = new IPACall();
deleteUser.setId(0);
deleteUser.setMethod("user_del");
ArrayList<String> userArray = new ArrayList<String>();
userArray.add(principal.getUid());
deleteUser.getParams().add(userArray);
HashMap<String, String> additionalParams = new HashMap<String, String>();
deleteUser.getParams().add(additionalParams);
IPAResponse resp = this.executeIPACall(deleteUser, con);
this.cfgMgr.getProvisioningEngine().logAction(name, true, ActionType.Delete, approvalID, workflow, "uid", user.getUserID());
} else {
IPACall idOveride = new IPACall();
idOveride.setId(0);
idOveride.setMethod("idoverrideuser_del");
List<String> params = new ArrayList<String>();
params.add(this.trustViewName);
params.add(principal.getUPN());
idOveride.getParams().add(params);
Map<String, Object> param2 = new HashMap<String, Object>();
idOveride.getParams().add(param2);
try {
IPAResponse resp = this.executeIPACall(idOveride, con);
} catch (IPAException e) {
if (!e.getMessage().equalsIgnoreCase("no modifications to be performed")) {
throw e;
}
}
}
} finally {
if (con != null) {
con.getBcm().shutdown();
}
}
} catch (Exception e) {
throw new ProvisioningException("Could not run search", e);
}
}
use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.
the class UserPrincipal method setAttribute.
private void setAttribute(UserPrincipal principal, Attribute attrNew, HttpCon con, int approvalID, Workflow workflow) throws Exception {
if (principal.isPrimaryDomain()) {
IPACall modify = new IPACall();
modify.setId(0);
modify.setMethod("user_mod");
ArrayList<String> userArray = new ArrayList<String>();
userArray.add(principal.getUid());
modify.getParams().add(userArray);
HashMap<String, Object> additionalParams = new HashMap<String, Object>();
if (attrNew.getValues().size() > 1) {
additionalParams.put(attrNew.getName(), attrNew.getValues());
} else {
additionalParams.put(attrNew.getName(), attrNew.getValues().get(0));
}
modify.getParams().add(additionalParams);
try {
IPAResponse resp = this.executeIPACall(modify, con);
} catch (IPAException e) {
if (!e.getMessage().equalsIgnoreCase("no modifications to be performed")) {
throw e;
}
}
} else {
if (attrNew.getName().equalsIgnoreCase("uid") && attrNew.getValues().get(0).equals(principal.getUPN())) {
return;
}
IPACall idOveride = new IPACall();
idOveride.setId(0);
idOveride.setMethod("idoverrideuser_mod");
List<String> params = new ArrayList<String>();
params.add(this.trustViewName);
params.add(principal.getUPN());
idOveride.getParams().add(params);
Map<String, Object> param2 = new HashMap<String, Object>();
param2.put("all", true);
param2.put("rights", false);
param2.put(attrNew.getName(), attrNew.getValues().get(0));
idOveride.getParams().add(param2);
try {
IPAResponse resp = this.executeIPACall(idOveride, con);
} catch (IPAException e) {
if (!e.getMessage().equalsIgnoreCase("no modifications to be performed")) {
throw e;
}
}
}
}
use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.
the class UserPrincipal method isGroupExists.
@Override
public boolean isGroupExists(String name, User user, Map<String, Object> request) throws ProvisioningException {
IPACall groupSearch = new IPACall();
groupSearch.setId(0);
groupSearch.setMethod("group_show");
ArrayList<String> groupArray = new ArrayList<String>();
groupArray.add(name);
groupSearch.getParams().add(groupArray);
HashMap<String, String> additionalParams = new HashMap<String, String>();
groupSearch.getParams().add(additionalParams);
HttpCon con = null;
try {
con = this.createClient();
IPAResponse resp = this.executeIPACall(groupSearch, con);
return true;
} catch (IPAException ipae) {
if (ipae.getCode() == 4001) {
return false;
} else {
throw new ProvisioningException("Could not find groups", ipae);
}
} catch (Exception e) {
throw new ProvisioningException("Could not find groups", e);
} finally {
if (con != null) {
con.getBcm().close();
}
}
}
use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.
the class UserPrincipal method executeIPACall.
private IPAResponse executeIPACall(IPACall ipaCall, HttpCon con) throws IPAException, ClientProtocolException, IOException {
Gson gson = new Gson();
String json = gson.toJson(ipaCall);
if (logger.isDebugEnabled()) {
logger.debug("Outbound JSON : '" + json + "'");
}
HttpClient http = con.getHttp();
StringEntity str = new StringEntity(json, ContentType.APPLICATION_JSON);
HttpPost httppost = new HttpPost(this.url + "/ipa/session/json");
httppost.addHeader("Referer", this.url + "/ipa/ui/");
httppost.setEntity(str);
HttpResponse resp = http.execute(httppost);
BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
StringBuffer b = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
b.append(line);
}
if (logger.isDebugEnabled()) {
logger.debug("Inbound JSON : " + b.toString());
}
EntityUtils.consumeQuietly(resp.getEntity());
httppost.completed();
IPAResponse ipaResponse = gson.fromJson(b.toString(), IPAResponse.class);
if (ipaResponse.getError() != null) {
IPAException ipaException = new IPAException(ipaResponse.getError().getMessage());
ipaException.setCode(ipaResponse.getError().getCode());
ipaException.setName(ipaResponse.getError().getName());
throw ipaException;
} else {
return ipaResponse;
}
}
use of com.tremolosecurity.unison.freeipa.util.IPAException in project OpenUnison by TremoloSecurity.
the class UserPrincipal method executeIPABatchCall.
private IPABatchResponse executeIPABatchCall(IPACall ipaCall, HttpCon con) throws IPAException, ClientProtocolException, IOException {
Gson gson = new Gson();
String json = gson.toJson(ipaCall);
if (logger.isDebugEnabled()) {
logger.debug("Outbound JSON : '" + json + "'");
}
HttpClient http = con.getHttp();
StringEntity str = new StringEntity(json, ContentType.APPLICATION_JSON);
HttpPost httppost = new HttpPost(this.url + "/ipa/session/json");
httppost.addHeader("Referer", this.url + "/ipa/ui/");
httppost.setEntity(str);
HttpResponse resp = http.execute(httppost);
BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
StringBuffer b = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
b.append(line);
}
if (logger.isDebugEnabled()) {
logger.debug("Inbound JSON : " + b.toString());
}
EntityUtils.consumeQuietly(resp.getEntity());
httppost.completed();
IPABatchResponse ipaResponse = gson.fromJson(b.toString(), IPABatchResponse.class);
if (ipaResponse.getError() != null) {
IPAException ipaException = new IPAException(ipaResponse.getError().getMessage());
ipaException.setCode(ipaResponse.getError().getCode());
ipaException.setName(ipaResponse.getError().getName());
throw ipaException;
} else {
return ipaResponse;
}
}
Aggregations