Search in sources :

Example 41 with SearchCursor

use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.

the class AdminRoleDAO method findRoles.

/**
 * @param adminRole
 * @return
 * @throws FinderException
 */
List<AdminRole> findRoles(AdminRole adminRole) throws FinderException {
    List<AdminRole> roleList = new ArrayList<AdminRole>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(adminRole.getContextId(), GlobalIds.ADMIN_ROLE_ROOT);
    String filter;
    try {
        String searchVal = encodeSafeText(adminRole.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + ROLE_NM + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            roleList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, adminRole.getContextId()));
        }
    } catch (LdapException e) {
        String error = "findRoles name [" + adminRole.getName() + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findRoles name [" + adminRole.getName() + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
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) AdminRole(org.apache.directory.fortress.core.model.AdminRole) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 42 with SearchCursor

use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.

the class AdminRoleDAO method findRoles.

/**
 * @param adminRole
 * @param limit
 * @return
 * @throws FinderException
 */
List<String> findRoles(AdminRole adminRole, int limit) throws FinderException {
    List<String> roleList = new ArrayList<String>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(adminRole.getContextId(), GlobalIds.ADMIN_ROLE_ROOT);
    String filter;
    String searchVal = null;
    try {
        searchVal = encodeSafeText(adminRole.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + ROLE_NM + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_NM_ATR, false, limit);
        while (searchResults.next()) {
            Entry entry = searchResults.getEntry();
            roleList.add(getAttribute(entry, ROLE_NM));
        }
    } catch (LdapException e) {
        String error = "findRoles name [" + searchVal + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findRoles name [" + searchVal + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
Also used : 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) 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 43 with SearchCursor

use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.

the class RoleDAO 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.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++, contextId));
        }
    } catch (LdapException e) {
        String error = "getAllDescendants filter [" + filter + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "getAllDescendants filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_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 44 with SearchCursor

use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.

the class RoleDAO method groupRoles.

/**
 * Pull back all roles that are assigned to a particular group.
 * @param group
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Role> groupRoles(Group group) throws FinderException {
    List<Role> roleList = new ArrayList<>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(group.getContextId(), GlobalIds.ROLE_ROOT);
    StringBuilder filterbuf = new StringBuilder();
    try {
        // loop for each group member....
        // add role name to search filter
        // 
        List<String> members = group.getMembers();
        if (CollectionUtils.isNotEmpty(members)) {
            filterbuf.append(GlobalIds.FILTER_PREFIX);
            filterbuf.append(GlobalIds.ROLE_OBJECT_CLASS_NM);
            filterbuf.append(")(");
            filterbuf.append("|");
            for (String memberdn : members) {
                filterbuf.append("(");
                filterbuf.append(SchemaConstants.ENTRY_DN_AT);
                filterbuf.append("=");
                filterbuf.append(memberdn);
                filterbuf.append(")");
            }
            filterbuf.append("))");
            ld = getAdminConnection();
            SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filterbuf.toString(), ROLE_ATRS, false, GlobalIds.BATCH_SIZE);
            long sequence = 0;
            while (searchResults.next()) {
                roleList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, group.getContextId()));
            }
        } else {
            String error = "groupRoles passed empty member list";
            throw new FinderException(GlobalErrIds.GROUP_MEMBER_NULL, error);
        }
    } catch (LdapException e) {
        String error = "groupRoles filter [" + filterbuf.toString() + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "groupRoles filter [" + filterbuf.toString() + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) 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 45 with SearchCursor

use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.

the class RoleDAO method findRoles.

/**
 * @param role
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Role> findRoles(Role role) throws FinderException {
    List<Role> roleList = new ArrayList<>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(role.getContextId(), GlobalIds.ROLE_ROOT);
    String filter = null;
    try {
        String searchVal = encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + ROLE_NM + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            roleList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, role.getContextId()));
        }
    } catch (LdapException e) {
        String error = "findRoles filter [" + filter + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findRoles filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) 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)

Aggregations

SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)55 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)52 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)50 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)49 FinderException (org.apache.directory.fortress.core.FinderException)48 ArrayList (java.util.ArrayList)44 Entry (org.apache.directory.api.ldap.model.entry.Entry)11 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)7 Permission (org.apache.directory.fortress.core.model.Permission)7 Dn (org.apache.directory.api.ldap.model.name.Dn)5 User (org.apache.directory.fortress.core.model.User)5 IOException (java.io.IOException)4 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)4 SearchRequestImpl (org.apache.directory.api.ldap.model.message.SearchRequestImpl)4 HashSet (java.util.HashSet)3 Response (org.apache.directory.api.ldap.model.message.Response)3 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)3 AuthZ (org.apache.directory.fortress.core.model.AuthZ)3 SDSet (org.apache.directory.fortress.core.model.SDSet)3 HashMap (java.util.HashMap)2