mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-13 05:12:07 +08:00
1、新增system服务国际化配置文件;2、资金管理请求校验国际化;3、全局异常GlobalError增加国际化提示;
This commit is contained in:
+6
-4
@@ -1,6 +1,7 @@
|
||||
package com.cf.imes.framework.organ.config;
|
||||
|
||||
import com.cf.imes.framework.common.enums.WebFilterOrderEnum;
|
||||
import com.cf.imes.framework.common.util.i18n.core.util.I18nUtils;
|
||||
import com.cf.imes.framework.mybatis.core.util.MyBatisUtils;
|
||||
import com.cf.imes.framework.redis.config.ChenfengCacheProperties;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnoreAspect;
|
||||
@@ -80,12 +81,13 @@ public class ChenfengOrganAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean<OrganSecurityWebFilter> organSecurityWebFilter(OrganProperties tenantProperties,
|
||||
WebProperties webProperties,
|
||||
GlobalExceptionHandler globalExceptionHandler,
|
||||
OrganFrameworkService organFrameworkService) {
|
||||
WebProperties webProperties,
|
||||
GlobalExceptionHandler globalExceptionHandler,
|
||||
OrganFrameworkService organFrameworkService,
|
||||
I18nUtils i18nUtils) {
|
||||
FilterRegistrationBean<OrganSecurityWebFilter> registrationBean = new FilterRegistrationBean<>();
|
||||
registrationBean.setFilter(new OrganSecurityWebFilter(tenantProperties, webProperties,
|
||||
globalExceptionHandler, organFrameworkService));
|
||||
globalExceptionHandler, organFrameworkService, i18nUtils));
|
||||
registrationBean.setOrder(WebFilterOrderEnum.TENANT_SECURITY_FILTER);
|
||||
return registrationBean;
|
||||
}
|
||||
|
||||
+13
-6
@@ -7,6 +7,7 @@ import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.util.servlet.ServletUtils;
|
||||
import com.cf.imes.framework.common.util.i18n.core.util.I18nUtils;
|
||||
import com.cf.imes.framework.security.core.LoginUser;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.framework.organ.config.OrganProperties;
|
||||
@@ -28,6 +29,9 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.NO_PERMISSION_TO_VISIT_ORG;
|
||||
import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants.REQUEST_ORGAN_ID_NOT_EXIST;
|
||||
|
||||
/**
|
||||
* 多组织 Security Web 过滤器
|
||||
* 1. 如果是登陆的用户,校验是否有权限访问该组织,避免越权问题。
|
||||
@@ -48,15 +52,19 @@ public class OrganSecurityWebFilter extends ApiRequestFilter {
|
||||
private final GlobalExceptionHandler globalExceptionHandler;
|
||||
private final OrganFrameworkService organFrameworkService;
|
||||
|
||||
private final I18nUtils i18nUtils;
|
||||
|
||||
public OrganSecurityWebFilter(OrganProperties organProperties,
|
||||
WebProperties webProperties,
|
||||
GlobalExceptionHandler globalExceptionHandler,
|
||||
OrganFrameworkService organFrameworkService) {
|
||||
OrganFrameworkService organFrameworkService,
|
||||
I18nUtils i18nUtils) {
|
||||
super(webProperties);
|
||||
this.organProperties = organProperties;
|
||||
this.pathMatcher = new AntPathMatcher();
|
||||
this.globalExceptionHandler = globalExceptionHandler;
|
||||
this.organFrameworkService = organFrameworkService;
|
||||
this.i18nUtils = i18nUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,8 +85,7 @@ public class OrganSecurityWebFilter extends ApiRequestFilter {
|
||||
log.error("[doFilterInternal][组织({}) User({}/{}) 越权访问组织({}) URL({}/{})]",
|
||||
user.getOrganId(), user.getId(), user.getUserType(),
|
||||
OrganContextHolder.getOrganId(), request.getRequestURI(), request.getMethod());
|
||||
ServletUtils.writeJSON(response, CommonResult.error(GlobalErrorCodeConstants.FORBIDDEN.getCode(),
|
||||
"您无权访问该组织的数据"));
|
||||
ServletUtils.writeJSON(response, CommonResult.error(NO_PERMISSION_TO_VISIT_ORG.getCode(), i18nUtils.getMessage(NO_PERMISSION_TO_VISIT_ORG.getMsg())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -88,8 +95,7 @@ public class OrganSecurityWebFilter extends ApiRequestFilter {
|
||||
// 2. 如果请求未带组织的编号,不允许访问。
|
||||
if (organId == null) {
|
||||
log.error("[doFilterInternal][URL({}/{}) 未传递组织编号]", request.getRequestURI(), request.getMethod());
|
||||
ServletUtils.writeJSON(response, CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(),
|
||||
"请求的组织标识未传递,请进行排查"));
|
||||
ServletUtils.writeJSON(response, CommonResult.error(REQUEST_ORGAN_ID_NOT_EXIST.getCode(), i18nUtils.getMessage(REQUEST_ORGAN_ID_NOT_EXIST.getMsg())));
|
||||
return;
|
||||
}
|
||||
// 3. 校验组织是合法,例如说被禁用、到期
|
||||
@@ -108,6 +114,7 @@ public class OrganSecurityWebFilter extends ApiRequestFilter {
|
||||
CommonResult<?> result = globalExceptionHandler.allExceptionHandler(request, ex);
|
||||
// 组织失效返回401踢出系统
|
||||
needUnauthorizedWhenOrgExpired(ex, result);
|
||||
result.setMsg(i18nUtils.getMessage(result.getMsg(), null));
|
||||
ServletUtils.writeJSON(response, result);
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +140,7 @@ public class OrganSecurityWebFilter extends ApiRequestFilter {
|
||||
// 非管理端校验产品的有效性
|
||||
if (!isManageEndPoint) {
|
||||
if (ObjectUtil.isNull(productId)) {
|
||||
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED.getCode(), GlobalErrorCodeConstants.USER_PRODUCTID_NOT_EXIST.getMsg());
|
||||
throw new ServiceException(GlobalErrorCodeConstants.USER_PRODUCTID_NOT_EXIST);
|
||||
}
|
||||
if (!isProductIgnoreUrl(request)) {
|
||||
organFrameworkService.validOrgProduct(user.getOrganId(), productId);
|
||||
|
||||
Reference in New Issue
Block a user