I use Spring Data Rest with Spring Data Mongo.
I have a rather simple REST API which looks similar to this:
public class User {
String id;
String email;
String password;
List<String> roles;
}
public class UserData {
String data;
User user;
}
@PreAuthorize("hasRole('ROLE_USER')")
public interface QueryTemplateRepository extends
MongoRepository<UserData, String> {
}
What I want now is that users can only access their data and if they create/edit data it will be linked to their account.
Do I have to get rid of the MongoRepository and write everything myself? Is there some kind of interceptor or filter where I can do this?
I will want to create more REST APIs that are restricted to the user's data, so it would be great if there was some generic solution to this problem.