Search in sources :

Example 21 with LdapConnection

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

the class AdminRoleDAO method deassign.

/**
 * This method will remove the supplied DN as a role occupant to the target record.
 * This data will be stored in the {@link GlobalIds#ADMIN_ROLE_ROOT} container.
 *
 * @param entity record contains {@link AdminRole#name}.  Null attributes will be ignored.
 * @param userDn contains the DN for userId who is being deassigned.
 * @return input record back to client.
 * @throws UpdateException in the event LDAP errors occur.
 */
AdminRole deassign(AdminRole entity, String userDn) throws UpdateException {
    LdapConnection ld = null;
    String dn = getDn(entity);
    try {
        List<Modification> mods = new ArrayList<Modification>();
        mods.add(new DefaultModification(ModificationOperation.REMOVE_ATTRIBUTE, ROLE_OCCUPANT, userDn));
        ld = getAdminConnection();
        modify(ld, dn, mods, entity);
    } catch (LdapException e) {
        String error = "deassign role name [" + entity.getName() + "] user dn [" + userDn + "] caught LdapException=" + e.getMessage();
        throw new UpdateException(GlobalErrIds.ARLE_USER_DEASSIGN_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return 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 22 with LdapConnection

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

the class AdminRoleDAO method findAssignedRoles.

/**
 * @param userDn
 * @return
 * @throws FinderException
 */
List<String> findAssignedRoles(String userDn, String contextId) throws FinderException {
    List<String> roleNameList = new ArrayList<>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(contextId, GlobalIds.ADMIN_ROLE_ROOT);
    try {
        String filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")";
        filter += "(" + ROLE_OCCUPANT + "=" + userDn + "))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_NM_ATR, false, GlobalIds.BATCH_SIZE);
        while (searchResults.next()) {
            roleNameList.add(getAttribute(searchResults.getEntry(), ROLE_NM));
        }
    } catch (LdapException e) {
        String error = "findAssignedRoles userDn [" + userDn + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_OCCUPANT_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findAssignedRoles userDn [" + userDn + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_OCCUPANT_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleNameList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 23 with LdapConnection

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

the class AdminRoleDAO method remove.

/**
 * This method will completely remove the AdminRole from the directory.  It will use {@link AdminRole#name} as key.
 * This operation is performed on the {@link GlobalIds#ADMIN_ROLE_ROOT} container.
 *
 * @param role record contains {@link AdminRole#name}.
 * @throws RemoveException in the event LDAP errors occur.
 */
void remove(AdminRole role) throws RemoveException {
    LdapConnection ld = null;
    String dn = getDn(role);
    try {
        ld = getAdminConnection();
        delete(ld, dn, role);
    } catch (LdapException e) {
        String error = "remove role name=" + role.getName() + " LdapException=" + e.getMessage();
        throw new RemoveException(GlobalErrIds.ARLE_DELETE_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
}
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 24 with LdapConnection

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

the class AdminRoleDAO method getAllDescendants.

/**
 * @param contextId
 * @return
 * @throws FinderException
 */
List<Graphable> getAllDescendants(String contextId) throws FinderException {
    String[] DESC_ATRS = { ROLE_NM, GlobalIds.PARENT_NODES };
    List<Graphable> descendants = new ArrayList<>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(contextId, GlobalIds.ADMIN_ROLE_ROOT);
    String filter = null;
    try {
        filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + GlobalIds.PARENT_NODES + "=*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, DESC_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            descendants.add(unloadDescendants(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "getAllDescendants filter [" + filter + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "getAllDescendants filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return descendants;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) Graphable(org.apache.directory.fortress.core.model.Graphable) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 25 with LdapConnection

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

the class PermDAO method createObject.

/**
 * @param entity
 * @return
 * @throws org.apache.directory.fortress.core.CreateException
 */
PermObj createObject(PermObj entity) throws CreateException {
    LdapConnection ld = null;
    String dn = getDn(entity, entity.getContextId());
    try {
        Entry entry = new DefaultEntry(dn);
        entry.add(SchemaConstants.OBJECT_CLASS_AT, PERM_OBJ_OBJ_CLASS);
        entry.add(GlobalIds.POBJ_NAME, entity.getObjName());
        // this will generatre a new random, unique id on this entity:
        entity.setInternalId();
        // create the rDN:
        entry.add(GlobalIds.FT_IID, entity.getInternalId());
        // ou is required:
        entry.add(SchemaConstants.OU_AT, entity.getOu());
        // description is optional:
        if (StringUtils.isNotEmpty(entity.getDescription())) {
            entry.add(SchemaConstants.DESCRIPTION_AT, entity.getDescription());
        }
        // type is optional:
        if (StringUtils.isNotEmpty(entity.getType())) {
            entry.add(GlobalIds.TYPE, entity.getType());
        }
        // if the props is null don't try to load these attributes
        if (PropUtil.isNotEmpty(entity.getProperties())) {
            loadProperties(entity.getProperties(), entry, GlobalIds.PROPS);
        }
        // now add the new entry to directory:
        ld = getAdminConnection();
        add(ld, entry, entity);
        entity.setDn(dn);
    } catch (LdapException e) {
        String error = "createObject perm obj [" + entity.getObjName() + "] caught LdapException=" + e.getMessage();
        throw new CreateException(GlobalErrIds.PERM_ADD_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
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)

Aggregations

LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)178 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)164 ArrayList (java.util.ArrayList)89 FinderException (org.apache.directory.fortress.core.FinderException)73 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)63 Entry (org.apache.directory.api.ldap.model.entry.Entry)50 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 LdapNetworkConnection (org.apache.directory.ldap.client.api.LdapNetworkConnection)14 IOException (java.io.IOException)12 Permission (org.apache.directory.fortress.core.model.Permission)9 Dn (org.apache.directory.api.ldap.model.name.Dn)7 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)6 SecurityException (org.apache.directory.fortress.core.SecurityException)6