【发布时间】:2019-04-01 21:25:29
【问题描述】:
我收到错误 403 Forbidden for POST 端点,其他端点按预期工作。
我有 4 个端点,我需要重现身份验证行为:
GET \users - no authentication
GET \details\1 - needs authentication
GET \users\1 needs authentication
POST \users\1 needs authentication
我的配置类:
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication()
.passwordEncoder(org.springframework.security
.crypto.password.NoOpPasswordEncoder.getInstance())
.withUser("user").password("pwd")
.roles("USER").and().withUser("admin").password("pwd")
.roles("USER", "ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers( "/users").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic();
}
}
Maven 依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
【问题讨论】:
标签: spring-boot spring-security