Pre Merge pull request !117 from jackie/master

pull/117/MERGE
jackie 2024-05-11 15:53:23 +00:00 committed by Gitee
commit d3318a7633
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 16 additions and 2 deletions

View File

@ -24,12 +24,15 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.util.pattern.PathPattern;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Spring Security
@ -161,10 +164,21 @@ public class YudaoWebSecurityConfigurerAdapter {
if (!handlerMethod.hasMethodAnnotation(PermitAll.class)) {
continue;
}
if (entry.getKey().getPatternsCondition() == null) {
Set<String> urls = new HashSet<>();
if (null != entry.getKey().getPatternsCondition()) {
urls.addAll( entry.getKey().getPatternsCondition().getPatterns());
}
//如果请求路径与控制器方法的路径模式匹配但请求方法不匹配则getPatternsCondition()会返回false而getPathPatternsCondition()仍然会返回true
if (null != entry.getKey().getPathPatternsCondition()){
urls.addAll(entry.getKey().getPathPatternsCondition().getPatterns().stream().map(PathPattern::getPatternString).collect(Collectors.toSet()));
}
if (urls.isEmpty()){
continue;
}
Set<String> urls = entry.getKey().getPatternsCondition().getPatterns();
// 特殊:使用 @RequestMapping 注解,并且未写 method 属性,此时认为都需要免登录
Set<RequestMethod> methods = entry.getKey().getMethodsCondition().getMethods();
if (CollUtil.isEmpty(methods)) { //