title: SpringBoot/JPA - data row level authorization
body: <p>I'm looking for a way to authorize access based on ROLES and DATA CONTENT (table row) using Spring Boot &amp; JPA</p>
  <p>The use case is the following:</p>
  <pre><code>Given a User with a Role 'ROLE_AAA'
  When user fetches data from table 'REPORT'
  Then only reports with specific 'REPORT_ROLE' association will be returned
  </code></pre>
  <p><strong>ER</strong></p>
  <p>Table: role</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>ROLE</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>ROLE_AAA</td>
  </tr>
  <tr>
  <td>2</td>
  <td>ROLE_BBB</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Table: report</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>CONTENT</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>...</td>
  </tr>
  <tr>
  <td>2</td>
  <td>...</td>
  </tr>
  <tr>
  <td>3</td>
  <td>...</td>
  </tr>
  <tr>
  <td>4</td>
  <td>...</td>
  </tr>
  <tr>
  <td>5</td>
  <td>...</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Table: report_roles</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>REPORT_ID</th>
  <th>ROLE_ID</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>1</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2</td>
  </tr>
  <tr>
  <td>4</td>
  <td>2</td>
  </tr>
  <tr>
  <td>5</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>In this case a user with role ROLE_AAA will get reports with ID 1,2 &amp; 5 only.</p>
  <pre><code>SELECT re.*
  FROM report re
  JOIN report_role rr
  ON re.id = rr.report_id
  JOIN role ro
  ON ro.id = rr.role_id
  WHERE ro.name = 'ROLE_AAA'
  </code></pre>
  <p>I could easily write queries (@org.springframework.data.jpa.repository.Query) joining on table I want to get data from, with the association role table, but I feel I'm missing a JPA or Spring Security feature that might offer it out off the box.</p>
  <p>Any design/implementation suggestion will be very appreciated.</p>
  <p><strong>UPDATE</strong></p>
  <p>Since returns will be paginated (<code>retuning Page&lt;Object&gt; from JPARepository</code>), I believe PostFiltering is not an option here.</p>