【发布时间】:2019-05-31 10:55:50
【问题描述】:
只有具有管理员角色的用户应该能够在“users/all”发出请求,但基本用户也可以。 这是我的安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/users/**").permitAll()
.antMatchers( "/users/all").authenticated().anyRequest().hasAnyRole("ADMIN")
.antMatchers("/users/me").authenticated().anyRequest().hasAnyRole("ADMIN", "BASIC_USER")
.and()
.formLogin().disable()
.httpBasic();
}
This is the request from Postman
为什么我可以向基本用户提出请求?
如果我把它们按这个顺序排列:
.antMatchers( "/users/all").authenticated().anyRequest().hasAnyRole("ADMIN")
.antMatchers("/users/me").authenticated().anyRequest().hasAnyRole("ADMIN", "BASIC_USER")
.antMatchers(HttpMethod.POST, "/users/**").permitAll()
还是一样,但是 /me 请求不再起作用了。
现在 /me 请求响应为 403。
【问题讨论】:
标签: rest http spring-boot spring-security basic-authentication