【发布时间】:2019-12-18 20:04:18
【问题描述】:
我正在尝试熟悉 Spring Boot 安全性,我的 API 是一个简单的 GET/POST 到 127.0.0.1:8080/employee/ 像这样简单的自动配置。
@Configuration
public class SecurityConfig implements WebMvcConfigurer {
@Configuration
protected static class ApplicationSecurity extends WebSecurityConfigurerAdapter{
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user1").password("{noop}user1").authorities("USER").and()
.withUser("user2").password("{noop}user2").authorities("USER").and()
.withUser("admin").password("{noop}admin").authorities("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/employee/**").authorizeRequests().anyRequest().hasRole("ADMIN");
}
}
}
这总是给我 403 Forbidden。 试过这个: - antMatcher("/employee*"),适用于任何用户。我能否在理解此模式的工作原理方面获得一些帮助,我只需要将“/employee”或“/employee/”或“/employee/1”限制为 Admin。
【问题讨论】:
标签: spring-boot spring-security roles