java - 如何以编程方式检索所有蚂蚁匹配器 URL
问题描述
我有一个基本的 Spring 应用程序,它具有各种端点和一个登录页面,通过配置 WebSecurityConfigurerAdapter 的 HttpSecurity 来定义。
我有一个服务,它在我的应用程序中查找所有端点并收集有关它们的一些基本信息,我通过自动装配 RequestMappingHandlerMapping 类并遍历不同的处理程序方法来实现这些信息。
我想为 WebSecurityConfigurer 适配器定义的路径收集一些类似的信息。
例如,在配置方法中,如果我有,请说:
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().authorizeRequests()
.antMatchers(HttpMethod.POST, "/login").permitAll()
我想从服务中收集信息:"/login"
和HttpMethod.POST
。任何帮助将不胜感激!
解决方案
我的帖子没有直接回答这个问题,因为我不知道有办法做到这一点。但是,有一个解决方法,这个想法值得一个机会:
我建议你有一个映射源并antMatchers
动态设置。该解决方案既配置了适配器,又保留了映射源以供进一步使用(我建议保持值本身不可变)。
List<MatcherMapping> mappings = ....
for (MatcherMapping mapping: mappings) {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().authorizeRequests()
.antMatchers(mapping.getHttpMethod(), mapping.getUrl())
.permitAll()
}
该类MatcherMapping
将只是一个简单的数据容器。
public final class MatcherMapping {
private final HttpMethod httpMethod;
private final String url;
// constructor and getters
}
无论您是使用服务获取数据还是直接获取数据,最终都取决于您。
推荐阅读
- vue.js - 如何修复 vue.js 中的库添加错误
- ssl - 无法使用零 ssl 验证 github 页面 dns
- c# - C# 中国际象棋的 MiniMax 算法无法正常工作
- python - 如何处理代码以避免被杀?
- jquery - JQuery根据选择在表中添加新行
- python-3.x - 如何从 SHA3-512 哈希值生成密码?
- python - python azure sdk - 列出存储帐户 SKU
- python - 如何更新特定记录中的值?
- android - On click isn't fired on recyclerview in nestedscrollview under coordinatorlayout in Android
- android - My app crashes when I Log in because of Badge Counter(getOrCreateBadge) for Kotlinn