use of com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection in project OpenUnison by TremoloSecurity.
the class LDAPProvider method setUserPassword.
@Override
public void setUserPassword(User user, Map<String, Object> request) throws ProvisioningException {
StringBuffer filter = new StringBuffer();
filter.append("(").append(this.userIDAttribute).append("=").append(user.getUserID()).append(")");
int approvalID = 0;
if (request.containsKey("APPROVAL_ID")) {
approvalID = (Integer) request.get("APPROVAL_ID");
}
Workflow workflow = (Workflow) request.get("WORKFLOW");
try {
LdapConnection con;
try {
con = this.ldapPool.getConnection();
} catch (Exception e) {
throw new ProvisioningException("Could not get LDAP connection " + user.getUserID(), e);
}
try {
LDAPSearchResults res = con.getConnection().search(this.searchBase, 2, filter.toString(), new String[] { "1.1" }, false);
if (!res.hasMore()) {
throw new ProvisioningException("Could not find user");
}
String dn = res.next().getDN();
LDAPModification mod = new LDAPModification(LDAPModification.REPLACE, new LDAPAttribute("userPassword", user.getPassword()));
con.getConnection().modify(dn, mod);
this.cfgMgr.getProvisioningEngine().logAction(this.name, false, ActionType.Replace, approvalID, workflow, "userPassword", "*********");
} finally {
con.returnCon();
}
} catch (Exception e) {
throw new ProvisioningException("Could not set user's password", e);
}
}
use of com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection in project OpenUnison by TremoloSecurity.
the class LDAPProvider 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");
try {
StringBuffer filter = new StringBuffer();
filter.append("(").append(this.userIDAttribute).append("=").append(user.getUserID()).append(")");
LdapConnection con;
try {
con = this.ldapPool.getConnection();
} catch (Exception e) {
throw new ProvisioningException("Could not get LDAP connection " + user.getUserID(), e);
}
try {
LDAPSearchResults res = con.getConnection().search(searchBase, 2, filter.toString(), new String[] { "1.1" }, false);
if (!res.hasMore()) {
throw new ProvisioningException("User does not exist " + user.getUserID());
}
String dn = res.next().getDN();
while (res.hasMore()) res.next();
con.getConnection().delete(dn);
this.cfgMgr.getProvisioningEngine().logAction(this.name, true, ActionType.Delete, approvalID, workflow, "dn", dn);
} finally {
con.returnCon();
}
} catch (LDAPException e) {
throw new ProvisioningException("Could not delete user " + user.getUserID(), e);
}
}
use of com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection in project OpenUnison by TremoloSecurity.
the class ADProvider method deleteUser.
@Override
public void deleteUser(User user, Map<String, Object> request) throws ProvisioningException {
try {
StringBuffer filter = new StringBuffer();
filter.append("(").append(this.userIDAttribute).append("=").append(user.getUserID()).append(")");
LdapConnection con;
try {
con = this.ldapPool.getConnection();
} catch (Exception e) {
StringBuffer b = new StringBuffer();
b.append("Could not get LDAP connection ").append(user.getUserID());
throw new ProvisioningException(b.toString(), e);
}
try {
doDelete(user, filter, con.getConnection(), request);
} finally {
con.returnCon();
}
} catch (LDAPException e) {
StringBuffer b = new StringBuffer();
b.append("Could not delete user ").append(user.getUserID());
throw new ProvisioningException(b.toString(), e);
}
}
use of com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection in project OpenUnison by TremoloSecurity.
the class ADProvider method addGroup.
@Override
public void addGroup(String name, Map<String, String> additionalAttributes, 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");
String dn = new StringBuilder("cn=").append(name).append(",").append(additionalAttributes.get("base")).toString();
LDAPEntry entry = new LDAPEntry(dn);
entry.getAttributeSet().add(new LDAPAttribute("objectClass", "group"));
entry.getAttributeSet().add(new LDAPAttribute("cn", name));
try {
LdapConnection con;
try {
con = this.ldapPool.getConnection();
} catch (Exception e) {
throw new ProvisioningException("Could not get LDAP connection " + user.getUserID(), e);
}
try {
con.getConnection().add(entry);
this.cfgMgr.getProvisioningEngine().logAction(name, false, ActionType.Add, approvalID, workflow, "domain-group", name);
} finally {
con.returnCon();
}
} catch (Exception e) {
throw new ProvisioningException("Could not set user's password", e);
}
}
use of com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection in project OpenUnison by TremoloSecurity.
the class ADProvider method isGroupExists.
@Override
public boolean isGroupExists(String name, User user, Map<String, Object> request) throws ProvisioningException {
try {
LdapConnection con;
try {
con = this.ldapPool.getConnection();
} catch (Exception e) {
throw new ProvisioningException("Could not get LDAP connection " + user.getUserID(), e);
}
try {
logger.info("Looking for '" + name + "' - " + and(equal("objectClass", "group"), equal("cn", name)).toString());
LDAPSearchResults res = con.getConnection().search(this.searchBase, 2, and(equal("objectClass", "group"), equal("cn", name)).toString(), new String[] { "1.1" }, false);
if (!res.hasMore()) {
logger.info("Not found");
return false;
} else {
try {
LDAPEntry entry = res.next();
} catch (LDAPReferralException e) {
logger.info("referral, skipping");
return false;
}
}
return true;
} finally {
con.returnCon();
}
} catch (Exception e) {
throw new ProvisioningException("Could not set user's password", e);
}
}
Aggregations