Skip to content
Permalink
Browse files

[JENKINS-42686] Better handle of PartialResultException

  • Loading branch information...
fbelzunc committed Mar 14, 2017
1 parent 943701d commit 29bf6c3e4f5b053a308a57553dcae6ae72920645
@@ -51,6 +51,7 @@

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.PartialResultException;
import javax.naming.TimeLimitExceededException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
@@ -719,12 +720,20 @@ private void recursiveGroupLookup(DirContext context, Attributes id, Set<Granted
}

private void parseMembers(String userDN, Set<GrantedAuthority> groups, NamingEnumeration<SearchResult> renum) throws NamingException {
while (renum.hasMore()) {
Attributes a = renum.next().getAttributes();
Attribute cn = a.get("cn");
if (LOGGER.isLoggable(Level.FINE))
LOGGER.fine(userDN+" is a member of "+cn);
groups.add(new GrantedAuthorityImpl(cn.get().toString()));
try {
while (renum.hasMore()) {
Attributes a = renum.next().getAttributes();
Attribute cn = a.get("cn");
if (LOGGER.isLoggable(Level.FINE))
LOGGER.fine(userDN + " is a member of " + cn);
groups.add(new GrantedAuthorityImpl(cn.get().toString()));
}
} catch (PartialResultException e) {
// See JENKINS-42687. Just log the exception. Sometimes all the groups are correctly
// retrieved but this Exception is launched as a last element of the NamingEnumeration
// Even if it is really a PartialResultException, I don't see why this should be a blocker
// I think a better approach is to log the Exception and continue
LOGGER.log(Level.WARNING, String.format("JENKINS-42687 Might be more members for user %s", userDN), e);
}
}

@@ -31,6 +31,7 @@
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.PartialResultException;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
@@ -96,6 +97,13 @@ public Attributes searchOne(String filter, Object... args) throws NamingExceptio
LOG.finer("no result");
}
return null;
} catch (PartialResultException e) {
// See JENKINS-42687. On this case might happen that the search instead of returning an empty
// NamingEnumeration is returning a PartialResultException. Again, In my opinion this should
// not be a blocker. We should just log the Exception and return null like on the case where
// any user was found.
LOG.log(Level.WARNING, String.format("JENKINS-42687 The user we are looking for might exist"), e);
return null;
} finally {
r.close();
}

0 comments on commit 29bf6c3

Please sign in to comment.
You can’t perform that action at this time.