mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-14 20:33:40 +00:00
Merge pull request #85 from MuSan-Li/feature_20250516_fix_auth
修复未登录也可以访问接口
This commit is contained in:
@@ -10,6 +10,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有Url配置
|
* 获取所有Url配置
|
||||||
@@ -19,23 +20,24 @@ import java.util.regex.Pattern;
|
|||||||
@Data
|
@Data
|
||||||
public class AllUrlHandler implements InitializingBean {
|
public class AllUrlHandler implements InitializingBean {
|
||||||
|
|
||||||
private static final Pattern PATTERN = Pattern.compile("\\{(.*?)\\}");
|
private List<String> urls = new ArrayList<>(256);
|
||||||
|
|
||||||
private List<String> urls = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
Set<String> set = new HashSet<>();
|
String name = "requestMappingHandlerMapping";
|
||||||
RequestMappingHandlerMapping mapping = SpringUtils.getBean("requestMappingHandlerMapping", RequestMappingHandlerMapping.class);
|
RequestMappingHandlerMapping mapping = SpringUtils.getBean(name, RequestMappingHandlerMapping.class);
|
||||||
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
|
|
||||||
map.keySet().forEach(info -> {
|
Map<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();
|
||||||
// 获取注解上边的 path 替代 path variable 为 *
|
|
||||||
if(info.getPathPatternsCondition()!=null){
|
Pattern pattern = Pattern.compile("\\{(.*?)\\}");
|
||||||
Objects.requireNonNull(info.getPathPatternsCondition().getPatterns())
|
|
||||||
.forEach(url -> set.add(ReUtil.replaceAll(url.getPatternString(), PATTERN, "*")));
|
Set<String> handlerSet = handlerMethods.keySet().stream()
|
||||||
}
|
.flatMap(info -> info.getPatternsCondition().getPatterns().stream())
|
||||||
});
|
.collect(Collectors.toSet());
|
||||||
urls.addAll(set);
|
|
||||||
|
// 获取注解上边的 path 替代 path variable 为 *
|
||||||
|
handlerSet.stream().map(path -> ReUtil.replaceAll(path, pattern, "*"))
|
||||||
|
.forEach(item -> urls.add(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user