java - 允许 URL 中的语言参数(Spring Boot / Security)
问题描述
你好亲爱的社区,
关于我的目标的详细信息:
- 在Spring Boot应用程序中使用国际化以及Spring Security 的身份验证机制
实际结果:
- 国际化效果很好
然后我添加了安全性:
http.authorizeRequests()
// Restrict Endpoints
.antMatchers("/login/**").hasAnyRole("admin", "member")
// Allow Forms
.antMatchers("/member/**").permitAll()
// Allow Resources
.antMatchers("/js/**").permitAll()
.antMatchers("/css/**").permitAll()
// Deny All
.anyRequest().authenticated();
}
由于.anyRequest().authenticated()
根路径上的请求/?lang=de
会触发身份验证。
我尝试了什么:
http.authorizeRequests()
// Restrict Endpoints
.antMatchers("/login/**").hasAnyRole("admin", "member")
// Allow Forms
.antMatchers("/member/**").permitAll()
// Allow Resources
.antMatchers("/js/**").permitAll()
.antMatchers("/css/**").permitAll()
// Trick to allow Internationalization
.antMatchers("/*").permitAll()
// Deny All
.anyRequest().authenticated();
}
我添加了.antMatchers("/*").permitAll()
哪个有效,但它允许在根路径上使用很多资源。我的目标是只允许/?lang=de
不进行身份验证。
有机会吗?
我研究过但不满意的资源:
亲切的问候
OtenMoten
解决方案
好吧,终于它工作了。
上面我告诉过我对提到的 stackoverflow 链接不满意,但它正在工作。
我已经添加:
.regexMatchers("/.*lang=.*").permitAll()
http.authorizeRequests()
// Restrict Endpoints
.antMatchers("/login/**").hasAnyRole("admin", "member")
// Allow Forms
.antMatchers("/member/**").permitAll()
// Allow Resources
.antMatchers("/js/**").permitAll()
.antMatchers("/css/**").permitAll()
.regexMatchers("/.*lang=.*").permitAll()
// Deny All
.anyRequest().authenticated();
}
推荐阅读
- dart - 将项目/文件夹颤动复制到另一台计算机
- c# - 在 VS 2017 SDK 文档中找不到命名空间?
- module - 如何在自定义 Ansible 模块中区分源路径和远程路径
- rasa-nlu - RASA 实体在训练后未检测到同义词
- php - 分组和计数数组php
- python - 尝试合并两列上的两个数据帧时,“NoneType”类型的对象没有 len()
- android - FFMpeg 库:如何在音频文件中精确查找
- python - max(my_array) 和 my_array.max() 有什么区别
- string - Python3:在一行中返回带有字符串的random.randint
- path - Git Bash 中 Windows 7 上的“bash:aws:找不到命令”