mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-08 16:57:09 +08:00
refactor(encrypt): 拆分字段加密、API 加密模块
This commit is contained in:
@@ -32,9 +32,9 @@ public class OrderedConstants {
|
||||
public static final class Filter {
|
||||
|
||||
/**
|
||||
* API加/密过滤器顺序
|
||||
* API 加密过滤器顺序
|
||||
*/
|
||||
public static final int API_CRYPTO_FILTER = Ordered.HIGHEST_PRECEDENCE;
|
||||
public static final int API_ENCRYPT_FILTER = Ordered.HIGHEST_PRECEDENCE;
|
||||
|
||||
/**
|
||||
* 链路追踪过滤器顺序
|
||||
|
@@ -49,31 +49,41 @@ public class PropertiesConstants {
|
||||
*/
|
||||
public static final String WEB_RESPONSE = WEB + StringConstants.DOT + "response";
|
||||
|
||||
/**
|
||||
* 加密配置
|
||||
*/
|
||||
public static final String ENCRYPT = CONTINEW_STARTER + StringConstants.DOT + "encrypt";
|
||||
|
||||
/**
|
||||
* 加密-密码编码器
|
||||
*/
|
||||
public static final String ENCRYPT_PASSWORD_ENCODER = ENCRYPT + StringConstants.DOT + "password-encoder";
|
||||
|
||||
/**
|
||||
* 加密-字段加密
|
||||
*/
|
||||
public static final String ENCRYPT_FIELD = ENCRYPT + StringConstants.DOT + "field";
|
||||
|
||||
/**
|
||||
* 加密-API 加密
|
||||
*/
|
||||
public static final String ENCRYPT_API = ENCRYPT + StringConstants.DOT + "api";
|
||||
|
||||
/**
|
||||
* 安全配置
|
||||
*/
|
||||
public static final String SECURITY = CONTINEW_STARTER + StringConstants.DOT + "security";
|
||||
|
||||
/**
|
||||
* 安全-数据加/解密配置
|
||||
* 安全-XSS 配置
|
||||
*/
|
||||
public static final String SECURITY_CRYPTO = SECURITY + StringConstants.DOT + "crypto";
|
||||
|
||||
/**
|
||||
* 安全-API加/解密配置
|
||||
*/
|
||||
public static final String SECURITY_API_CRYPTO = SECURITY + StringConstants.DOT + "api-crypto";
|
||||
public static final String SECURITY_XSS = SECURITY + StringConstants.DOT + "xss";
|
||||
|
||||
/**
|
||||
* 安全-敏感词配置
|
||||
*/
|
||||
public static final String SECURITY_SENSITIVE_WORDS = SECURITY + StringConstants.DOT + "sensitive-words";
|
||||
|
||||
/**
|
||||
* 安全-XSS 配置
|
||||
*/
|
||||
public static final String SECURITY_XSS = SECURITY + StringConstants.DOT + "xss";
|
||||
|
||||
/**
|
||||
* 限流配置
|
||||
*/
|
||||
|
@@ -20,12 +20,16 @@ import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.server.PathContainer;
|
||||
import org.springframework.web.accept.ContentNegotiationManager;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerExecutionChain;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
import org.springframework.web.util.pattern.PathPattern;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
@@ -135,4 +139,31 @@ public class SpringWebUtils {
|
||||
.getUrlMap();
|
||||
ReflectUtil.<Void>invoke(resourceHandlerMapping, "registerHandlers", additionalUrlMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取处理器方法
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 处理器方法
|
||||
* @since 2.14.0
|
||||
*/
|
||||
public static HandlerMethod getHandlerMethod(HttpServletRequest request) {
|
||||
try {
|
||||
RequestMappingHandlerMapping handlerMapping = SpringUtil
|
||||
.getBean("requestMappingHandlerMapping", RequestMappingHandlerMapping.class);
|
||||
HandlerExecutionChain handlerExecutionChain = handlerMapping.getHandler(request);
|
||||
// 检查是否存在处理链
|
||||
if (handlerExecutionChain == null) {
|
||||
return null;
|
||||
}
|
||||
// 获取处理器
|
||||
Object handler = handlerExecutionChain.getHandler();
|
||||
if (handler instanceof HandlerMethod handlerMethod) {
|
||||
return handlerMethod;
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user