Spring Security 允许 root 访问,但保护其他所有资源。

huangapple go评论60阅读模式
英文:

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().

huangapple
  • 本文由 发表于 2020年5月5日 16:34:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/61609004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定