Search in sources :

Example 6 with CursorLdapReferralException

use of org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException in project midpoint by Evolveum.

the class AbstractLdapTest method ldapSearch.

protected List<Entry> ldapSearch(LdapNetworkConnection connection, String baseDn, String filter, SearchScope scope, String... attributes) throws LdapException, CursorException {
    logger.trace("LDAP search base={}, filter={}, scope={}, attributes={}", baseDn, filter, scope, attributes);
    SearchRequest searchRequest = new SearchRequestImpl();
    searchRequest.setBase(new Dn(baseDn));
    searchRequest.setFilter(filter);
    searchRequest.setScope(scope);
    searchRequest.addAttributes(attributes);
    searchRequest.ignoreReferrals();
    List<Entry> entries = new ArrayList<>();
    try {
        SearchCursor searchCursor = connection.search(searchRequest);
        while (searchCursor.next()) {
            Response response = searchCursor.get();
            if (response instanceof SearchResultEntry) {
                Entry entry = ((SearchResultEntry) response).getEntry();
                entries.add(entry);
            }
        }
        searchCursor.close();
    } catch (IOException e) {
        throw new IllegalStateException("IO Error: " + e.getMessage(), e);
    } catch (CursorLdapReferralException e) {
        throw new IllegalStateException("Got referral to: " + e.getReferralInfo(), e);
    }
    return entries;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) CursorLdapReferralException(org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) Dn(org.apache.directory.api.ldap.model.name.Dn) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)6 CursorLdapReferralException (org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException)6 Entry (org.apache.directory.api.ldap.model.entry.Entry)6 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)5 EntryCursor (org.apache.directory.api.ldap.model.cursor.EntryCursor)5 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 Dn (org.apache.directory.api.ldap.model.name.Dn)3 InternalServerError (io.kamax.mxisd.exception.InternalServerError)2 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)2 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)2 SearchRequestImpl (org.apache.directory.api.ldap.model.message.SearchRequestImpl)2 EntryCursorImpl (org.apache.directory.ldap.client.api.EntryCursorImpl)2 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)2 GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)2 User (org.apache.openmeetings.db.entity.user.User)2 OmException (org.apache.openmeetings.util.OmException)2 ThreePid (io.kamax.matrix.ThreePid)1 BackendAuthResult (io.kamax.mxisd.auth.provider.BackendAuthResult)1 LdapConfig (io.kamax.mxisd.config.ldap.LdapConfig)1 UserDirectorySearchResult (io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult)1