mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
Merge branch 'main' into 'LiuZt'
# Conflicts: # cf-module-system/cf-module-system-api/src/main/java/com/cf/imes/module/system/enums/ErrorCodeConstants.java # cf-module-system/cf-module-system-biz/src/main/java/com/cf/imes/module/system/service/process/ProcessGroupService.java # cf-module-system/cf-module-system-biz/src/test/java/com/cf/imes/module/system/service/process/GroupServiceImplTest.java
This commit is contained in:
+1
@@ -26,6 +26,7 @@ public interface GlobalErrorCodeConstants {
|
||||
ErrorCode LOCKED = new ErrorCode(423, "请求失败,请稍后重试"); // 并发请求,不允许
|
||||
ErrorCode TOO_MANY_REQUESTS = new ErrorCode(429, "请求过于频繁,请稍后重试");
|
||||
ErrorCode DATA_SOURCE_CODE_NOT_FOUND = new ErrorCode(430, "未传递数据源标识");
|
||||
ErrorCode ORGAN_ID_NOT_FOUND = new ErrorCode(431, "未传组织标识");
|
||||
|
||||
// ========== 服务端错误段 ==========
|
||||
|
||||
|
||||
+2
-1
@@ -65,7 +65,8 @@ public class OrganSecurityWebFilter extends ApiRequestFilter {
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||
throws ServletException, IOException {
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
Long organId = WebFrameworkUtils.getOrganId(request);
|
||||
//Long organId = OrganContextHolder.getOrganId();
|
||||
boolean isRpcRequest = WebFrameworkUtils.isRpcRequest(request);
|
||||
// 1. 登陆的用户,校验是否有权限访问该组织,避免越权问题。
|
||||
LoginUser user = SecurityFrameworkUtils.getLoginUser();
|
||||
|
||||
+4
-5
@@ -6,7 +6,6 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.Date;
|
||||
import static com.cf.imes.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
import static com.cf.imes.framework.common.util.date.DateUtils.TIME_ZONE_DEFAULT;
|
||||
|
||||
@@ -19,12 +18,12 @@ public class ESDocument {
|
||||
public String id;
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
|
||||
private Date createTime;
|
||||
private Long creator;
|
||||
private String createTime;
|
||||
private String creator;
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND, timezone = TIME_ZONE_DEFAULT)
|
||||
private Date updateTime;
|
||||
private Long updater;
|
||||
private String updateTime;
|
||||
private String updater;
|
||||
private Long organId;
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public interface ESDocumentService {
|
||||
* @param documents 要增加的对象集合
|
||||
* @return 批量操作的结果
|
||||
*/
|
||||
<T> BulkResponse bulkCreate(String idxName, List<T> documents) throws Exception;
|
||||
<T> BulkResponse bulkCreate(String idxName, List<?extends ESDocument> documents) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+64
-43
@@ -15,6 +15,11 @@ import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeFormatterBuilder;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -23,7 +28,7 @@ import java.util.function.BiConsumer;
|
||||
/**
|
||||
* @author there
|
||||
*/
|
||||
public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
public class ESDocumentServiceImpl implements ESDocumentService {
|
||||
//同步客户端
|
||||
private final ElasticsearchClient elasticsearchClient;
|
||||
|
||||
@@ -32,20 +37,23 @@ public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
|
||||
private Snowflake snowflake = IdUtil.getSnowflake();
|
||||
|
||||
public ESDocumentServiceImpl (ElasticsearchClient elasticsearchClient, ElasticsearchAsyncClient elasticsearchAsyncClient) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public ESDocumentServiceImpl(ElasticsearchClient elasticsearchClient, ElasticsearchAsyncClient elasticsearchAsyncClient) {
|
||||
this.elasticsearchClient = elasticsearchClient;
|
||||
this.elasticsearchAsyncClient = elasticsearchAsyncClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> IndexResponse createByFluentDSL(String idxName, String idxId, ESDocument document) throws Exception {
|
||||
Date date = new Date();
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
document.setCreator(loginUser.getId());
|
||||
document.setUpdater(loginUser.getId());
|
||||
document.setCreator(loginUser.getNickname());
|
||||
document.setUpdater(loginUser.getNickname());
|
||||
document.setOrganId(loginUser.getOrganId());
|
||||
document.setCreateTime(new Date());
|
||||
document.setUpdateTime(new Date());
|
||||
if(StrUtil.isBlank(document.getId())) {
|
||||
document.setCreateTime(simpleDateFormat.format(date));
|
||||
document.setUpdateTime(simpleDateFormat.format(date));
|
||||
if (StrUtil.isBlank(document.getId())) {
|
||||
document.setId(snowflake.nextIdStr());
|
||||
}
|
||||
return elasticsearchClient.index(idx -> idx
|
||||
@@ -56,21 +64,23 @@ public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
|
||||
/**
|
||||
* BuilderPattern 方式创建文档
|
||||
* @param idxName 索引名
|
||||
* @param idxId 索引id
|
||||
*
|
||||
* @param idxName 索引名
|
||||
* @param idxId 索引id
|
||||
* @param document 文档对象
|
||||
*/
|
||||
@Override
|
||||
public <T> IndexResponse createByBuilderPattern(String idxName, String idxId, ESDocument document) throws Exception {
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
document.setCreator(loginUser.getId());
|
||||
document.setUpdater(loginUser.getId());
|
||||
Date date = new Date();
|
||||
document.setCreator(loginUser.getNickname());
|
||||
document.setUpdater(loginUser.getNickname());
|
||||
document.setOrganId(loginUser.getOrganId());
|
||||
document.setCreateTime(new Date());
|
||||
document.setUpdateTime(new Date());
|
||||
document.setCreateTime(simpleDateFormat.format(date));
|
||||
document.setUpdateTime(simpleDateFormat.format(date));
|
||||
IndexRequest.Builder<Object> indexReqBuilder = new IndexRequest.Builder<>();
|
||||
indexReqBuilder.index(idxName);
|
||||
if(StrUtil.isBlank(idxId)) {
|
||||
if (StrUtil.isBlank(idxId)) {
|
||||
idxId = snowflake.nextIdStr();
|
||||
}
|
||||
indexReqBuilder.id(idxId);
|
||||
@@ -80,13 +90,14 @@ public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
|
||||
/**
|
||||
* json方式创建文档
|
||||
* @param idxName 索引名
|
||||
* @param idxId 索引id
|
||||
*
|
||||
* @param idxName 索引名
|
||||
* @param idxId 索引id
|
||||
* @param jsonContent json字符串
|
||||
*/
|
||||
@Override
|
||||
public IndexResponse createByJson(String idxName, String idxId, String jsonContent) throws Exception {
|
||||
if(StrUtil.isBlank(idxId)) {
|
||||
if (StrUtil.isBlank(idxId)) {
|
||||
idxId = snowflake.nextIdStr();
|
||||
}
|
||||
String finalIdxId = idxId;
|
||||
@@ -98,11 +109,12 @@ public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步方式创建文档
|
||||
* @param idxName 索引名
|
||||
* @param idxId 索引id
|
||||
* 异步方式创建文档
|
||||
*
|
||||
* @param idxName 索引名
|
||||
* @param idxId 索引id
|
||||
* @param document 文档
|
||||
* @param action 操作
|
||||
* @param action 操作
|
||||
*/
|
||||
@Override
|
||||
public <T> void createAsync(String idxName, String idxId, T document, BiConsumer<IndexResponse, Throwable> action) {
|
||||
@@ -115,51 +127,57 @@ public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
|
||||
/**
|
||||
* 批量方式创建文档
|
||||
* @param idxName 索引名
|
||||
*
|
||||
* @param idxName 索引名
|
||||
* @param documents 要增加的对象集合
|
||||
*/
|
||||
|
||||
@Override
|
||||
public <T> BulkResponse bulkCreate(String idxName, List<T> documents) throws Exception {
|
||||
public <T> BulkResponse bulkCreate(String idxName, List<? extends ESDocument> documents) throws Exception {
|
||||
BulkRequest.Builder br = new BulkRequest.Builder();
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
documents.forEach(document ->{
|
||||
ESDocument esDocument = (ESDocument) document;
|
||||
if(StrUtil.isBlank(esDocument.getId())) {
|
||||
Date date = new Date();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
documents.forEach(esDocument -> {
|
||||
if (StrUtil.isBlank(esDocument.getId())) {
|
||||
esDocument.setId(snowflake.nextIdStr());
|
||||
}
|
||||
esDocument.setUpdater(loginUser.getId());
|
||||
esDocument.setUpdateTime(new Date());
|
||||
esDocument.setCreator(loginUser.getNickname());
|
||||
esDocument.setCreateTime(simpleDateFormat.format(date));
|
||||
esDocument.setUpdater(loginUser.getNickname());
|
||||
|
||||
esDocument.setUpdateTime(simpleDateFormat.format(date));
|
||||
br.operations(op -> op.index(idx -> idx
|
||||
.index(idxName)
|
||||
.id(esDocument.getId().toString())
|
||||
.id(esDocument.getId())
|
||||
.document(esDocument)));
|
||||
});
|
||||
return elasticsearchClient.bulk(br.build());
|
||||
return elasticsearchClient.bulk(br.build());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param idxName 索引名称
|
||||
* @param docId 文档id
|
||||
* @param tClass 返回的类型
|
||||
* @param map 修改内容的map
|
||||
* Map<String, Object> map = new HashMap<>();
|
||||
* map.put("age", 35);
|
||||
* 把年龄改成35
|
||||
* @param docId 文档id
|
||||
* @param tClass 返回的类型
|
||||
* @param map 修改内容的map
|
||||
* Map<String, Object> map = new HashMap<>();
|
||||
* map.put("age", 35);
|
||||
* 把年龄改成35
|
||||
*/
|
||||
@Override
|
||||
public <T> Result updateById(String idxName, String docId, Class<T> tClass, Map<String,Object> map) throws IOException {
|
||||
public <T> Result updateById(String idxName, String docId, Class<T> tClass, Map<String, Object> map) throws IOException {
|
||||
UpdateResponse<T> response = elasticsearchClient.update(e -> e.index(idxName).id(docId).doc(map), tClass);
|
||||
return response.result();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档id查询信息
|
||||
*
|
||||
* @param idxName 索引名
|
||||
* @param docId 文档id
|
||||
* @param docId 文档id
|
||||
*/
|
||||
@Override
|
||||
public <T> T getById(String idxName, String docId,Class<T> tClass) throws IOException {
|
||||
public <T> T getById(String idxName, String docId, Class<T> tClass) throws IOException {
|
||||
GetResponse<T> response = elasticsearchClient.get(g -> g
|
||||
.index(idxName)
|
||||
.id(docId),
|
||||
@@ -169,8 +187,9 @@ public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
|
||||
/**
|
||||
* 根据索引名称和文档id查询ObjectNode
|
||||
*
|
||||
* @param idxName 索引名
|
||||
* @param docId 文档id
|
||||
* @param docId 文档id
|
||||
*/
|
||||
@Override
|
||||
public JSONObject getObjectNodeById(String idxName, String docId) throws IOException {
|
||||
@@ -184,8 +203,9 @@ public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
|
||||
/**
|
||||
* 单条输出
|
||||
*
|
||||
* @param idxName 索引名
|
||||
* @param docId 文档id
|
||||
* @param docId 文档id
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteById(String idxName, String docId) throws IOException {
|
||||
@@ -197,8 +217,9 @@ public class ESDocumentServiceImpl implements ESDocumentService{
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param idxName 索引名
|
||||
* @param docIds 要删除的文档id集合
|
||||
* @param docIds 要删除的文档id集合
|
||||
*/
|
||||
@Override
|
||||
public BulkResponse bulkDeleteByIds(String idxName, List<String> docIds) throws Exception {
|
||||
|
||||
+10
-8
@@ -32,14 +32,15 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
|
||||
baseDO.setUpdateTime(current);
|
||||
}
|
||||
|
||||
Long userId = WebFrameworkUtils.getLoginUserId();
|
||||
//Long userId = WebFrameworkUtils.getLoginUserId();
|
||||
String loginUserName = WebFrameworkUtils.getLoginUserName();
|
||||
// 当前登录用户不为空,创建人为空,则当前登录用户为创建人
|
||||
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getCreator())) {
|
||||
baseDO.setCreator(userId.toString());
|
||||
if (Objects.nonNull(loginUserName) && Objects.isNull(baseDO.getCreator())) {
|
||||
baseDO.setCreator(loginUserName);
|
||||
}
|
||||
// 当前登录用户不为空,更新人为空,则当前登录用户为更新人
|
||||
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getUpdater())) {
|
||||
baseDO.setUpdater(userId.toString());
|
||||
if (Objects.nonNull(loginUserName) && Objects.isNull(baseDO.getUpdater())) {
|
||||
baseDO.setUpdater(loginUserName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,9 +55,10 @@ public class DefaultDBFieldHandler implements MetaObjectHandler {
|
||||
|
||||
// 当前登录用户不为空,更新人为空,则当前登录用户为更新人
|
||||
Object modifier = getFieldValByName("updater", metaObject);
|
||||
Long userId = WebFrameworkUtils.getLoginUserId();
|
||||
if (Objects.nonNull(userId) && Objects.isNull(modifier)) {
|
||||
setFieldValByName("updater", userId.toString(), metaObject);
|
||||
//Long userId = WebFrameworkUtils.getLoginUserId();
|
||||
String loginUserName = WebFrameworkUtils.getLoginUserName();
|
||||
if (Objects.nonNull(loginUserName) && Objects.isNull(modifier)) {
|
||||
setFieldValByName("updater", loginUserName, metaObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -132,4 +132,16 @@ public class LambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapperX<T> or(boolean condition) {
|
||||
super.or(condition);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapperX<T> or() {
|
||||
super.or();
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
<https://www.cf.com/Spring-Boot/Resilience4j/?chenfeng>
|
||||
+8
@@ -19,6 +19,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||
import org.springframework.security.web.firewall.DefaultHttpFirewall;
|
||||
import org.springframework.security.web.firewall.HttpFirewall;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -100,4 +102,10 @@ public class ChenfengSecurityAutoConfiguration {
|
||||
return methodInvokingFactoryBean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HttpFirewall httpFirewall() {
|
||||
return new DefaultHttpFirewall();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -75,4 +75,8 @@ public class LoginUser {
|
||||
* 数据源编码
|
||||
*/
|
||||
private String dataCode;
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickname;
|
||||
}
|
||||
|
||||
+7
-4
@@ -23,6 +23,8 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Token 过滤器,验证 token 的有效性
|
||||
@@ -92,10 +94,10 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
&& ObjectUtil.notEqual(accessToken.getUserType(), userType)) {
|
||||
throw new AccessDeniedException("错误的用户类型");
|
||||
}
|
||||
CommonResult<Boolean> superAdmin = permissionApi.hasAnyRoles(accessToken.getUserId(), "super_admin");
|
||||
//CommonResult<Boolean> superAdmin = permissionApi.hasAnyRoles(accessToken.getUserId(), "super_admin");
|
||||
// 构建登录用户
|
||||
return new LoginUser().setId(accessToken.getUserId()).setUserType(accessToken.getUserType())
|
||||
.setOrganId(accessToken.getOrganId()).setScopes(accessToken.getScopes()).setIsSupAdmin(superAdmin.getCheckedData())
|
||||
.setOrganId(accessToken.getOrganId()).setScopes(accessToken.getScopes()).setIsSupAdmin(accessToken.getIsSupAdmin())
|
||||
.setLarge(accessToken.getLarge()).setDbNo(accessToken.getDbNo()).setTableNo(accessToken.getTableNo());
|
||||
} catch (ServiceException serviceException) {
|
||||
// 校验 Token 不通过时,考虑到一些接口是无需登录的,所以直接返回 null 即可
|
||||
@@ -131,8 +133,9 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
|
||||
String loginUserStr = request.getHeader(SecurityFrameworkUtils.LOGIN_USER_HEADER);
|
||||
if(StrUtil.isNotEmpty(loginUserStr)) {
|
||||
LoginUser loginUser = JsonUtils.parseObject(loginUserStr, LoginUser.class);
|
||||
CommonResult<Boolean> superAdmin = permissionApi.hasAnyRoles(loginUser.getId(), "super_admin");
|
||||
loginUser.setIsSupAdmin(superAdmin.getCheckedData());
|
||||
//CommonResult<Boolean> superAdmin = permissionApi.hasAnyRoles(loginUser.getId(), "super_admin");
|
||||
//loginUser.setIsSupAdmin(superAdmin.getCheckedData());
|
||||
loginUser.setNickname(URLDecoder.decode(loginUser.getNickname(),StandardCharsets.UTF_8));
|
||||
return loginUser;
|
||||
}
|
||||
return null;
|
||||
|
||||
+10
@@ -41,6 +41,16 @@ public interface SecurityFrameworkService {
|
||||
*/
|
||||
boolean hasAnyRoles(String... roles);
|
||||
|
||||
|
||||
/**
|
||||
* 判断是否有角色,任一一个即可
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param roles 角色数组
|
||||
* @return 是否
|
||||
*/
|
||||
boolean hasAnyRoles(Long userId, String... roles);
|
||||
|
||||
/**
|
||||
* 判断是否有授权
|
||||
*
|
||||
|
||||
+8
-1
@@ -48,7 +48,8 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
|
||||
@Override
|
||||
public Boolean load(KeyValue<Long, List<String>> key) {
|
||||
return permissionApi.hasAnyPermissions(key.getKey(), key.getValue().toArray(new String[0])).getCheckedData();
|
||||
Boolean checkedData = permissionApi.hasAnyPermissions(key.getKey(), key.getValue().toArray(new String[0])).getCheckedData();
|
||||
return checkedData;
|
||||
}
|
||||
|
||||
});
|
||||
@@ -75,6 +76,12 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
|
||||
return hasAnyRolesCache.get(new KeyValue<>(SecurityFrameworkUtils.getLoginUserId(), Arrays.asList(roles)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public boolean hasAnyRoles(Long userId, String... roles) {
|
||||
return hasAnyRolesCache.get(new KeyValue<>(userId, Arrays.asList(roles)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScope(String scope) {
|
||||
return hasAnyScopes(scope);
|
||||
|
||||
+1
@@ -106,6 +106,7 @@ public class SecurityFrameworkUtils {
|
||||
// 原因是,Spring Security 的 Filter 在 ApiAccessLogFilter 后面,在它记录访问日志时,线上上下文已经没有用户编号等信息
|
||||
WebFrameworkUtils.setLoginUserId(request, loginUser.getId());
|
||||
WebFrameworkUtils.setLoginUserType(request, loginUser.getUserType());
|
||||
WebFrameworkUtils.setLoginUserName(request, loginUser.getNickname());
|
||||
}
|
||||
|
||||
private static Authentication buildAuthentication(LoginUser loginUser, HttpServletRequest request) {
|
||||
|
||||
+4
-4
@@ -19,7 +19,7 @@ import static com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConsta
|
||||
*/
|
||||
public class DataSourceFilter extends OncePerRequestFilter {
|
||||
//数据源编码
|
||||
private static final String DATA_SOURCE_CODE = "dataCode";
|
||||
private static final String DATA_SOURCE_CODE = "data-code";
|
||||
|
||||
private WebProperties webProperties;
|
||||
|
||||
@@ -36,12 +36,12 @@ public class DataSourceFilter extends OncePerRequestFilter {
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||
String dataSourceCode = request.getHeader(DATA_SOURCE_CODE);
|
||||
if(StrUtil.isBlank(dataSourceCode)) {
|
||||
String dataCode = request.getHeader(DATA_SOURCE_CODE);
|
||||
if(StrUtil.isEmpty(dataCode)) {
|
||||
ServletUtils.writeJSON(response, CommonResult.error(DATA_SOURCE_CODE_NOT_FOUND));
|
||||
return;
|
||||
}
|
||||
DynamicDataSourceContextHolder.push(dataSourceCode);
|
||||
DynamicDataSourceContextHolder.push(dataCode);
|
||||
filterChain.doFilter(request, response);
|
||||
DynamicDataSourceContextHolder.clear();
|
||||
}
|
||||
|
||||
+1
@@ -87,6 +87,7 @@ public class GlobalExceptionHandler {
|
||||
return serviceExceptionHandler((ServiceException) ex);
|
||||
}
|
||||
if (ex instanceof AccessDeniedException) {
|
||||
ex.printStackTrace();
|
||||
return accessDeniedExceptionHandler(request, (AccessDeniedException) ex);
|
||||
}
|
||||
return defaultExceptionHandler(request, ex);
|
||||
|
||||
+26
@@ -25,6 +25,8 @@ public class WebFrameworkUtils {
|
||||
|
||||
private static final String REQUEST_ATTRIBUTE_COMMON_RESULT = "common_result";
|
||||
|
||||
private static final String REQUEST_ATTRIBUTE_LOGIN_USER_NAME = "login-user-name";
|
||||
|
||||
public static final String HEADER_ORGAN_ID = "organ-id";
|
||||
|
||||
/**
|
||||
@@ -56,6 +58,10 @@ public class WebFrameworkUtils {
|
||||
request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID, userId);
|
||||
}
|
||||
|
||||
public static void setLoginUserName(ServletRequest request, String nickname) {
|
||||
request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_NAME, nickname);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户类型
|
||||
*
|
||||
@@ -80,6 +86,20 @@ public class WebFrameworkUtils {
|
||||
return (Long) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前用户的昵称,从请求中
|
||||
* 注意:该方法仅限于 framework 框架使用!!!
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 用户编号
|
||||
*/
|
||||
private static String getLoginUserName(HttpServletRequest request) {
|
||||
if (request == null) {
|
||||
return null;
|
||||
}
|
||||
return (String) request.getAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前用户的类型
|
||||
* 注意:该方法仅限于 web 相关的 framework 组件使用!!!
|
||||
@@ -116,6 +136,12 @@ public class WebFrameworkUtils {
|
||||
return getLoginUserId(request);
|
||||
}
|
||||
|
||||
public static String getLoginUserName() {
|
||||
HttpServletRequest request = getRequest();
|
||||
return getLoginUserName(request);
|
||||
}
|
||||
|
||||
|
||||
public static Integer getTerminal() {
|
||||
HttpServletRequest request = getRequest();
|
||||
if (request == null) {
|
||||
|
||||
Reference in New Issue
Block a user