Spring data rest - Is there a way to limit supported operations?

I want to provide data from a database as a Restful API in a Spring application (SpringBoot). Spring's Data Rest function seems to be exactly right for this activity.

This database is read-only for my applications. By default, all HTTP methods are used. Is there some kind of configuration that I can use to limit (in fact, prevent) other methods due to the fact that they were open?

+5
source share
2 answers

From the Spring docs on Hiding CRUD repository methods :

16.2.3. Hiding CRUD repository methods

If you do not want to disclose the save or delete method on your CrudRepository, you can use @RestResource (exported = false) by overriding the method you want to disable and placing the annotation in the advanced version. For example, to prevent HTTP users from calling CrudRepository removal methods, override all of them and add annotation to the override methods.

@RepositoryRestResource(path = "people", rel = "people") interface PersonRepository extends CrudRepository<Person, Long> { @Override @RestResource(exported = false) void delete(Long id); @Override @RestResource(exported = false) void delete(Person entity); } 

It is important that you redefine both deletion methods as an exporter, currently using a somewhat naive algorithm to determine which CRUD method to use in the interest of faster execution time. It is not currently possible to disable the delete version, which accepts the identifier, but leave the exported version, which accepts an instance of the object. For you can either export the removal methods or not. if you want to disable them, then just keep in mind that you must version with exported = false.

+12
source

Source: https://habr.com/ru/post/1264826/


All Articles