【发布时间】:2021-06-29 21:17:06
【问题描述】:
为了授权请求,我们覆盖了configure(HttpSecurity) 方法,我们在该方法中提到了访问我们想要哪个角色的 API。但是我们没有提到的 API 无需登录即可访问。为什么会出现这种行为?
我没有为 API 写 permitAll() 为什么这是默认行为?
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/admin").hasRole("ADMIN")
.antMatchers("/user").hasAnyRole("ADMIN", "USER")
.antMatchers("/").hasRole("USER")
.and()
.formLogin();
}
}
在此代码中admin API 可以通过管理员角色访问,user API 可以通过管理员和用户角色访问,/ API 可以通过用户角色访问并且还有一个 API @987654327 @ 我没有提到,我可以在没有登录的情况下访问它。
问题是我怎么没有为学生 API 编写 permitAll() 方法。
【问题讨论】:
标签: java spring spring-boot security spring-security