你好亲爱的社区,
关于我的目标的细节:
实际结果:
然后我增加了安全性:
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
发布于 2021-08-23 10:19:46
终于起作用了。
上面我告诉过我不适合上面提到的堆栈溢出链接,但是它是有效的。
我补充说:
.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();}
https://stackoverflow.com/questions/68890628
复制相似问题