Commit 423f6cc9da8cc5ecac95f3e763cd61636b0df45b
1 parent
f3dbcf46
【修复】全局:@PermitAll 未处理 RequestMappingInfo.getPatternsCondition 的问题
Showing
1 changed file
with
14 additions
and
3 deletions
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 | 28 | import org.springframework.web.method.HandlerMethod; |
| 29 | 29 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; |
| 30 | 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 | 34 | import java.util.List; |
| 33 | 35 | import java.util.Map; |
| 34 | 36 | import java.util.Set; |
| 35 | 37 | |
| 38 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; | |
| 39 | + | |
| 36 | 40 | /** |
| 37 | 41 | * 自定义的 Spring Security 配置适配器实现 |
| 38 | 42 | * |
| ... | ... | @@ -163,13 +167,20 @@ public class YudaoWebSecurityConfigurerAdapter { |
| 163 | 167 | if (!handlerMethod.hasMethodAnnotation(PermitAll.class)) { |
| 164 | 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 | 178 | continue; |
| 168 | 179 | } |
| 169 | - Set<String> urls = entry.getKey().getPatternsCondition().getPatterns(); | |
| 180 | + | |
| 170 | 181 | // 特殊:使用 @RequestMapping 注解,并且未写 method 属性,此时认为都需要免登录 |
| 171 | 182 | Set<RequestMethod> methods = entry.getKey().getMethodsCondition().getMethods(); |
| 172 | - if (CollUtil.isEmpty(methods)) { // | |
| 183 | + if (CollUtil.isEmpty(methods)) { | |
| 173 | 184 | result.putAll(HttpMethod.GET, urls); |
| 174 | 185 | result.putAll(HttpMethod.POST, urls); |
| 175 | 186 | result.putAll(HttpMethod.PUT, urls); | ... | ... |