如何使用Spring Security禁用@Controller中的单个路径授权[复制]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用Spring Security禁用@Controller中的单个路径授权[复制]相关的知识,希望对你有一定的参考价值。
通过配置HttpSecurity
可以禁用特定路径的授权:
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
...
.antMatchers("/some/open/resources/**")
.permitAll();
}
是否也可以在Spring @Controller
级别上做同样的事情?最好通过一些注释,如下所示:
@RequestMapping(value = "/some/open/resources/")
@NoAuthorization
public void get() {
// return something
}
答案
我不知道,但你可以这样做:
http.authorizeRequests()
.anyRequest().permitAll();
.antMatchers("/", "/home").permitAll()
.antMatchers("/viewFingerprints").permitAll()
.anyRequest().authenticated()
你只能访问/home
和/viewFingerprints
,其余的将被阻止。
以上是关于如何使用Spring Security禁用@Controller中的单个路径授权[复制]的主要内容,如果未能解决你的问题,请参考以下文章