refactor(LDAP): 登录时更新ldap用户信息

This commit is contained in:
shiziyuan9527 2021-04-25 18:12:23 +08:00 committed by 刘瑞斌
parent 4f0751788f
commit 2786714482
1 changed files with 10 additions and 2 deletions

View File

@ -49,11 +49,13 @@ public class LdapController {
// userId email 有一个相同即为存在本地用户 // userId email 有一个相同即为存在本地用户
User u = userService.selectUser(userId, email); User u = userService.selectUser(userId, email);
String name = ldapService.getMappingAttr("name", dirContext);
String phone = ldapService.getNotRequiredMappingAttr("phone", dirContext);
if (u == null) { if (u == null) {
// 新建用户 获取LDAP映射属性 // 新建用户 获取LDAP映射属性
String name = ldapService.getMappingAttr("name", dirContext); // String name = ldapService.getMappingAttr("name", dirContext);
String phone = ldapService.getNotRequiredMappingAttr("phone", dirContext); // String phone = ldapService.getNotRequiredMappingAttr("phone", dirContext);
User user = new User(); User user = new User();
user.setId(userId); user.setId(userId);
@ -66,6 +68,12 @@ public class LdapController {
user.setSource(UserSource.LDAP.name()); user.setSource(UserSource.LDAP.name());
userService.addLdapUser(user); userService.addLdapUser(user);
} else {
// 更新
u.setName(name);
u.setPhone(phone);
u.setEmail(email);
userService.updateUser(u);
} }
// 执行 LocalRealm LDAP 登录逻辑 // 执行 LocalRealm LDAP 登录逻辑