use of com.tremolosecurity.provisioning.core.Workflow in project OpenUnison by TremoloSecurity.
the class ADProvider method doSync.
private void doSync(User user, boolean fromUserOnly, Set<String> attributes, StringBuffer filter, LDAPConnection con, Map<String, Object> request) throws LDAPException, ProvisioningException {
LDAPSearchResults res = con.search(searchBase, 2, filter.toString(), this.toStringArray(attributes), false);
int approvalID = 0;
boolean isExternal = false;
LDAPEntry ldapUser = null;
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
Workflow workflow = (Workflow) request.get("WORKFLOW");
if (!res.hasMore()) {
if (this.supportExternalUsers) {
ldapUser = this.getMyVDUser(filter);
if (ldapUser == null) {
this.createUser(user, attributes, request);
} else {
isExternal = true;
ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>();
HashSet<String> done = new HashSet<String>();
syncUser(user, fromUserOnly, attributes, con, approvalID, workflow, mods, done, ldapUser, isExternal, request);
}
} else {
this.createUser(user, attributes, request);
}
} else {
ArrayList<LDAPModification> mods = new ArrayList<LDAPModification>();
HashSet<String> done = new HashSet<String>();
try {
ldapUser = res.next();
try {
while (res.hasMore()) res.next();
} catch (LDAPReferralException e) {
}
} catch (LDAPReferralException e) {
if (this.supportExternalUsers) {
ldapUser = this.getMyVDUser(filter);
if (ldapUser == null) {
this.createUser(user, attributes, request);
return;
} else {
isExternal = true;
}
} else {
this.createUser(user, attributes, request);
return;
}
}
syncUser(user, fromUserOnly, attributes, con, approvalID, workflow, mods, done, ldapUser, isExternal, request);
}
}
use of com.tremolosecurity.provisioning.core.Workflow in project OpenUnison by TremoloSecurity.
the class ADProvider method doSetPassword.
private void doSetPassword(User user, StringBuffer filter, LDAPConnection con, Map<String, Object> request) throws LDAPException, ProvisioningException {
int approvalID = 0;
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
Workflow workflow = (Workflow) request.get("WORKFLOW");
LDAPSearchResults res = con.search(this.searchBase, 2, filter.toString(), new String[] { "1.1" }, false);
if (!res.hasMore()) {
throw new ProvisioningException("Could not find user");
}
LDAPEntry entry = res.next();
String dn = entry.getDN();
StringBuffer password = new StringBuffer();
password.append('"').append(user.getPassword()).append('"');
byte[] unicodePwd;
try {
unicodePwd = password.toString().getBytes("UTF-16LE");
} catch (UnsupportedEncodingException e) {
throw new ProvisioningException("Could not generate password", e);
}
LDAPModification mod = new LDAPModification(LDAPModification.REPLACE, new LDAPAttribute("unicodePwd", unicodePwd));
try {
con.modify(dn, mod);
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Replace, approvalID, workflow, "unicodePwd", "*******");
} catch (LDAPException e) {
throw new ProvisioningException("Could not set password", e);
}
res = con.search(dn, 0, "(objectClass=*)", new String[] { "userAccountControl" }, false);
res.hasMore();
entry = res.next();
LDAPAttribute attr = entry.getAttribute("userAccountControl");
int val = Integer.parseInt(attr.getStringValue());
if (!user.getAttribs().containsKey("userAccountControl")) {
if ((val & 2) == 2) {
val -= 2;
}
if ((val & 65536) != 65536) {
val += 65536;
}
mod = new LDAPModification(LDAPModification.REPLACE, new LDAPAttribute("userAccountControl", Integer.toString(val)));
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Replace, approvalID, workflow, "userAccountControl", Integer.toString(val));
con.modify(dn, mod);
} else {
int userAccountControlFromUser = Integer.parseInt(user.getAttribs().get("userAccountControl").getValues().get(0));
if (val != userAccountControlFromUser) {
mod = new LDAPModification(LDAPModification.REPLACE, new LDAPAttribute("userAccountControl", Integer.toString(userAccountControlFromUser)));
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Replace, approvalID, workflow, "userAccountControl", Integer.toString(userAccountControlFromUser));
con.modify(dn, mod);
}
}
}
use of com.tremolosecurity.provisioning.core.Workflow in project OpenUnison by TremoloSecurity.
the class AttributeChange method syncUser.
@Override
public void syncUser(User user, boolean addOnly, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
User fromAzure = this.findUser(user.getUserID(), attributes, request);
if (fromAzure == null) {
this.createUser(user, attributes, request);
return;
}
int approvalID = 0;
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
Workflow workflow = (Workflow) request.get("WORKFLOW");
synUser(user, addOnly, attributes, fromAzure, approvalID, workflow);
}
use of com.tremolosecurity.provisioning.core.Workflow 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.core.Workflow 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();
}
}
}
Aggregations