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;
}
Aggregations