I am working on a Spring web application that uses:
- Spring MVC
- Spring Core
- Spring Roo
- Spring Security
- Spring Data JPA
- Mysql
The issue I have is as follows: for each access from the web layer to the application's entities/objects I want to be able to check whether or not they do indeed belong to the current user.
Let me illustrate: users of the application have advertisements, curriculums (referred to as entities/objects). I frequently perform GETs or POSTs on those objects/entities using the PK/ID in order to retrieve, update or delete those objects. As of now, I have not found a clean and flexible way to prevent a user from retrieving, updating or deleting someone else's objects.
I use Spring Security and I know at any time who is the current user (currently logged-in user/principal) but I am not sure where (which layer) and how to perform the check.
I have tried advising the service and controller methods with AspectJ but the way I implemented it is far from ideal as a mere change in the method signature causes the advice not to be applied.
I could use ACLs with Spring Security but it adds an unnecessary layer of complexity: I just need to grant or reject access to the entities given on whether or not they belong to an account/user.
Can anyone who has already met this issue please provide a clean, flexible and DRY solution?