3 Commits

Author SHA1 Message Date
xxx
ff9e212366 fixed: 修复LDAP同步部门重复写入bug 2023-11-20 10:43:59 +08:00
xxx
c3b3e06a07 fixed: LDAP服务不存在属性读取报错的bug 2023-11-17 11:51:07 +08:00
xxx
8e60deb3bc readme 2023-11-16 09:25:25 +08:00
3 changed files with 23 additions and 12 deletions

View File

@@ -35,7 +35,3 @@
- 保留页脚处版权信息。 - 保留页脚处版权信息。
- 保留源代码中的协议。 - 保留源代码中的协议。
- 如果修改了代码,则必须在文件中进行说明。 - 如果修改了代码,则必须在文件中进行说明。
● 允许
- 私用、商用、修改。

View File

@@ -136,6 +136,12 @@ public class LDAPBus {
} }
// 写入本地缓存 // 写入本地缓存
depIdKeyByName.put(fullName, depId); depIdKeyByName.put(fullName, depId);
// 写入本地缓存
LdapDepartment storedLdapDepartment = new LdapDepartment();
storedLdapDepartment.setUuid(uuid);
storedLdapDepartment.setDn(dn);
storedLdapDepartment.setDepartmentId(depId);
ldapDepartments.put(uuid, storedLdapDepartment);
} }
} }

View File

@@ -25,6 +25,7 @@ import java.util.*;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.NamingEnumeration; import javax.naming.NamingEnumeration;
import javax.naming.NamingException; import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes; import javax.naming.directory.Attributes;
import javax.naming.directory.SearchControls; import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult; import javax.naming.directory.SearchResult;
@@ -148,7 +149,7 @@ public class LdapUtil {
} }
// 唯一特征值 // 唯一特征值
String uSNCreated = (String) attributes.get("uSNCreated").get(); String uSNCreated = getAttribute(attributes, "uSNCreated");
if (StringUtil.isEmpty(uSNCreated)) { if (StringUtil.isEmpty(uSNCreated)) {
continue; continue;
} }
@@ -253,17 +254,16 @@ public class LdapUtil {
ldapUser.setDn(item.getName()); ldapUser.setDn(item.getName());
// name解析 // name解析
String displayName = (String) attributes.get("displayName").get(); String displayName = getAttribute(attributes, "displayName");
if (StringUtil.isEmpty(displayName)) { if (StringUtil.isEmpty(displayName)) {
displayName = (String) attributes.get("cn").get(); displayName = getAttribute(attributes, "cn");
} }
ldapUser.setCn(displayName); ldapUser.setCn(displayName);
// 邮箱解析 // 邮箱解析
String email = String email = getAttribute(attributes, "mail");
attributes.get("mail") == null ? null : (String) attributes.get("mail").get(); if (StringUtil.isEmpty(email)) {
if (email == null) { getAttribute(attributes, "email");
email = attributes.get("email") == null ? null : (String) attributes.get("email").get();
} }
ldapUser.setEmail(email); ldapUser.setEmail(email);
@@ -296,6 +296,15 @@ public class LdapUtil {
return ldapUser; return ldapUser;
} }
private static String getAttribute(Attributes attributes, String keyName)
throws NamingException {
Attribute attribute = attributes.get(keyName);
if (attribute == null) {
return null;
}
return (String) attribute.get();
}
private static String baseDNOuScope(String baseDN) { private static String baseDNOuScope(String baseDN) {
List<String> ouScopes = new ArrayList<>(); List<String> ouScopes = new ArrayList<>();
String[] rdnList = baseDN.toLowerCase().split(","); String[] rdnList = baseDN.toLowerCase().split(",");