title: API key Authentication with spring security in spring data rest api
body: <p>Am using spring-data-rest for developing my API and I have to use spring security to authenticate a request. When I pass a authentication details, I have to generate an API+secret key and store it in client side and sent with all further requests from that subject. And have to check it in every request and if they logout I have to regenerate key when they login again. I have implemented security as like this,</p>
  
  <pre><code>import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  
  @EnableWebSecurity
  @Configuration
  public class SecurityConfig extends WebSecurityConfigurerAdapter{
  
  
      @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception{
          auth.inMemoryAuthentication()
              .withUser("test").password("test").roles("test");
      }
  
      @Override protected void configure(HttpSecurity http) throws Exception{
          http.authorizeRequests()
              .antMatchers("/**").hasRole("test")
              .anyRequest().anonymous()
              .and()
              .httpBasic()
              .and()
              .csrf()
              .disable();
      }
  
  }
  </code></pre>
  
  <p>and registered filter via java config.</p>
  
  <p>and I have look at this <a href="http://www.objectpartners.com/2011/06/16/implementing-rest-authentication/" rel="nofollow">tutorial</a> which is exactly the same am looking for. I am not good with spring and so I need to know whether am moving correctly.</p>
  
  <p>Am going to implement facebook login and no registration in my site, everyone will login with facebook to access site or my app. So i wont have password too. Guide me in a proper way that how I could progress to achieve this. Thanks in advance.</p>