title: Spring boot REST service with multiple users
body: <p>First of all, I spent some time thinking whether this question belongs to SO, so if you think it is more appropriate for some other Stack Exchange site, please feel free to recommend or migrate.</p>
  
  <p>I am writing a REST application which will be able to register new users and allow the existing users to interact with each other (you can imagine a forum or a minimalistic social network, for example).</p>
  
  <p>At the moment, I have a simple app setup with database schema, <strong>spring-JPA</strong> and <strong>spring-data-rest</strong> exposing all the repositories.</p>
  
  <p>However, all users are now able to access all the resources from the server. I would like a user to see only his own entities: for example by going to <code>/api/user/messages</code>.</p>
  
  <p>I am also going to use some security in the application, probably OAuth2, so I need it to be compatible.</p>
  
  <p>I have read some articles and SO questions concerning this topic and decided that <strong>multi-tenancy</strong> might be a solution to my problem. Usually though, these articles work with separate databases for each client and smaller number of clients in total so I am curious whether it is actually meant to be used for a huge number of users in the system. I expect all the users to share the database with their records and use the same schema.</p>
  
  <p>Is there some tutorial for this topic concerning spring boot and shared database-schema? Or is there some better approach how to solve this problem? I would be glad for any tips!</p>
  
  <p>EDIT: As pointed out in the comments, using multi-tenancy might be an overkill for this task, since I only need to separate the users on entity level. I would be glad for any hint how to do that in Spring boot and JPA since I have found no tutorials concerning this topic.</p>