|
|
@@ -6,6 +6,8 @@ import cn.iocoder.byzs.framework.common.enums.UserTypeEnum;
|
|
|
import cn.iocoder.byzs.framework.common.util.monitor.TracerUtils;
|
|
|
import cn.iocoder.byzs.framework.common.util.servlet.ServletUtils;
|
|
|
import cn.iocoder.byzs.framework.common.util.validation.ValidationUtils;
|
|
|
+import cn.iocoder.byzs.framework.tenant.core.context.TenantContextHolder;
|
|
|
+import cn.iocoder.byzs.framework.web.core.util.WebFrameworkUtils;
|
|
|
import cn.iocoder.byzs.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
|
|
import cn.iocoder.byzs.module.system.api.sms.SmsCodeApi;
|
|
|
import cn.iocoder.byzs.module.system.api.sms.dto.code.SmsCodeUseReqDTO;
|
|
|
@@ -37,9 +39,12 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import static cn.iocoder.byzs.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
+import static cn.iocoder.byzs.framework.common.pojo.CommonResult.success;
|
|
|
import static cn.iocoder.byzs.framework.common.util.servlet.ServletUtils.getClientIP;
|
|
|
import static cn.iocoder.byzs.module.system.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
@@ -208,8 +213,28 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
}
|
|
|
|
|
|
private AuthLoginRespVO createTokenAfterLoginSuccess(Long userId, String username, LoginLogTypeEnum logType) {
|
|
|
+
|
|
|
+ // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
+ if (!Objects.equals(TenantContextHolder.getTenantId(), WebFrameworkUtils.DEFAULT_TENANT_ID)){
|
|
|
+ // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
+ oauth2TokenService.removeUserTokens(userId, getUserType().getValue());
|
|
|
+
|
|
|
+ //查看登录ip是否已被授权
|
|
|
+ Set<String> userLoginIpSet = loginLogService.selectIpListByUserId(userId);
|
|
|
+ if(!userLoginIpSet.contains(ServletUtils.getClientIP())){
|
|
|
+
|
|
|
+ //需要手机号校验
|
|
|
+ //发送手机验证码
|
|
|
+ AuthSmsLoginReqVO authSmsLoginReqVO = new AuthSmsLoginReqVO().setMobile(username);
|
|
|
+// smsCodeApi.sendSmsCode(AuthConvert.INSTANCE.convert(authSmsLoginReqVO));
|
|
|
+
|
|
|
+ throw exception(AUTH_LOGIN_IP_NOT_AUTHORIZED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 插入登陆日志
|
|
|
createLoginLog(userId, username, logType, LoginResultEnum.SUCCESS);
|
|
|
+
|
|
|
// 创建访问令牌
|
|
|
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, getUserType().getValue(),
|
|
|
OAuth2ClientConstants.CLIENT_ID_DEFAULT, null);
|