AnonymousPathProperties.java 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.inspur.smsb.gateway.config;
  2. import lombok.Setter;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.boot.context.properties.ConfigurationProperties;
  5. import org.springframework.stereotype.Component;
  6. import org.springframework.util.AntPathMatcher;
  7. import java.util.List;
  8. /**
  9. * anonymous path config properties
  10. * @author linwenhua
  11. * @date 2022-12-15 10:55
  12. **/
  13. @Slf4j
  14. @Component
  15. @ConfigurationProperties(prefix = "anonymous-path")
  16. public class AnonymousPathProperties {
  17. @Setter
  18. private List<String> paths;
  19. private final AntPathMatcher antPathMatcher = new AntPathMatcher();
  20. public String[] getPaths() {
  21. String[] pathArray = new String[paths.size()];
  22. return paths.toArray(pathArray);
  23. }
  24. public boolean checkAnonymousPath(String path){
  25. // 判断该路径是否在白名单里,如果是直接放行
  26. for (String url : paths) {
  27. if (antPathMatcher.match(url, path)) {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. }