fix:previewImage方法添加进认证白名单
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.sdm.data.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "security.whitelist")
|
||||
@Data
|
||||
public class WhitelistProperties {
|
||||
|
||||
private List<String> paths = new ArrayList<>();
|
||||
|
||||
}
|
||||
@@ -1,24 +1,30 @@
|
||||
package com.sdm.data.filter;
|
||||
|
||||
import com.sdm.common.common.ThreadLocalContext;
|
||||
//import com.sdm.data.service.UserService;
|
||||
import com.sdm.data.config.WhitelistProperties;
|
||||
import jakarta.servlet.*;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class AuthFilter implements Filter {
|
||||
// @Resource
|
||||
// private UserService userService;
|
||||
@Autowired
|
||||
private WhitelistProperties whitelistProperties;
|
||||
|
||||
private List<String> excludedPaths;
|
||||
private final AntPathMatcher pathMatcher = new AntPathMatcher();
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
Filter.super.init(filterConfig);
|
||||
// 从初始化参数中读取白名单
|
||||
excludedPaths = whitelistProperties.getPaths();
|
||||
log.info("----------- AuthFilter init ----------");
|
||||
}
|
||||
|
||||
@@ -26,6 +32,14 @@ public class AuthFilter implements Filter {
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
if (servletRequest instanceof HttpServletRequest) {
|
||||
HttpServletRequest req = (HttpServletRequest) servletRequest;
|
||||
String path = req.getRequestURI().substring(req.getContextPath().length());
|
||||
// 检查当前请求是否在白名单中
|
||||
for (String excludedPath : excludedPaths) {
|
||||
if (pathMatcher.match(excludedPath, path)) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(!ThreadLocalContext.verifyRequest(req))
|
||||
{
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
|
||||
@@ -115,4 +115,9 @@ minio:
|
||||
secret-business-bucket: secretbusiness # 存放保密业务代码、脚本的桶(仅超级管理员访问)
|
||||
spdm-bucket: spdm # 普通业务数据桶(分配给用户读写权限)
|
||||
directMemory: 16384 # 16kb
|
||||
lifecycleConfig: '{"auto-expire-1d":"1d"}'
|
||||
lifecycleConfig: '{"auto-expire-1d":"1d"}'
|
||||
|
||||
security:
|
||||
whitelist:
|
||||
paths:
|
||||
- /data/previewImage
|
||||
@@ -122,6 +122,10 @@ management:
|
||||
db:
|
||||
enabled: false
|
||||
|
||||
security:
|
||||
whitelist:
|
||||
paths:
|
||||
- /data/previewImage
|
||||
|
||||
# 0单机处理,可以指向本地,1负载均衡轮询
|
||||
serverType: 0
|
||||
|
||||
@@ -155,4 +155,9 @@ minio:
|
||||
secure: false
|
||||
secret-business-bucket: secretbusiness # 存放保密业务代码、脚本的桶(仅超级管理员访问)
|
||||
spdm-bucket: spdm # 普通业务数据桶(分配给用户读写权限)
|
||||
directMemory: 16384 # 16kb
|
||||
directMemory: 16384 # 16kb
|
||||
|
||||
security:
|
||||
whitelist:
|
||||
paths:
|
||||
- /data/previewImage
|
||||
@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/systemMsg")
|
||||
@Tag(name = "系统评审")
|
||||
@Tag(name = "消息通知")
|
||||
public class SystemMessageController implements IMessageFeignClient {
|
||||
|
||||
@Autowired
|
||||
|
||||
Reference in New Issue
Block a user