英文:
Spring Security permitAll for root but protect everything else
问题
我想允许所有人访问 /,但限制所有其他路径
类似于
.antMatchers("/").permitAll()
.antMatchers("NOT /").authenticated()
对于 "NOT /",我该如何设置模式?
英文:
I want to allow access to / for everybody but restrict all other paths
Something like
.antMatchers("/").permitAll()
.antMatchers("NOT /").authenticated()
How do I have to set the pattern for "NOT /"?
答案1
得分: 3
尝试一下这个:
.antMatchers("/").permitAll()
.anyRequest().authenticated()
permitAll()
只会应用于匹配 "/"
的请求,其他请求将会进一步路由到 authenticated()
。
英文:
Try this:
.antMatchers("/").permitAll()
.anyRequest().authenticated()
permitAll()
will only be applied to requests matching "/"
, other requests will be routed further to authenticated()
.
专注分享java语言的经验与见解,让所有开发者获益!
评论