|
|
@@ -22,6 +22,7 @@ import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum;
|
|
|
import cn.iocoder.yudao.module.system.service.logger.LoginLogService;
|
|
|
import cn.iocoder.yudao.module.system.service.member.MemberService;
|
|
|
import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService;
|
|
|
+import cn.iocoder.yudao.module.system.service.permission.RoleService;
|
|
|
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
|
|
|
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
|
import com.anji.captcha.model.common.ResponseModel;
|
|
|
@@ -33,6 +34,7 @@ import jakarta.validation.Validator;
|
|
|
import lombok.Setter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -67,6 +69,10 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
private CaptchaService captchaService;
|
|
|
@Resource
|
|
|
private SmsCodeApi smsCodeApi;
|
|
|
+ @Resource
|
|
|
+ private RoleService roleService;
|
|
|
+ @Resource
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
/**
|
|
|
* 验证码的开关,默认为 true
|
|
|
@@ -84,6 +90,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
createLoginLog(null, username, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
|
|
|
throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
|
|
|
}
|
|
|
+ // 登录失败,账号密码不正确
|
|
|
if (!userService.isPasswordMatch(password, user.getPassword())) {
|
|
|
createLoginLog(user.getId(), username, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
|
|
|
throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
|
|
|
@@ -93,9 +100,60 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
createLoginLog(user.getId(), username, logTypeEnum, LoginResultEnum.USER_DISABLED);
|
|
|
throw exception(AUTH_LOGIN_USER_DISABLED);
|
|
|
}
|
|
|
+ // 新增登录校验规则
|
|
|
+ // addAuthenticate(user, username);
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
+ /*public void addAuthenticate(AdminUserDO user, String username) {
|
|
|
+ // 检查用户在该模块是否是黑名单
|
|
|
+ String headerModule = ServletUtils.getRequest().getHeader("Module");
|
|
|
+ // 1.获取用户黑名单
|
|
|
+ List<UserBlackVo> userBlackList = userService.getUserBlackList(user.getId());
|
|
|
+ if (!userBlackList.isEmpty()) {
|
|
|
+ for (UserBlackVo userBlackVo : userBlackList) {
|
|
|
+ String module = DictUtils.getDictLabel("module", userBlackVo.getModule());
|
|
|
+ if (StringUtils.isNotBlank(headerModule) && headerModule.equals(module)) {
|
|
|
+ log.info("登录用户:{} 已被拉入 {} 模块黑名单.", username, module);
|
|
|
+ throw exception(AUTH_USER_BLACK, username, module);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 2.检查安卓的登录,根据登录模块和角色决定
|
|
|
+ if (!"admin".equals(username) && StringUtils.isNotBlank(headerModule) && "Android_Normal".equals(headerModule)) {
|
|
|
+ Boolean b = checkLoginByAttrModule(headerModule, user.getId());
|
|
|
+ if (!b) {
|
|
|
+ log.info("登录用户:{} 正在登录 {} 模块,由于您无相关角色,无法登录.", username, headerModule);
|
|
|
+ throw exception(AUTH_USER_LACK_ROLE, username);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ // 检测用户的角色能否在该模块登录
|
|
|
+ /* private Boolean checkLoginByAttrModule(String headerModule, Long userId) {
|
|
|
+ if (userId != null) {
|
|
|
+ // 1.获取用户的角色
|
|
|
+ List<RoleDO> roles = roleService.getRoleList(userId);
|
|
|
+ if (!roles.isEmpty()) {
|
|
|
+ if ("Android_Normal".equals(headerModule)) {
|
|
|
+ // 机柜
|
|
|
+ IsSystemAttributeVO cacheObject = JsonUtils.parseObject(stringRedisTemplate.opsForValue().get(RedisKeyConstants.ISCS_ATTR + "sys.loto_cabinet.role"), IsSystemAttributeVO.class);
|
|
|
+ if (cacheObject != null && StringUtils.isNotBlank(cacheObject.getSysAttrValue())) {
|
|
|
+ String[] strArray = Convert.toStrArray(cacheObject.getSysAttrValue());
|
|
|
+ for (RoleDO role : roles) {
|
|
|
+ for (String s : strArray) {
|
|
|
+ if (role.getCode().equals(s)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }*/
|
|
|
+
|
|
|
@Override
|
|
|
public AuthLoginRespVO login(AuthLoginReqVO reqVO) {
|
|
|
// 校验验证码
|