use of com.tremolosecurity.unison.freeipa.json.IPAResponse in project OpenUnison by TremoloSecurity.
the class UserPrincipal method deleteAttribute.
private void deleteAttribute(UserPrincipal principal, String attrName, 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>();
additionalParams.put(attrName, "");
modify.getParams().add(additionalParams);
IPAResponse resp = this.executeIPACall(modify, con);
} else {
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(attrName, "");
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.json.IPAResponse in project OpenUnison by TremoloSecurity.
the class UserPrincipal method deleteGroup.
@Override
public void deleteGroup(String name, 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");
IPACall groupSearch = new IPACall();
groupSearch.setId(0);
groupSearch.setMethod("group_del");
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);
this.cfgMgr.getProvisioningEngine().logAction(name, true, ActionType.Delete, approvalID, workflow, "group-object", name);
} catch (Exception e) {
throw new ProvisioningException("Could not find groups", e);
} finally {
if (con != null) {
con.getBcm().close();
}
}
}
use of com.tremolosecurity.unison.freeipa.json.IPAResponse in project OpenUnison by TremoloSecurity.
the class UserPrincipal method createUser.
public void createUser(User user, Set<String> attributes, 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 createUser = new IPACall();
createUser.setId(0);
createUser.setMethod("user_add");
ArrayList<String> userArray = new ArrayList<String>();
userArray.add(principal.getUid());
createUser.getParams().add(userArray);
HashMap<String, Object> userAttrs = new HashMap<String, Object>();
for (String attrName : attributes) {
Attribute attr = user.getAttribs().get(attrName);
if (attr != null && !attr.getName().equalsIgnoreCase("uid")) {
if (attr.getValues().size() == 1) {
userAttrs.put(attr.getName(), attr.getValues().get(0));
} else {
ArrayList vals = new ArrayList<String>();
vals.addAll(attr.getValues());
userAttrs.put(attr.getName(), vals);
}
}
}
createUser.getParams().add(userAttrs);
IPAResponse resp = this.executeIPACall(createUser, con);
this.cfgMgr.getProvisioningEngine().logAction(name, true, ActionType.Add, approvalID, workflow, "uid", user.getUserID());
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, "uid", user.getUserID());
for (String attrName : userAttrs.keySet()) {
Object o = userAttrs.get(attrName);
if (o instanceof String) {
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, attrName, (String) o);
} else {
List<String> vals = (List<String>) o;
for (String val : vals) {
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, attrName, val);
}
}
}
for (String group : user.getGroups()) {
this.addGroup(principal, group, con, approvalID, workflow);
}
if (this.createShadowAccount) {
String password = new BigInteger(130, random).toString(32);
password = PBKDF2.generateHash(password);
user.setPassword(password);
this.setUserPassword(user, request);
}
} else {
IPACall idOveride = new IPACall();
idOveride.setId(0);
idOveride.setMethod("idoverrideuser_add");
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>();
for (String attrName : attributes) {
Attribute attr = user.getAttribs().get(attrName);
if (attr != null) {
if (attr.getName().equalsIgnoreCase("uid") && !attr.getValues().get(0).equals(user.getUserID())) {
param2.put(attr.getName(), attr.getValues().get(0));
} else if (!attr.getName().equalsIgnoreCase("uid")) {
param2.put(attr.getName(), attr.getValues().get(0));
}
}
}
idOveride.getParams().add(param2);
IPAResponse resp = this.executeIPACall(idOveride, con);
this.cfgMgr.getProvisioningEngine().logAction(name, true, ActionType.Add, approvalID, workflow, "uid", user.getUserID());
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, "uid", user.getUserID());
for (String attrName : attributes) {
Attribute attr = user.getAttribs().get(attrName);
if (attr != null) {
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, attrName, attr.getValues().get(0));
}
}
for (String group : user.getGroups()) {
this.addGroup(principal, group, con, approvalID, workflow);
}
}
} finally {
if (con != null) {
con.getBcm().shutdown();
}
}
} catch (Exception e) {
throw new ProvisioningException("Could not run search", e);
}
}
Aggregations