【发布时间】:2018-09-24 21:16:02
【问题描述】:
我的 Spring REST 服务具有以下安全适配器,以使用 HTTP 基本 http 身份验证。 现在,当我尝试向任何 GET HTTP 端点发送请求时,该请求已成功授权和处理。但是所有其他 HTTP 方法都返回 401。知道吗?
@EnableWebSecurity
public class WebSecurityAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password(passwordEncoder().encode("password")).roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/**").hasRole("USER").and().httpBasic();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
【问题讨论】:
标签: java spring-boot spring-security