【发布时间】:2021-10-23 16:30:11
【问题描述】:
亲爱的社区,您好,
关于我的目标的详细信息:
- 在 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 无需身份验证。
有机会吗?
我研究过但不满意的资源:
- antMatchers Spring Security pattern with changeable URL user ID
- Regex doesn't match antMatcher URL pattern
亲切的问候
OtenMoten
【问题讨论】:
标签: java spring-boot authentication spring-security internationalization