如何在 Spring Data REST 中允许 POST 和 PATCH 的同时禁止 PUT? [英] How to disallow PUT while allowing POST and PATCH in Spring Data REST?

查看:25
本文介绍了如何在 Spring Data REST 中允许 POST 和 PATCH 的同时禁止 PUT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在 Spring Data REST 中完全禁止存储库的 PUT,而在集合上的 POST 和项目上的 PATCH 仍然可能?

Is it possible to completely disallow PUT for a repository in Spring Data REST while POST on the collection and PATCH on the item remain possible?

这背后的基本原理是 PUT 通常允许替换语义,但在我们的例子中,资源只能通过集合上的 POST 创建,通过项目上的 PATCH 部分更新(使用特定的 UI 对话框......每个仅支持特定的部分更新),或通过项目的 DELETE 删除.

The rationale behind this is that a PUT typically allows for replace semantics, but in our case the resource can only be created via POST on the collection, partially updated via PATCH on the item (using specific UI dialogs... each of which only supports a particular partial update), or deleted via DELETE on the item.

推荐答案

如果您的应用程序中有 Spring 安全性,那么这可以通过添加intercept-url 来拒绝访问 Spring 数据存储库上的 PUT 方法来完成,如下所示:

If you have Spring security in your application, then this can be done by adding intercept-url to deny access to PUT method on Spring data repository, something like below:

<security:intercept-url pattern="/{repositoryPath}" method="PUT" access="denyAll" />

这篇关于如何在 Spring Data REST 中允许 POST 和 PATCH 的同时禁止 PUT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆