Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-42686] Better handle of PartialResultException
  • Loading branch information
fbelzunc committed Mar 14, 2017
1 parent 943701d commit 29bf6c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 29bf6c3

Please sign in to comment.