Search in sources :

Example 56 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class GroupDAO method create.

/**
 * @param group
 * @throws org.apache.directory.fortress.core.CreateException
 */
Group create(Group group) throws CreateException {
    LdapConnection ld = null;
    String nodeDn = getDn(group.getName(), group.getContextId());
    try {
        LOG.debug("create group dn [{}]", nodeDn);
        Entry myEntry = new DefaultEntry(nodeDn);
        myEntry.add(SchemaConstants.OBJECT_CLASS_AT, GROUP_OBJ_CLASS);
        myEntry.add(SchemaConstants.CN_AT, group.getName());
        // protocol is required:
        myEntry.add(GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol());
        // type is required:
        myEntry.add(GlobalIds.TYPE, group.getType().toString());
        loadAttrs(group.getMembers(), myEntry, SchemaConstants.MEMBER_AT);
        loadProperties(group.getProperties(), myEntry, GROUP_PROPERTY_ATTR_IMPL, '=');
        if (StringUtils.isNotEmpty(group.getDescription())) {
            myEntry.add(SchemaConstants.DESCRIPTION_AT, group.getDescription());
        }
        ld = getAdminConnection();
        add(ld, myEntry);
    } catch (LdapException e) {
        String error = "create group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.GROUP_ADD_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return group;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CreateException(org.apache.directory.fortress.core.CreateException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 57 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class GroupDAO method remove.

/**
 * This method will remove group node from diretory.
 *
 * @param group
 * @throws org.apache.directory.fortress.core.RemoveException
 */
Group remove(Group group) throws RemoveException {
    LdapConnection ld = null;
    String nodeDn = getDn(group.getName(), group.getContextId());
    LOG.debug("remove group dn [{}]", nodeDn);
    try {
        ld = getAdminConnection();
        delete(ld, nodeDn, group);
    } catch (LdapException e) {
        String error = "remove group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
        throw new RemoveException(GlobalErrIds.GROUP_DELETE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return group;
}
Also used : RemoveException(org.apache.directory.fortress.core.RemoveException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 58 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class GroupDAO method deassign.

/**
 * @param entity
 * @param userDn
 * @return
 * @throws org.apache.directory.fortress.core.UpdateException
 */
Group deassign(Group entity, String userDn) throws FinderException, UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity.getName(), entity.getContextId());
    LOG.debug("deassign group property dn [{}], member dn [{}]", dn, userDn);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, SchemaConstants.MEMBER_AT, userDn));
        ld = getAdminConnection();
        modify(ld, dn, mods, entity);
    } catch (LdapException e) {
        String error = "deassign group name [" + entity.getName() + "] user dn [" + userDn + "] caught " + "LDAPException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.GROUP_USER_DEASSIGN_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return get(entity);
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) ArrayList(java.util.ArrayList) UpdateException(org.apache.directory.fortress.core.UpdateException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 59 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class OrgUnitDAO method findByKey.

/**
 * @param entity
 * @return
 * @throws FinderException
 */
OrgUnit findByKey(OrgUnit entity) throws FinderException {
    OrgUnit oe = null;
    LdapConnection ld = null;
    Dn dn = getDn(entity);
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, ORGUNIT_ATRS);
        if (findEntry == null) {
            String warning = "findByKey orgUnit name [" + entity.getName() + "] type [" + entity.getType() + "] COULD NOT FIND ENTRY for dn [" + dn + "]";
            int errCode;
            if (entity.getType() == OrgUnit.Type.PERM) {
                errCode = GlobalErrIds.ORG_NOT_FOUND_PERM;
            } else {
                errCode = GlobalErrIds.ORG_NOT_FOUND_USER;
            }
            throw new FinderException(errCode, warning);
        }
        oe = getEntityFromLdapEntry(findEntry, 0, entity.getContextId());
    } catch (LdapNoSuchObjectException e) {
        String warning = "findByKey orgUnit name [" + entity.getName() + "] type [" + entity.getType() + "] COULD NOT FIND ENTRY for dn [" + dn + "]";
        int errCode;
        if (entity.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_NOT_FOUND_PERM;
        } else {
            errCode = GlobalErrIds.ORG_NOT_FOUND_USER;
        }
        throw new FinderException(errCode, warning);
    } catch (LdapException e) {
        String error = "findByKey orgUnitName [" + entity.getName() + "] type [" + entity.getType() + "] dn [" + dn + "] caught LdapException=" + e;
        int errCode;
        if (entity.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_READ_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_READ_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return oe;
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) FinderException(org.apache.directory.fortress.core.FinderException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 60 with LdapConnection

use of org.apache.directory.ldap.client.api.LdapConnection in project directory-fortress-core by apache.

the class OrganizationalUnitDAO method remove.

/**
 * @param oe
 * @throws org.apache.directory.fortress.core.RemoveException
 */
void remove(OrganizationalUnit oe) throws RemoveException {
    LdapConnection ld = null;
    String nodeDn = SchemaConstants.OU_AT + "=" + oe.getName() + ",";
    if (StringUtils.isNotEmpty(oe.getParent())) {
        nodeDn += SchemaConstants.OU_AT + "=" + oe.getParent() + ",";
    }
    nodeDn += getRootDn(oe.getContextId(), GlobalIds.SUFFIX);
    LOG.info("remove container dn [{}]", nodeDn);
    try {
        ld = getAdminConnection();
        deleteRecursive(ld, nodeDn);
    } catch (CursorException e) {
        String error = "remove container node dn [" + nodeDn + "] caught CursorException=" + e.getMessage();
        throw new RemoveException(GlobalErrIds.CNTR_DELETE_FAILED, error, e);
    } catch (LdapException e) {
        String error = "remove container node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
        throw new RemoveException(GlobalErrIds.CNTR_DELETE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
Also used : RemoveException(org.apache.directory.fortress.core.RemoveException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)180 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)166 ArrayList (java.util.ArrayList)90 FinderException (org.apache.directory.fortress.core.FinderException)73 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)65 Entry (org.apache.directory.api.ldap.model.entry.Entry)52 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)49 Modification (org.apache.directory.api.ldap.model.entry.Modification)43 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)41 UpdateException (org.apache.directory.fortress.core.UpdateException)41 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)37 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)20 CreateException (org.apache.directory.fortress.core.CreateException)17 RemoveException (org.apache.directory.fortress.core.RemoveException)17 IOException (java.io.IOException)14 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)14 Permission (org.apache.directory.fortress.core.model.Permission)9 Dn (org.apache.directory.api.ldap.model.name.Dn)7 EntryCursor (org.apache.directory.api.ldap.model.cursor.EntryCursor)6 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)6