我试图使用POST请求插入数据,但是我得到了一个403错误。当我使用GET时,基本身份验证是有效的。测试用的是Fiddler。
有什么问题吗?
安全配置:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/**").hasRole("USER").and()
.httpBasic();
}
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth
.inMemoryAuthentication()
.withUser("user")
.password("password")
.roles("USER");
}
}请求-员额:
User-Agent: Fiddler
Host: localhost:8080
Content-Length: 200
Content-Type: application/json
Authorization: Basic dXNlcjpwYXNzd29yZA==请求机构:
{"name" : "name1",
"description" : "desc1"}发布于 2015-05-26 23:46:37
它可能是CSRF,它是spring安全默认启用的。在GET请求中查找标头,并在POST中使用该标头和值。
在做这件事之前要三思,但是你可以用
http.csrf().disable()https://docs.spring.io/spring-security/site/docs/current/reference/html/web-app-security.html#csrf
发布于 2015-05-26 21:31:50
试试这个:
@Configuration
@EnableWebSecurity
public class HelloWebSecurityConfiguration
extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}来源:http://spring.io/blog/2013/07/03/spring-security-java-config-preview-web-security/
https://stackoverflow.com/questions/30469093
复制相似问题