|
@@ -18,7 +18,9 @@ import cn.iocoder.byzs.module.system.controller.admin.auth.vo.*;
|
|
|
import cn.iocoder.byzs.module.system.controller.admin.auth.vo.*;
|
|
import cn.iocoder.byzs.module.system.controller.admin.auth.vo.*;
|
|
|
import cn.iocoder.byzs.module.system.convert.auth.AuthConvert;
|
|
import cn.iocoder.byzs.module.system.convert.auth.AuthConvert;
|
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
|
|
|
|
|
+import cn.iocoder.byzs.module.system.dal.dataobject.tenant.TenantDO;
|
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.user.AdminUserDO;
|
|
import cn.iocoder.byzs.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
|
|
+import cn.iocoder.byzs.module.system.dal.mysql.tenant.TenantMapper;
|
|
|
import cn.iocoder.byzs.module.system.enums.logger.LoginLogTypeEnum;
|
|
import cn.iocoder.byzs.module.system.enums.logger.LoginLogTypeEnum;
|
|
|
import cn.iocoder.byzs.module.system.enums.logger.LoginResultEnum;
|
|
import cn.iocoder.byzs.module.system.enums.logger.LoginResultEnum;
|
|
|
import cn.iocoder.byzs.module.system.enums.oauth2.OAuth2ClientConstants;
|
|
import cn.iocoder.byzs.module.system.enums.oauth2.OAuth2ClientConstants;
|
|
@@ -38,6 +40,7 @@ import jakarta.validation.Validator;
|
|
|
import jodd.util.StringUtil;
|
|
import jodd.util.StringUtil;
|
|
|
import lombok.Setter;
|
|
import lombok.Setter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -83,6 +86,8 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
@Value("${byzs.captcha.enable:true}")
|
|
@Value("${byzs.captcha.enable:true}")
|
|
|
@Setter // 为了单测:开启或者关闭验证码
|
|
@Setter // 为了单测:开启或者关闭验证码
|
|
|
private Boolean captchaEnable;
|
|
private Boolean captchaEnable;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TenantMapper tenantMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public AdminUserDO authenticate(String username, String password) {
|
|
public AdminUserDO authenticate(String username, String password) {
|
|
@@ -147,30 +152,37 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
tenantId = user.getTenantId();
|
|
tenantId = user.getTenantId();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
|
|
- if (!Objects.equals(tenantId, WebFrameworkUtils.DEFAULT_TENANT_ID)){
|
|
|
|
|
|
|
+ // 默认租户用户可以多设备登录,无需校验ip
|
|
|
|
|
+ if (Objects.equals(tenantId, WebFrameworkUtils.DEFAULT_TENANT_ID)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //查看登录ip是否已被授权
|
|
|
|
|
- if (StringUtil.isNotBlank(user.getLoginIp()) && !IpUtil.isSameNetworkSegment(user.getLoginIp(), getClientIP())) {
|
|
|
|
|
|
|
+ //该租户未限制ip
|
|
|
|
|
+ TenantDO tenantDO = tenantMapper.selectById(tenantId);
|
|
|
|
|
+ if (tenantDO != null && (tenantDO.getIpLimit() == null || tenantDO.getIpLimit().equals("false"))) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //发送手机验证码
|
|
|
|
|
|
|
+ //查看登录ip是否已被授权或不在同一网段
|
|
|
|
|
+ if (StringUtil.isNotBlank(user.getLoginIp()) && !IpUtil.isSameNetworkSegment(user.getLoginIp(), getClientIP())) {
|
|
|
|
|
+
|
|
|
|
|
+ //发送手机验证码
|
|
|
// AuthSmsLoginReqVO authSmsLoginReqVO = new AuthSmsLoginReqVO().setMobile(user.getNickname());
|
|
// AuthSmsLoginReqVO authSmsLoginReqVO = new AuthSmsLoginReqVO().setMobile(user.getNickname());
|
|
|
// smsCodeApi.sendSmsCode(AuthConvert.INSTANCE.convert(authSmsLoginReqVO));
|
|
// smsCodeApi.sendSmsCode(AuthConvert.INSTANCE.convert(authSmsLoginReqVO));
|
|
|
|
|
|
|
|
- //校验手机号是否存在
|
|
|
|
|
- if(StringUtil.isBlank(user.getMobile())){
|
|
|
|
|
- throw exception(AUTH_LOGIN_IP_NOT_AUTHORIZED_NOT_MOBILE_NOT_EXISTS);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 构建返回数据
|
|
|
|
|
- java.util.Map<String, Object> data = new java.util.HashMap<>();
|
|
|
|
|
- data.put("mobile", user.getMobile());
|
|
|
|
|
- throw exception(AUTH_LOGIN_IP_NOT_AUTHORIZED, data);
|
|
|
|
|
|
|
+ //校验手机号是否存在
|
|
|
|
|
+ if(StringUtil.isBlank(user.getMobile())){
|
|
|
|
|
+ throw exception(AUTH_LOGIN_IP_NOT_AUTHORIZED_NOT_MOBILE_NOT_EXISTS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
|
|
- oauth2TokenService.removeUserTokens(user.getId(), getUserType().getValue());
|
|
|
|
|
|
|
+ // 构建返回数据
|
|
|
|
|
+ java.util.Map<String, Object> data = new java.util.HashMap<>();
|
|
|
|
|
+ data.put("mobile", user.getMobile());
|
|
|
|
|
+ throw exception(AUTH_LOGIN_IP_NOT_AUTHORIZED, data);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
|
|
+ oauth2TokenService.removeUserTokens(user.getId(), getUserType().getValue());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|