mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-28 04:57:17 +08:00
refactor: 适配 ContiNew Starter 密码编码器(安全模块)、链路跟踪(Web 模块)
并适配 ContiNew Starter CRUD 模块包调整
This commit is contained in:
@@ -96,6 +96,12 @@
|
||||
<artifactId>continew-starter-file-excel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ContiNew Starter 安全模块 - 密码编码器 -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-security-password</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ContiNew Starter API 文档模块 -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
@@ -107,11 +113,5 @@
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-json-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- TLog(轻量级的分布式日志标记追踪神器) -->
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>tlog-web-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -16,17 +16,14 @@
|
||||
|
||||
package top.charles7c.continew.admin.common.config.mybatis;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import top.charles7c.continew.admin.common.util.helper.LoginHelper;
|
||||
import top.charles7c.continew.starter.core.exception.BusinessException;
|
||||
import top.charles7c.continew.starter.extension.crud.base.BaseDO;
|
||||
import top.charles7c.continew.starter.extension.crud.model.entity.BaseDO;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* MyBatis Plus 元对象处理器配置(插入或修改时自动填充)
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.common.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* TLog 配置属性
|
||||
*
|
||||
* <p>
|
||||
* 重写 TLog 配置以适配 Spring Boot 3.x
|
||||
* </p>
|
||||
*
|
||||
* @author Jasmine
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "tlog")
|
||||
public class TLogProperties {
|
||||
|
||||
/**
|
||||
* 日志标签模板
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* 自动打印调用参数和时间
|
||||
*/
|
||||
private Boolean enableInvokeTimePrint;
|
||||
|
||||
/**
|
||||
* 自定义 TraceId 生成器
|
||||
*/
|
||||
private String idGenerator;
|
||||
|
||||
/**
|
||||
* MDC 模式
|
||||
*/
|
||||
private Boolean mdcEnable;
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.common.config.tlog;
|
||||
|
||||
import com.yomahub.tlog.id.TLogIdGeneratorLoader;
|
||||
import com.yomahub.tlog.spring.TLogPropertyInit;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import top.charles7c.continew.admin.common.config.properties.TLogProperties;
|
||||
|
||||
/**
|
||||
* TLog 配置
|
||||
*
|
||||
* <p>
|
||||
* 重写 TLog 配置以适配 Spring Boot 3.x
|
||||
* </p>
|
||||
*
|
||||
* @see TLogConfiguration
|
||||
* @author Jasmine
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
@EnableConfigurationProperties(TLogProperties.class)
|
||||
public class TLogConfiguration {
|
||||
|
||||
private final TLogProperties tLogProperties;
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public TLogPropertyInit tLogPropertyInit() {
|
||||
TLogPropertyInit tLogPropertyInit = new TLogPropertyInit();
|
||||
tLogPropertyInit.setPattern(tLogProperties.getPattern());
|
||||
tLogPropertyInit.setEnableInvokeTimePrint(tLogProperties.getEnableInvokeTimePrint());
|
||||
tLogPropertyInit.setMdcEnable(tLogProperties.getMdcEnable());
|
||||
// 设置自定义 TraceId 生成器
|
||||
TLogIdGeneratorLoader.setIdGenerator(new TraceIdGenerator());
|
||||
return tLogPropertyInit;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.common.config.tlog;
|
||||
|
||||
import com.yomahub.tlog.context.TLogContext;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.charles7c.continew.admin.common.constant.SysConstants;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* TLog 过滤器
|
||||
*
|
||||
* <p>
|
||||
* 重写 TLog 配置以适配 Spring Boot 3.x
|
||||
* </p>
|
||||
*
|
||||
* @see TLogConfiguration
|
||||
* @author Jasmine
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
@Component
|
||||
public class TLogServletFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request,
|
||||
ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
if (request instanceof HttpServletRequest httpServletRequest && response instanceof HttpServletResponse httpServletResponse) {
|
||||
try {
|
||||
TLogWebCommon.loadInstance().preHandle(httpServletRequest);
|
||||
// 把 traceId 放入 response 的 header,为了方便有些人有这样的需求,从前端拿整条链路的 traceId
|
||||
httpServletResponse.addHeader(SysConstants.TRACE_ID, TLogContext.getTraceId());
|
||||
chain.doFilter(request, response);
|
||||
return;
|
||||
} finally {
|
||||
TLogWebCommon.loadInstance().afterCompletion();
|
||||
}
|
||||
}
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.common.config.tlog;
|
||||
|
||||
import com.yomahub.tlog.constant.TLogConstants;
|
||||
import com.yomahub.tlog.core.rpc.TLogLabelBean;
|
||||
import com.yomahub.tlog.core.rpc.TLogRPCHandler;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* TLog Web 通用拦截器
|
||||
*
|
||||
* <p>
|
||||
* 重写 TLog 配置以适配 Spring Boot 3.x
|
||||
* </p>
|
||||
*
|
||||
* @see TLogWebCommon
|
||||
* @author Jasmine
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
public class TLogWebCommon extends TLogRPCHandler {
|
||||
|
||||
private static volatile TLogWebCommon tLogWebCommon;
|
||||
|
||||
public static TLogWebCommon loadInstance() {
|
||||
if (tLogWebCommon == null) {
|
||||
synchronized (TLogWebCommon.class) {
|
||||
if (tLogWebCommon == null) {
|
||||
tLogWebCommon = new TLogWebCommon();
|
||||
}
|
||||
}
|
||||
}
|
||||
return tLogWebCommon;
|
||||
}
|
||||
|
||||
public void preHandle(HttpServletRequest request) {
|
||||
String traceId = request.getHeader(TLogConstants.TLOG_TRACE_KEY);
|
||||
String spanId = request.getHeader(TLogConstants.TLOG_SPANID_KEY);
|
||||
String preIvkApp = request.getHeader(TLogConstants.PRE_IVK_APP_KEY);
|
||||
String preIvkHost = request.getHeader(TLogConstants.PRE_IVK_APP_HOST);
|
||||
String preIp = request.getHeader(TLogConstants.PRE_IP_KEY);
|
||||
TLogLabelBean labelBean = new TLogLabelBean(preIvkApp, preIvkHost, preIp, traceId, spanId);
|
||||
processProviderSide(labelBean);
|
||||
}
|
||||
|
||||
public void afterCompletion() {
|
||||
cleanThreadLocal();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.common.config.tlog;
|
||||
|
||||
import com.yomahub.tlog.id.TLogIdGenerator;
|
||||
import com.yomahub.tlog.id.snowflake.UniqueIdGenerator;
|
||||
|
||||
/**
|
||||
* TLog ID 自定义生成器
|
||||
*
|
||||
* @see TraceIdGenerator
|
||||
* @author Jasmine
|
||||
* @since 2024/1/30 11:39
|
||||
*/
|
||||
public class TraceIdGenerator extends TLogIdGenerator {
|
||||
@Override
|
||||
public String generateTraceId() {
|
||||
return String.valueOf(UniqueIdGenerator.generateId());
|
||||
}
|
||||
}
|
||||
@@ -68,9 +68,4 @@ public class SysConstants {
|
||||
* 描述类字段后缀
|
||||
*/
|
||||
public static final String DESCRIPTION_FIELD_SUFFIX = "String";
|
||||
|
||||
/**
|
||||
* Trace ID
|
||||
*/
|
||||
public static final String TRACE_ID = "traceId";
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import top.charles7c.continew.admin.common.constant.CacheConstants;
|
||||
import top.charles7c.continew.admin.common.model.dto.LoginUser;
|
||||
import top.charles7c.continew.starter.core.util.ExceptionUtils;
|
||||
import top.charles7c.continew.starter.core.util.IpUtils;
|
||||
import top.charles7c.continew.starter.extension.crud.base.CommonUserService;
|
||||
import top.charles7c.continew.starter.extension.crud.service.CommonUserService;
|
||||
import top.charles7c.continew.starter.web.util.ServletUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
Reference in New Issue
Block a user