|
|
@@ -3,9 +3,8 @@ package com.wx.blink.admin.system.login.service;
|
|
|
import cn.dev33.satoken.stp.StpInterface;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
-import cn.hutool.core.util.NumberUtil;
|
|
|
-import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
|
+import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
|
|
import com.wx.blink.admin.system.department.domain.vo.DepartmentVO;
|
|
|
import com.wx.blink.admin.system.department.service.DepartmentService;
|
|
|
import com.wx.blink.admin.system.employee.domain.entity.EmployeeEntity;
|
|
|
@@ -27,9 +26,7 @@ import com.wx.blink.base.common.enumeration.UserTypeEnum;
|
|
|
import com.wx.blink.base.common.util.BlinkBeanUtil;
|
|
|
import com.wx.blink.base.common.util.BlinkEnumUtil;
|
|
|
import com.wx.blink.base.common.util.BlinkIpUtil;
|
|
|
-import com.wx.blink.base.common.util.BlinkStringUtil;
|
|
|
import com.wx.blink.base.constant.LoginDeviceEnum;
|
|
|
-import com.wx.blink.base.constant.RedisKeyConst;
|
|
|
import com.wx.blink.base.module.support.apiencrypt.service.ApiEncryptService;
|
|
|
import com.wx.blink.base.module.support.captcha.CaptchaService;
|
|
|
import com.wx.blink.base.module.support.captcha.domain.CaptchaVO;
|
|
|
@@ -41,13 +38,11 @@ import com.wx.blink.base.module.support.loginlog.LoginLogService;
|
|
|
import com.wx.blink.base.module.support.loginlog.domain.LoginLogEntity;
|
|
|
import com.wx.blink.base.module.support.loginlog.domain.LoginLogVO;
|
|
|
import com.wx.blink.base.module.support.mail.MailService;
|
|
|
-import com.wx.blink.base.module.support.mail.constant.MailTemplateCodeEnum;
|
|
|
import com.wx.blink.base.module.support.redis.RedisService;
|
|
|
import com.wx.blink.base.module.support.securityprotect.domain.LoginFailEntity;
|
|
|
import com.wx.blink.base.module.support.securityprotect.service.Level3ProtectConfigService;
|
|
|
import com.wx.blink.base.module.support.securityprotect.service.SecurityLoginService;
|
|
|
import com.wx.blink.base.module.support.securityprotect.service.SecurityPasswordService;
|
|
|
-import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -147,7 +142,7 @@ public class LoginService implements StpInterface {
|
|
|
* @return 返回用户登录信息
|
|
|
*/
|
|
|
public ResponseDTO<LoginResultVO> login(LoginForm loginForm, String ip, String userAgent) {
|
|
|
-
|
|
|
+ UserTypeEnum userType = parseUserType(loginForm.getLoginType());
|
|
|
LoginDeviceEnum loginDeviceEnum = BlinkEnumUtil.getEnumByValue(loginForm.getLoginDevice(), LoginDeviceEnum.class);
|
|
|
if (loginDeviceEnum == null) {
|
|
|
return ResponseDTO.userErrorParam("登录设备暂不支持!");
|
|
|
@@ -196,7 +191,7 @@ public class LoginService implements StpInterface {
|
|
|
} else {
|
|
|
|
|
|
// 按照等保登录要求,进行登录失败次数校验
|
|
|
- ResponseDTO<LoginFailEntity> loginFailEntityResponseDTO = securityLoginService.checkLogin(employeeEntity.getEmployeeId(), UserTypeEnum.EMPLOYEE);
|
|
|
+ ResponseDTO<LoginFailEntity> loginFailEntityResponseDTO = securityLoginService.checkLogin(employeeEntity.getEmployeeId(), userType);
|
|
|
if (!loginFailEntityResponseDTO.getOk()) {
|
|
|
return ResponseDTO.error(loginFailEntityResponseDTO);
|
|
|
}
|
|
|
@@ -206,11 +201,11 @@ public class LoginService implements StpInterface {
|
|
|
// 记录登录失败
|
|
|
saveLoginLog(employeeEntity, ip, userAgent, "密码错误", LoginLogResultEnum.LOGIN_FAIL);
|
|
|
// 记录等级保护次数
|
|
|
- String msg = securityLoginService.recordLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.EMPLOYEE, employeeEntity.getLoginName(), loginFailEntityResponseDTO.getData());
|
|
|
+ String msg = securityLoginService.recordLoginFail(employeeEntity.getEmployeeId(), userType, employeeEntity.getLoginName(), loginFailEntityResponseDTO.getData());
|
|
|
return msg == null ? ResponseDTO.userErrorParam("登录名或密码错误!") : ResponseDTO.error(UserErrorCode.LOGIN_FAIL_WILL_LOCK, msg);
|
|
|
}
|
|
|
|
|
|
- String saTokenLoginId = UserTypeEnum.EMPLOYEE.getValue() + StringConst.COLON + employeeEntity.getEmployeeId();
|
|
|
+ String saTokenLoginId = userType.getValue() + StringConst.COLON + employeeEntity.getEmployeeId();
|
|
|
// 登录
|
|
|
StpUtil.login(saTokenLoginId, String.valueOf(loginDeviceEnum.getDesc()));
|
|
|
}
|
|
|
@@ -222,7 +217,7 @@ public class LoginService implements StpInterface {
|
|
|
loginEmployeeCache.put(employeeEntity.getEmployeeId(), requestEmployee);
|
|
|
|
|
|
// 移除登录失败
|
|
|
- securityLoginService.removeLoginFail(employeeEntity.getEmployeeId(), UserTypeEnum.EMPLOYEE);
|
|
|
+ securityLoginService.removeLoginFail(employeeEntity.getEmployeeId(), userType);
|
|
|
|
|
|
// 获取登录结果信息
|
|
|
String token = StpUtil.getTokenValue();
|
|
|
@@ -238,6 +233,14 @@ public class LoginService implements StpInterface {
|
|
|
return ResponseDTO.ok(loginResultVO);
|
|
|
}
|
|
|
|
|
|
+ private UserTypeEnum parseUserType(String loginType) {
|
|
|
+ if (loginType.equals("USERNAME_PASSWORD")) {
|
|
|
+ return UserTypeEnum.EMPLOYEE;
|
|
|
+ } else {
|
|
|
+ return UserTypeEnum.PROVIDER;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 员工登陆
|
|
|
*
|