【发布时间】:2019-05-11 20:20:07
【问题描述】:
我有一个路径列表,我想提供给antMatchers()。但由于这个列表是动态的,我不能提供逗号分隔的路径。我目前正在遍历列表并将每个路径添加到antMatcher()。有没有更好的方法可以将 antMatcher 应用于路径列表?
当前代码sn-p:
http.authorizeRequests()
.antMatchers("/signup","/about")
.hasRole("ADMIN")
.anyRequest().authenticated();
我有一个路径列表。例如:
List<String> pathList = Arrays.asList(new String[]{"/signup","/about"});
我想应用 antMatchers 类似的东西:
http.authorizeRequests()
.antMatchers(pathList)
.hasRole("ADMIN")
.anyRequest().authenticated();
参考:https://spring.io/blog/2013/07/11/spring-security-java-config-preview-readability/ spring security http antMatcher with multiple paths
【问题讨论】: