I am working on a Spring Boot RESTful application which will be exposing a bunch of APIs for the web app to perform CRUD operations on the resources.
I am using spring-data-rest
(along with spring-data-jpa
of course) to expose the entities/repositories with the help of Spring Magic.
Even though I have secured (role-based) the endpoints with spring-security, it is not completely secure.
For example:
I have a User
entity with has one-to-many
relationship with Car
. So the endpoint (auto exposed by spring-data-rest
) for getting a user's cars is localhost:8080/users/{userId}/cars
However, any user with the required role can just pass the userId
of another user and still access the endpoint.
The behavior I want is to secure these endpoints in a way that if I a logged-in user's ID is 1
, then we can only hit localhost:8080/users/1/cars. Any other request with any other userId
should end up in 403
or something.
Note: I know if write my own controllers then I can get a handle of the principal and do what I desire. I just want to know is there a way or pattern in spring-data-rest
to achieve this?