【发布时间】:2022-02-25 16:03:45
【问题描述】:
在我拥有此配置的那一刻起,我一直在尝试为不同的 api 端点设置多个安全配置:
http
.antMatcher("/user/**")
.authorizeRequests()
.antMatchers("/user/document/**").permitAll()
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic();
此配置正在运行,但当我尝试删除第二个 authorizeRequests()(见下文)时,我也感到困惑。配置也正常。
http
.antMatcher("/user/**")
.authorizeRequests()
.antMatchers("/user/document/**").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic();
这个方法有什么作用?我必须每次都调用它吗?
【问题讨论】:
-
您可以重复每个方法,因为方法链。但你不需要它。为了更好的可读性,您不应重复任何方法。此外,在某些情况下,第二次调用可能会覆盖第一次调用。
标签: java spring spring-security