title: Spring Security in conjuction with Spring repositories to secure and authenticate various parts of a website
body: <p>I was looking for a concrete, serious and complete example on how to use Spring security in a Spring Boot application that uses <a href="http://docs.spring.io/spring-data/data-commons/docs/1.6.1.RELEASE/reference/html/repositories.html" rel="nofollow noreferrer">Spring data repositories</a> to access the database and therefore to query about registered users.</p>
  
  <p>I've seen that it's easily protected a range of webpages using Spring security by overriding the <code>configure</code> method, for example with the following options:</p>
  
  <pre><code>http.authorizeRequests()
      .antMatchers("/", "/css/**", "/js/**", "/vendor/**", "/templates/**")
      .permitAll()
      .anyRequest()
      .authenticated()
      .and()
      .formLogin()
      .loginPage("/login")
      .permitAll()
      .and()
      .logout()
      .permitAll();
  </code></pre>
  
  <p>This code protects users for example from accessing <code>http://localhost:3000/home/users/</code>, but allows then to access <code>http://localhost:3000/login</code> or simply <code>http://localhost:3000</code>.</p>
  
  <p>I've been reading around about Spring security, but I can't get how can I protect the different parts of an application, for example, when a user has logged in to the website, and prohibit him from accessing from example <code>http://localhost:3000/home/users/another_user</code>, and in general to control the access of a logged user to all parts of the website.</p>
  
  <p>I'm using <a href="http://docs.spring.io/spring-data/data-commons/docs/1.6.1.RELEASE/reference/html/repositories.html" rel="nofollow noreferrer">Spring data repositories</a> to manipulate data of the database through the entities. </p>
  
  <p>Do you know about an example that uses Spring security in conjunction with Spring repositories (and if necessary other tools) to protect (and authenticate) different parts of a website? A (video-)tutorial may also be useful.</p>
  
  <p>Thanks for any help.</p>
  
  <p>Note: I've looked at the sagan website's repository, but it's quite complex to understand what's going on...</p>