删除方法显示"forbidden"消息



我正在测试一个允许我删除数据库内容的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但我确实得到:

{ "时间戳":"2019-05-11T17:57:36.310+0000", "状态":403, "错误": "禁止", "消息": "禁止", }

当我尝试使用DELETE方法删除时。

为什么会出现此错误,如何获得最终能够从数据库中删除对象的授权?

您应该禁用CSRF(跨站点请求伪造),默认情况下,对于任何修改状态(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(); 
}

最新更新