From 9fef487b131ce507c7f4da3b7684261dac845823 Mon Sep 17 00:00:00 2001 From: xxx Date: Wed, 20 Sep 2023 16:41:32 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20LDAP=E7=9A=84=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E8=A7=A3=E6=9E=90=E9=9C=80=E8=A6=81=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E4=B8=8A=E7=BA=A7=E7=BB=84=E7=BB=87=E4=BD=9C=E7=94=A8?= =?UTF-8?q?=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../playedu/common/util/ldap/LdapUtil.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/playedu-common/src/main/java/xyz/playedu/common/util/ldap/LdapUtil.java b/playedu-common/src/main/java/xyz/playedu/common/util/ldap/LdapUtil.java index 5453950..34a6d18 100644 --- a/playedu-common/src/main/java/xyz/playedu/common/util/ldap/LdapUtil.java +++ b/playedu-common/src/main/java/xyz/playedu/common/util/ldap/LdapUtil.java @@ -134,14 +134,8 @@ public class LdapUtil { return null; } - List ouScopes = new ArrayList<>(); - String[] rdnList = baseDN.toLowerCase().split(","); - for (int i = 0; i < rdnList.length; i++) { - if (rdnList[i].startsWith("ou=")) { - ouScopes.add(rdnList[i]); - } - } - String ouScopesStr = String.join(",", ouScopes); + // baseDN中的ou作用域 + String ouScopesStr = baseDNOuScope(baseDN); List units = new ArrayList<>(); while (result.hasMoreElements()) { @@ -242,7 +236,12 @@ public class LdapUtil { } // ou计算 - String[] rdnList = ldapUser.getDn().toLowerCase().split(","); + String baseDNOuScope = baseDNOuScope(baseDN); + String[] rdnList = + (baseDNOuScope.isEmpty() + ? ldapUser.getDn().toLowerCase() + : ldapUser.getDn().toLowerCase() + "," + baseDNOuScope) + .split(","); List ou = new ArrayList<>(); for (String s : rdnList) { if (StringUtil.startsWith(s, "ou=")) { @@ -271,6 +270,17 @@ public class LdapUtil { return ldapUser; } + private static String baseDNOuScope(String baseDN) { + List ouScopes = new ArrayList<>(); + String[] rdnList = baseDN.toLowerCase().split(","); + for (String s : rdnList) { + if (s.startsWith("ou=")) { + ouScopes.add(s); + } + } + return String.join(",", ouScopes); + } + public static void closeContext(LdapContext ldapCtx) { if (ldapCtx == null) { return;