Commit 423f6cc9da8cc5ecac95f3e763cd61636b0df45b

Authored by YunaiV
1 parent f3dbcf46

【修复】全局:@PermitAll 未处理 RequestMappingInfo.getPatternsCondition 的问题

yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java
@@ -28,11 +28,15 @@ import org.springframework.web.bind.annotation.RequestMethod; @@ -28,11 +28,15 @@ import org.springframework.web.bind.annotation.RequestMethod;
28 import org.springframework.web.method.HandlerMethod; 28 import org.springframework.web.method.HandlerMethod;
29 import org.springframework.web.servlet.mvc.method.RequestMappingInfo; 29 import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
30 import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; 30 import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
  31 +import org.springframework.web.util.pattern.PathPattern;
31 32
  33 +import java.util.HashSet;
32 import java.util.List; 34 import java.util.List;
33 import java.util.Map; 35 import java.util.Map;
34 import java.util.Set; 36 import java.util.Set;
35 37
  38 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
  39 +
36 /** 40 /**
37 * 自定义的 Spring Security 配置适配器实现 41 * 自定义的 Spring Security 配置适配器实现
38 * 42 *
@@ -163,13 +167,20 @@ public class YudaoWebSecurityConfigurerAdapter { @@ -163,13 +167,20 @@ public class YudaoWebSecurityConfigurerAdapter {
163 if (!handlerMethod.hasMethodAnnotation(PermitAll.class)) { 167 if (!handlerMethod.hasMethodAnnotation(PermitAll.class)) {
164 continue; 168 continue;
165 } 169 }
166 - if (entry.getKey().getPatternsCondition() == null) { 170 + Set<String> urls = new HashSet<>();
  171 + if (entry.getKey().getPatternsCondition() != null) {
  172 + urls.addAll(entry.getKey().getPatternsCondition().getPatterns());
  173 + }
  174 + if (entry.getKey().getPathPatternsCondition() != null) {
  175 + urls.addAll(convertList(entry.getKey().getPathPatternsCondition().getPatterns(), PathPattern::getPatternString));
  176 + }
  177 + if (urls.isEmpty()) {
167 continue; 178 continue;
168 } 179 }
169 - Set<String> urls = entry.getKey().getPatternsCondition().getPatterns(); 180 +
170 // 特殊:使用 @RequestMapping 注解,并且未写 method 属性,此时认为都需要免登录 181 // 特殊:使用 @RequestMapping 注解,并且未写 method 属性,此时认为都需要免登录
171 Set<RequestMethod> methods = entry.getKey().getMethodsCondition().getMethods(); 182 Set<RequestMethod> methods = entry.getKey().getMethodsCondition().getMethods();
172 - if (CollUtil.isEmpty(methods)) { // 183 + if (CollUtil.isEmpty(methods)) {
173 result.putAll(HttpMethod.GET, urls); 184 result.putAll(HttpMethod.GET, urls);
174 result.putAll(HttpMethod.POST, urls); 185 result.putAll(HttpMethod.POST, urls);
175 result.putAll(HttpMethod.PUT, urls); 186 result.putAll(HttpMethod.PUT, urls);