refactor(系统设置): LDAP登录逻辑

This commit is contained in:
shiziyuan9527 2023-01-09 15:23:19 +08:00 committed by 刘瑞斌
parent 41e7f8bffe
commit 493f678643
2 changed files with 14 additions and 5 deletions

View File

@ -107,14 +107,22 @@ public class LdapService {
} else {
// 更新
u.setName(name);
if (StringUtils.isNotBlank(phone)) {
u.setPhone(phone);
}
if (StringUtils.isNotBlank(email)) {
u.setEmail(email);
}
userLoginService.updateUser(u);
}
// 执行 LocalRealm LDAP 登录逻辑
LoginRequest loginRequest = new LoginRequest();
if (u != null) {
// 根据id或email查找到了用户后续使用此用户id登录
loginRequest.setUsername(u.getId());
} else {
loginRequest.setUsername(userId);
}
loginRequest.setAuthenticate(UserSource.LDAP.name());
Optional<SessionUser> sessionUser = userLoginService.login(loginRequest, session, locale);

View File

@ -65,7 +65,8 @@ public class UserLoginService {
}
private UserDTO loginLdapMode(String userId) {
UserDTO loginUser = getLoginUser(userId, Collections.singletonList(UserSource.LDAP.name()));
// LDAP验证通过之后如果用户存在且用户类型是LDAP或LOCAL返回用户
UserDTO loginUser = getLoginUser(userId, Arrays.asList(UserSource.LDAP.name(), UserSource.LOCAL.name()));
if (loginUser == null) {
MSException.throwException(Translator.get("user_not_found_or_not_unique"));
}