Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ELY-2545] referral-mode="ignore" and filter-base-dn=rootDN cause javax.naming.PartialResultException #2117

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.PartialResultException;
import javax.naming.ReferralException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
Expand Down Expand Up @@ -1083,7 +1084,7 @@ public boolean tryAdvance(Consumer<? super SearchResult> action) {
throw referralException;
}

if ( ! result.hasMore()) { // end of page
if ( ! hasMore(result)) { // end of page
if ( ! (pageSize != 0 && context instanceof LdapContext) ) {
log.trace("Identity iterating - pagination not supported - end of list");
finished = true;
Expand All @@ -1105,7 +1106,7 @@ public boolean tryAdvance(Consumer<? super SearchResult> action) {
result.close();

result = searchWithPagination();
if ( ! result.hasMore()) {
if ( ! hasMore(result)) {
log.trace("Identity iterating - even after page loading no results - end of list");
finished = true;
return false; // no more elements
Expand Down Expand Up @@ -1219,6 +1220,22 @@ private SearchControls createSearchControls() {
private DirContext getContext() {
return context;
}

/*
* wrapper of NamingEnumeration<SearchResult>#hasMore() to ignore PartialResultException when referral-mode=ignore
*/
private boolean hasMore(NamingEnumeration<SearchResult> result) throws PartialResultException, NamingException {
try {
return result.hasMore();
} catch (PartialResultException e) {
if (getContext().getEnvironment().get(DirContext.REFERRAL).equals("ignore")) {
log.trace("Ignored PartialResultException with referral-mode=ignore: " + e.toString(false));
return false;
} else {
throw e;
}
}
}
}

static class IdentityMapping {
Expand Down
Loading