fix: 用户登录问题

This commit is contained in:
shiziyuan9527 2020-07-14 20:58:52 +08:00
parent cd9f39c8b1
commit 5cc3755dcd
2 changed files with 18 additions and 5 deletions

View File

@ -20,6 +20,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
@ -110,7 +112,8 @@ public class ShiroDBRealm extends AuthorizingRealm {
private AuthenticationInfo loginLdapMode(String userId, String password) {
UserDTO user = userService.getLoginUser(userId, UserSource.LDAP.name());
//
UserDTO user = userService.getLoginUser(userId, Arrays.asList(UserSource.LDAP.name(), UserSource.LOCAL.name()));
String msg;
if (user == null) {
msg = "The user does not exist: " + userId;
@ -126,10 +129,10 @@ public class ShiroDBRealm extends AuthorizingRealm {
}
private AuthenticationInfo loginLocalMode(String userId, String password) {
UserDTO user = userService.getLoginUser(userId, UserSource.LOCAL.name());
UserDTO user = userService.getLoginUser(userId, Collections.singletonList(UserSource.LOCAL.name()));
String msg;
if (user == null) {
user = userService.getUserDTOByEmail(userId);
user = userService.getLoginUserByEmail(userId, UserSource.LOCAL.name());
if (user == null) {
msg = "The user does not exist: " + userId;
logger.warn(msg);

View File

@ -180,9 +180,9 @@ public class UserService {
return userDTO;
}
public UserDTO getLoginUser(String userId, String source) {
public UserDTO getLoginUser(String userId, List<String> list) {
UserExample example = new UserExample();
example.createCriteria().andIdEqualTo(userId).andSourceEqualTo(source);
example.createCriteria().andIdEqualTo(userId).andSourceIn(list);
if (userMapper.countByExample(example) == 0) {
return null;
}
@ -199,6 +199,16 @@ public class UserService {
return getUserDTO(users.get(0).getId());
}
public UserDTO getLoginUserByEmail(String email, String source) {
UserExample example = new UserExample();
example.createCriteria().andEmailEqualTo(email).andSourceEqualTo(source);
List<User> users = userMapper.selectByExample(example);
if (users == null || users.size() <= 0) {
return null;
}
return getUserDTO(users.get(0).getId());
}
public UserRoleDTO getUserRole(String userId) {
UserRoleDTO userRoleDTO = new UserRoleDTO();
//