refactor(LDAP): 用户登录优化
--story=1004504 --user=lyh LDAP用户登录优化 https://www.tapd.cn/55049933/s/1090284
This commit is contained in:
parent
31067e9f41
commit
ed921bdef0
|
@ -63,9 +63,6 @@ public class LdapService {
|
|||
|
||||
// 检查属性是否存在
|
||||
getMappingAttr("name", dirContextOperations);
|
||||
getMappingAttr("email", dirContextOperations);
|
||||
|
||||
|
||||
return dirContextOperations;
|
||||
}
|
||||
|
||||
|
@ -85,17 +82,12 @@ public class LdapService {
|
|||
}
|
||||
|
||||
DirContextOperations dirContext = authenticate(request);
|
||||
String email = getMappingAttr("email", dirContext);
|
||||
String email = getNotRequiredMappingAttr("email", dirContext);
|
||||
String userId = getMappingAttr("username", dirContext);
|
||||
|
||||
SecurityUtils.getSubject().getSession().setAttribute("authenticate", UserSource.LDAP.name());
|
||||
SecurityUtils.getSubject().getSession().setAttribute("email", email);
|
||||
|
||||
|
||||
if (StringUtils.isBlank(email)) {
|
||||
MSException.throwException(Translator.get("login_fail_email_null"));
|
||||
}
|
||||
|
||||
// userId 或 email 有一个相同即为存在本地用户
|
||||
User u = userService.selectUser(userId, email);
|
||||
String name = getMappingAttr("name", dirContext);
|
||||
|
@ -106,6 +98,9 @@ public class LdapService {
|
|||
User user = new User();
|
||||
user.setId(userId);
|
||||
user.setName(name);
|
||||
if (StringUtils.isBlank(email)) {
|
||||
email = userId + "@localhost.localhost";
|
||||
}
|
||||
user.setEmail(email);
|
||||
|
||||
if (StringUtils.isNotBlank(phone)) {
|
||||
|
|
|
@ -164,15 +164,16 @@ public class UserService {
|
|||
public User selectUser(String userId, String email) {
|
||||
User user = userMapper.selectByPrimaryKey(userId);
|
||||
if (user == null) {
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andEmailEqualTo(email);
|
||||
List<User> users = userMapper.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(users)) {
|
||||
return users.get(0);
|
||||
if (StringUtils.isNotBlank(email)) {
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andEmailEqualTo(email);
|
||||
List<User> users = userMapper.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(users)) {
|
||||
return users.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return user;
|
||||
|
||||
}
|
||||
|
||||
private void checkUserParam(User user) {
|
||||
|
|
Loading…
Reference in New Issue