I wonder if there are some good practices how to secure entities on the backend without fetching all the time the root entities.
Let's say you have an app (e.g. Spring Boot + MySQL) with the following entities:
- User: Each one could have many
project
or no one at all. - Project: each one belongs to a User and could have many Item or no one at all.
- Item: each one belongs to a Project and could have many Comment or no one at all.
- Comment: each one belongs to an Item or no one at all.
Something classic like
User --> Project --> Item --> Comment
I wonder how to check efficiently if a user has the right e.g. to delete a Comment
.
My first idea would be to join back up to Project and then check if the User has the right to modify this Project.
I also think about a big mapping table with each entities in order to prevent doing the 2 joins. But it seems a mess to keep in sync.
My third think is that a Document-oriented database could be a better bet than a classic MySQL/MariaDB.
So my question is, is there any concept or maybe concrete implementation/library/example how to solve this problem?