title: How to Secure Spring Rest Services with Spring Sercurity and Angularjs?
body: <p>I have a Spring MVC Server Backend with Rest-Services and an AngularJS WebFrontend.</p>
  
  <p>i want to secure my spring mvc rest services but i want use java config.. and i have no idea how the configuration mus look like. Can someone help me with this ?
  The only good implementation i have found is this : <a href="https://github.com/philipsorst/angular-rest-springsecurity" rel="nofollow">https://github.com/philipsorst/angular-rest-springsecurity</a></p>
  
  <p>I use a postgrsDB and i wand store username and password and roles there, is the session token in the example from <a href="https://github.com/philipsorst/angular-rest-springsecurity" rel="nofollow">https://github.com/philipsorst/angular-rest-springsecurity</a> only stored in cache and not in the db ?</p>
  
  <p>At the moment i have a simple form login security, this was only for testing, but i did not use jsp i use only the spring mvc rest services and angularjs as webfrontend.. How can i modify my spring security code that it works with oauth2 like in the example from <a href="https://github.com/philipsorst/angular-rest-springsecurity" rel="nofollow">https://github.com/philipsorst/angular-rest-springsecurity</a> ? I have at the moment only this two classes from spring security..</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter{
  
      @Override
      public void configure(AuthenticationManagerBuilder auth) throws Exception {
  
          auth
          .inMemoryAuthentication()
          .withUser("username").password("test").roles("User");
      }
  }
  </code></pre>
  
  <p>and then i register the securityConfig in my WebInitializer.</p>
  
  <pre><code>public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
  @Override
  protected Class&lt;?&gt;[] getRootConfigClasses() {
      return new Class&lt;?&gt;[]{ PersistenceContext.class,AppConfig.class,SecurityConfig.class }; 
  } ....
  </code></pre>
  
  <p>But the roles and username/password should stored in a database.. must i use a special databse schema for spring security to store username,password and roles in my db ?</p>
  
  <p>And can i implement it so that i can only add the @Secured Annotation(or any other Annotation) over one of my rest services with the role in it ? Like @Secured("UserRole")</p>
  
  <p>Or ist Basic Authentification easier ? can i secure my rest services with basic authentification with rolemanagement !? if so we can use basic authentification..
  Best regards</p>