Skip to content

Commit

Permalink
Merge pull request #2117 from PrarthonaPaul/ELY-2545
Browse files Browse the repository at this point in the history
[ELY-2545] referral-mode="ignore" and filter-base-dn=rootDN cause javax.naming.PartialResultException
  • Loading branch information
Skyllarr committed Mar 15, 2024
2 parents 4f0795e + 448ac16 commit bf5bcf0
Showing 1 changed file with 19 additions and 2 deletions.
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

0 comments on commit bf5bcf0

Please sign in to comment.