package com.inspur.smsb.gateway.config; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.util.AntPathMatcher; import java.util.List; /** * anonymous path config properties * @author linwenhua * @date 2022-12-15 10:55 **/ @Slf4j @Component @ConfigurationProperties(prefix = "anonymous-path") public class AnonymousPathProperties { @Setter private List paths; private final AntPathMatcher antPathMatcher = new AntPathMatcher(); public String[] getPaths() { String[] pathArray = new String[paths.size()]; return paths.toArray(pathArray); } public boolean checkAnonymousPath(String path){ // 判断该路径是否在白名单里,如果是直接放行 for (String url : paths) { if (antPathMatcher.match(url, path)) { return true; } } return false; } }