My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 815 attachment: 0002-Ignore-PartialResultException-from-LDAP.patch (4.1 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
From 6738cbf36bb5125005d01ba201b23f7bd354ec65 Mon Sep 17 00:00:00 2001
From: James Y Knight <foom@fuhm.net>
Date: Tue, 4 Jan 2011 02:40:32 -0500
Subject: [PATCH 2/2] Ignore PartialResultException from LDAP.

This exception occurs when the server isn't following referrals for
you, and thus the result contains a referral. That happens when you're
using Active Directory. You almost certainly don't really want to
follow referrals in AD *anyways*, so just ignore these exceptions, so
we can still use the actual data.

Inspired by:
https://src.springframework.org/svn/spring-ldap/trunk/core/src/main/java/org/springframework/ldap/core/LdapTemplate.java
---
.../com/google/gerrit/server/auth/ldap/Helper.java | 23 ++++++++++++-------
.../google/gerrit/server/auth/ldap/LdapQuery.java | 9 +++++--
2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/Helper.java b/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/Helper.java
index 675202c..3ea8b74 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/Helper.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/Helper.java
@@ -38,6 +38,7 @@ import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.PartialResultException;
import javax.naming.directory.Attribute;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
@@ -168,10 +169,12 @@ import javax.net.ssl.SSLSocketFactory;
final Attribute groupAtt = account.getAll(schema.accountMemberField);
if (groupAtt != null) {
final NamingEnumeration<?> groups = groupAtt.getAll();
- while (groups.hasMore()) {
- final String nextDN = (String) groups.next();
- recursivelyExpandGroups(groupDNs, schema, ctx, nextDN);
- }
+ try {
+ while (groups.hasMore()) {
+ final String nextDN = (String) groups.next();
+ recursivelyExpandGroups(groupDNs, schema, ctx, nextDN);
+ }
+ } catch (PartialResultException e) {}
}
}

@@ -203,10 +206,12 @@ import javax.net.ssl.SSLSocketFactory;
ctx.getAttributes(compositeGroupName).get(schema.accountMemberField);
if (in != null) {
final NamingEnumeration<?> groups = in.getAll();
- while (groups.hasMore()) {
- final String nextDN = (String) groups.next();
- recursivelyExpandGroups(groupDNs, schema, ctx, nextDN);
- }
+ try {
+ while (groups.hasMore()) {
+ final String nextDN = (String) groups.next();
+ recursivelyExpandGroups(groupDNs, schema, ctx, nextDN);
+ }
+ } catch (PartialResultException e) {}
}
} catch (NamingException e) {
LdapRealm.log.warn("Could not find group " + groupDN, e);
@@ -316,4 +321,4 @@ import javax.net.ssl.SSLSocketFactory;
}
}
}
-}
\ No newline at end of file
+}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/LdapQuery.java b/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/LdapQuery.java
index 70ce779..1fe24dc 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/LdapQuery.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/auth/ldap/LdapQuery.java
@@ -25,6 +25,7 @@ import java.util.Set;

import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
+import javax.naming.PartialResultException;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.DirContext;
@@ -69,9 +70,11 @@ class LdapQuery {
res = ctx.search(base, pattern.getRawPattern(), pattern.bind(params), sc);
try {
final List<Result> r = new ArrayList<Result>();
- while (res.hasMore()) {
- r.add(new Result(res.next()));
- }
+ try {
+ while (res.hasMore()) {
+ r.add(new Result(res.next()));
+ }
+ } catch (PartialResultException e) {}
return r;
} finally {
res.close();
--
1.7.2.3

Powered by Google Project Hosting