删除方法显示 "forbidden" 消息
Delete method displays "forbidden" message
我正在测试允许我删除数据库内容的 Spring-boot
应用程序。我临时访问了我配置中的所有端点:
@Override
protected void configure(HttpSecurity http) throws Exception {
//Allow access to all endpoints
http.cors().and().authorizeRequests().anyRequest().permitAll();
}
属性为:
spring.datasource.url=jdbc:mariadb://localhost:3307/cardb
spring.datasource.username=root
spring.datasource.password=******
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.data.rest.basePath=/api
然后我可以使用应用程序中的 GET
方法或从 Postman
从数据库中获取内容,但我确实得到了:
{
"timestamp": "2019-05-11T17:57:36.310+0000",
"status": 403,
"error": "Forbidden",
"message": "Forbidden",
}
当我尝试使用 DELETE
方法删除时。
为什么会出现此错误?如何获得最终能够从数据库中删除对象的授权?
您应该禁用 CSRF(Cross-Site 请求伪造),它默认为任何修改状态的方法(PATCH、POST、PUT 和 DELETE – 不是 GET)启用:
@Override
protected void configure(HttpSecurity http) throws Exception {
//Allow access to all endpoints
http.csrf().disable().cors().and().authorizeRequests().anyRequest().permitAll();
}
我正在测试允许我删除数据库内容的 Spring-boot
应用程序。我临时访问了我配置中的所有端点:
@Override
protected void configure(HttpSecurity http) throws Exception {
//Allow access to all endpoints
http.cors().and().authorizeRequests().anyRequest().permitAll();
}
属性为:
spring.datasource.url=jdbc:mariadb://localhost:3307/cardb
spring.datasource.username=root
spring.datasource.password=******
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.data.rest.basePath=/api
然后我可以使用应用程序中的 GET
方法或从 Postman
从数据库中获取内容,但我确实得到了:
{ "timestamp": "2019-05-11T17:57:36.310+0000", "status": 403, "error": "Forbidden", "message": "Forbidden", }
当我尝试使用 DELETE
方法删除时。
为什么会出现此错误?如何获得最终能够从数据库中删除对象的授权?
您应该禁用 CSRF(Cross-Site 请求伪造),它默认为任何修改状态的方法(PATCH、POST、PUT 和 DELETE – 不是 GET)启用:
@Override
protected void configure(HttpSecurity http) throws Exception {
//Allow access to all endpoints
http.csrf().disable().cors().and().authorizeRequests().anyRequest().permitAll();
}