From 25e41753278ae531c5afdd0c2403d69404d326d3 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 20 Jun 2017 10:17:19 +0200 Subject: [PATCH] LDAP-62 Improve handling of PartialResultException --- .../org/sonar/plugins/ldap/LdapSearch.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sonar-ldap-plugin/src/main/java/org/sonar/plugins/ldap/LdapSearch.java b/sonar-ldap-plugin/src/main/java/org/sonar/plugins/ldap/LdapSearch.java index 5838589..a41dd1b 100644 --- a/sonar-ldap-plugin/src/main/java/org/sonar/plugins/ldap/LdapSearch.java +++ b/sonar-ldap-plugin/src/main/java/org/sonar/plugins/ldap/LdapSearch.java @@ -141,23 +141,28 @@ public NamingEnumeration find() throws NamingException { */ public SearchResult findUnique() throws NamingException { NamingEnumeration result = find(); - try { - if (result.hasMore()) { - SearchResult obj = result.next(); - if (!result.hasMore()) { - return obj; - } - throw new NamingException("Non unique result for " + toString()); + if (hasMore(result)) { + SearchResult obj = result.next(); + if (!hasMore(result)) { + return obj; } + throw new NamingException("Non unique result for " + toString()); + } + return null; + } + + private static boolean hasMore(NamingEnumeration result) throws NamingException { + try { + return result.hasMore(); } catch (PartialResultException e) { + LOG.debug("More result might be forthcoming if the referral is followed", e); // See LDAP-62 and http://docs.oracle.com/javase/jndi/tutorial/ldap/referral/jndi.html : // When the LDAP service provider receives a referral despite your having set Context.REFERRAL to "ignore", it will throw a // PartialResultException(in the API reference documentation) to indicate that more results might be forthcoming if the referral is // followed. In this case, the server does not support the Manage Referral control and is supporting referral updates in some other // way. - return null; + return false; } - return null; } @Override