Skip to content
Permalink
Browse files
Merge pull request #20 from fbelzunc/JENKINS-28857
[FIXED JENKINS-28857] Catch the case in which LDAP times out after some seconds
  • Loading branch information
fbelzunc committed Mar 1, 2016
2 parents 8ed46fc + 3f3f5c0 commit 0c908ff2aba57e2098916598ff03aef5f9b047aa
Showing 1 changed file with 13 additions and 3 deletions.
@@ -436,9 +436,19 @@ private Set<GrantedAuthority> resolveGroups(String domainDN, String userDN, DirC
switch (groupLookupStrategy) {
case AUTO:
// try the accurate one first, and if it's too slow fall back to recursive in the hope that it's faster
long start = System.currentTimeMillis();
boolean found = chainGroupLookup(domainDN, userDN, context, groups);
long duration = (System.currentTimeMillis() - start) / TimeUnit2.SECONDS.toMillis(1);
long start = System.nanoTime();
boolean found = false;
long duration = 0;
try {
found = chainGroupLookup(domainDN, userDN, context, groups);
duration = TimeUnit2.NANOSECONDS.toSeconds(System.nanoTime() - start);
} catch (NamingException e) {
if (e.getMessage().contains("LDAP response read timed out")) {
LOGGER.log(Level.WARNING, "LDAP response read time out. AD will fall back to recursive lookup", e);
} else {
throw e;
}
}
if (!found || duration >= 10) {
LOGGER.warning(String.format("AD chain lookup is taking too long (%dms). Falling back to recursive lookup", duration));
groupLookupStrategy = GroupLookupStrategy.RECURSIVE;

0 comments on commit 0c908ff

Please sign in to comment.