Search in sources :

Example 46 with SearchCursor

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

the class GroupDAO method find.

/**
 * @param user
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Group> find(User user) throws FinderException {
    List<Group> groupList = new ArrayList<>();
    LdapConnection ld = null;
    SearchCursor searchResults;
    String groupRoot = getRootDn(user.getContextId(), GlobalIds.GROUP_ROOT);
    String filter = null;
    try {
        encodeSafeText(user.getUserId(), GlobalIds.USERID_LEN);
        filter = GlobalIds.FILTER_PREFIX + GROUP_OBJECT_CLASS_IMPL + ")(" + SchemaConstants.MEMBER_AT + "=" + user.getDn() + "))";
        ld = getAdminConnection();
        searchResults = search(ld, groupRoot, SearchScope.ONELEVEL, filter, GROUP_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            groupList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (CursorException e) {
        String error = "find filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } catch (LdapException e) {
        String error = "find filter [" + filter + "] caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return groupList;
}
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 47 with SearchCursor

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

the class GroupDAO method roleGroups.

/**
 * @param role
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Group> roleGroups(Role role) throws FinderException {
    List<Group> groupList = new ArrayList<>();
    LdapConnection ld = null;
    SearchCursor searchResults;
    String groupRoot = getRootDn(role.getContextId(), GlobalIds.GROUP_ROOT);
    String filter = null;
    try {
        encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GROUP_OBJECT_CLASS_IMPL + ")(" + SchemaConstants.MEMBER_AT + "=" + role.getDn() + "))";
        ld = getAdminConnection();
        searchResults = search(ld, groupRoot, SearchScope.ONELEVEL, filter, GROUP_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            groupList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (CursorException e) {
        String error = "find filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } catch (LdapException e) {
        String error = "find filter [" + filter + "] caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return groupList;
}
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 48 with SearchCursor

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

the class GroupDAO method find.

/**
 * @param group
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Group> find(Group group) throws FinderException {
    List<Group> groupList = new ArrayList<>();
    LdapConnection ld = null;
    SearchCursor searchResults;
    String groupRoot = getRootDn(group.getContextId(), GlobalIds.GROUP_ROOT);
    String filter = null;
    try {
        String searchVal = encodeSafeText(group.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GROUP_OBJECT_CLASS_IMPL + ")(" + SchemaConstants.CN_AT + "=" + searchVal + "*))";
        ld = getAdminConnection();
        searchResults = search(ld, groupRoot, SearchScope.ONELEVEL, filter, GROUP_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            groupList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (CursorException e) {
        String error = "find filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } catch (LdapException e) {
        String error = "find filter [" + filter + "] caught LDAPException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.GROUP_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return groupList;
}
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 49 with SearchCursor

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

the class OrgUnitDAO method getOrgs.

/**
 * @param orgUnit
 * @return
 * @throws FinderException
 */
Set<String> getOrgs(OrgUnit orgUnit) throws FinderException {
    Set<String> ouSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    LdapConnection ld = null;
    String orgUnitRoot = getOrgRoot(orgUnit);
    try {
        String filter = "(objectclass=" + ORGUNIT_OBJECT_CLASS_NM + ")";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, orgUnitRoot, SearchScope.ONELEVEL, filter, ORGUNIT_ATR, false, GlobalIds.BATCH_SIZE);
        while (searchResults.next()) {
            ouSet.add(getAttribute(searchResults.getEntry(), SchemaConstants.OU_AT));
        }
        searchResults.close();
    } catch (LdapException e) {
        String error = "getOrgs type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught LdapException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_GET_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_GET_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } catch (CursorException e) {
        String error = "getOrgs type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught CursorException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_GET_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_GET_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } catch (IOException e) {
        String error = "getOrgs type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught IOException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_GET_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_GET_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return ouSet;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) TreeSet(java.util.TreeSet) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 50 with SearchCursor

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

the class OrgUnitDAO method findOrgs.

/**
 * @param orgUnit
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<OrgUnit> findOrgs(OrgUnit orgUnit) throws FinderException {
    List<OrgUnit> orgUnitList = new ArrayList<>();
    LdapConnection ld = null;
    String orgUnitRoot = getOrgRoot(orgUnit);
    try {
        String searchVal = encodeSafeText(orgUnit.getName(), GlobalIds.ROLE_LEN);
        String filter = GlobalIds.FILTER_PREFIX + ORGUNIT_OBJECT_CLASS_NM + ")(" + SchemaConstants.OU_AT + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, orgUnitRoot, SearchScope.ONELEVEL, filter, ORGUNIT_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            orgUnitList.add(getEntityFromLdapEntry(searchResults.getEntry(), sequence++, orgUnit.getContextId()));
        }
    } catch (LdapException e) {
        String error = "findOrgs search val [" + orgUnit.getName() + "] type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught LdapException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_SEARCH_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_SEARCH_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } catch (CursorException e) {
        String error = "findOrgs search val [" + orgUnit.getName() + "] type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught CursorException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_SEARCH_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_SEARCH_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return orgUnitList;
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) 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