Search in sources :

Example 6 with LdapConnection

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);
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) LDAPModification(com.novell.ldap.LDAPModification) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Workflow(com.tremolosecurity.provisioning.core.Workflow) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPReferralException(com.novell.ldap.LDAPReferralException) LdapConnection(com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection)

Example 7 with LdapConnection

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);
    }
}
Also used : LDAPSearchResults(com.novell.ldap.LDAPSearchResults) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Workflow(com.tremolosecurity.provisioning.core.Workflow) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPReferralException(com.novell.ldap.LDAPReferralException) LdapConnection(com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection)

Example 8 with LdapConnection

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);
    }
}
Also used : LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LDAPReferralException(com.novell.ldap.LDAPReferralException) LdapConnection(com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection)

Example 9 with LdapConnection

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);
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPEntry(com.novell.ldap.LDAPEntry) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Workflow(com.tremolosecurity.provisioning.core.Workflow) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LDAPReferralException(com.novell.ldap.LDAPReferralException) LdapConnection(com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection)

Example 10 with LdapConnection

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);
    }
}
Also used : LDAPReferralException(com.novell.ldap.LDAPReferralException) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LDAPReferralException(com.novell.ldap.LDAPReferralException) LdapConnection(com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection)

Aggregations

LDAPException (com.novell.ldap.LDAPException)13 LDAPReferralException (com.novell.ldap.LDAPReferralException)13 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)13 LdapConnection (com.tremolosecurity.provisioning.util.ldap.pool.LdapConnection)13 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)5 LDAPEntry (com.novell.ldap.LDAPEntry)4 Workflow (com.tremolosecurity.provisioning.core.Workflow)4 LDAPAttribute (com.novell.ldap.LDAPAttribute)3 LDAPAttributeSet (com.novell.ldap.LDAPAttributeSet)1 LDAPModification (com.novell.ldap.LDAPModification)1 Attribute (com.tremolosecurity.saml.Attribute)1