1、token、套餐产品id预设;2、登录/请求部门校验修复;

This commit is contained in:
gaoqr
2025-09-23 10:54:51 +08:00
parent 8345f6e36f
commit 1cedd2f246
8 changed files with 74 additions and 3 deletions
@@ -111,4 +111,10 @@ public class OAuth2AccessTokenDO extends BaseDO {
*/
@TableField(exist = false)
private String grayDefaultVersion;
/**
* 产品id
*/
@TableField(exist = false)
private Long productId;
}
@@ -51,4 +51,9 @@ public class TenantPackageDO extends BaseDO {
@TableField(typeHandler = JsonLongSetTypeHandler.class)
private Set<Long> menuIds;
/**
* 产品id
*/
@TableField(exist = false)
private Long productId;
}
@@ -130,4 +130,10 @@ public class AdminUserDO extends OrganBaseDO {
*/
@TableField(exist = false)
private UserTypeEnum userType;
/**
* 产品id
*/
@TableField(exist = false)
private Long productId;
}
@@ -0,0 +1,21 @@
package com.cf.imes.module.system.framework.product;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author Gqr
* @since 2025/9/23 9:14
*/
@Configuration
@ConfigurationProperties(prefix = "chenfeng.product-id")
@Data
public class ProductProperties {
/**
* imes生产系统
*/
private Long imesProduct;
}
@@ -1,6 +1,5 @@
package com.cf.imes.module.system.service.auth;
import cn.hutool.core.util.ObjectUtil;
import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
@@ -34,6 +33,8 @@ import com.cf.imes.module.system.enums.logger.LoginLogTypeEnum;
import com.cf.imes.module.system.enums.logger.LoginResultEnum;
import com.cf.imes.module.system.enums.oauth2.OAuth2ClientConstants;
import com.cf.imes.module.system.enums.sms.SmsSceneEnum;
import com.cf.imes.module.system.framework.product.ProductProperties;
import com.cf.imes.module.system.service.dept.DeptService;
import com.cf.imes.module.system.service.logger.LoginLogService;
import com.cf.imes.module.system.service.member.MemberService;
import com.cf.imes.module.system.service.oauth2.OAuth2TokenService;
@@ -103,6 +104,12 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Autowired
private SecurityFrameworkService securityFrameworkService;
@Resource
private DeptService deptService;
@Resource
private ProductProperties productProperties;
/**
* 验证码的开关,默认为 true
*/
@@ -132,7 +139,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
organFrameworkService.validOrgan(organId);
// 校验部门有效性
OrganContextHolder.setOrganId(organId);
organFrameworkService.validDept(user.getDeptId());
deptService.validUserLoginDept(user.getDeptId());
// 校验密码
if (!userService.isPasswordMatch(password, user.getPassword())) {
createLoginLog(user.getId(), username, null, organId, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
@@ -84,6 +84,13 @@ public interface DeptService {
*/
void validDept(Long deptId);
/**
* 用户登陆时部门校验
*
* @param deptId
*/
void validUserLoginDept(Long deptId);
/**
* 移除没有归属(上级)的部门
*
@@ -275,6 +275,24 @@ public class DeptServiceImpl implements DeptService {
validParentDept(deptDO);
}
/**
* 用户登陆时部门校验,部门不存在时也可以进行登录
*
* @param deptId
*/
@Override
public void validUserLoginDept(Long deptId) {
DeptDO deptDO = deptMapper.selectById(deptId);
if (deptDO == null) {
return;
}
if (!CommonStatusEnum.ENABLE.getStatus().equals(deptDO.getStatus())) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.DEPT_NOT_ALLOWED_LOGIN, deptDO.getName());
}
// 递归校验上级部门
validParentDept(deptDO);
}
/**
* 递归校验上级部门
@@ -224,7 +224,8 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService {
.setNickname(user.getNickname())
.setDeptId(user.getDeptId())
.setGrayVersion(user.getGrayVersion())
.setGrayDefaultVersion(user.getGrayDefaultVersion());
.setGrayDefaultVersion(user.getGrayDefaultVersion())
.setProductId(user.getProductId());
if (organId != null) {
OrganContextHolder.setOrganId(organId);
}