title: angular 2 login with spring security
body: <p>im trying to integrate spring security with a custom angular 2 login, that is a specific endpoint of my app is protected with spring security, trying to access it will redirect to /login that is handled in angular 2. as things stands now i have no clue as to how to perform the login and grant access to the backend API once logged.</p>
  
  <p>i am configuring spring security as follows:</p>
  
  <pre><code>@Override
  protected void configure(final HttpSecurity http) throws Exception {
      http
          .csrf().disable()
          .cors().and()
          .authorizeRequests()
          .antMatchers("/api/someEndpoint/**")
          .hasRole(ADMIN_ROLE).and().formLogin()
          .loginPage("/login").and().logout();
  }
  
  
  @Override
  protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
      auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
  }
  </code></pre>
  
  <p>as I had the default login everything worked fine, but I have found myself unable to create a working angular 2 login integration.
  I tried the following code in angular 2 to no avail:</p>
  
  <pre><code>login(loginDetails:Object) {
      console.log(loginDetails)
      const headers = new Headers({ 'Content-Type': 'application/json' });
  const options = new RequestOptions({ headers: headers });
  const body = JSON.stringify(loginDetails);
      console.log(headers);
      console.log(body);
  return this.http.post(this.loginUrl, body, options) 
  }
  </code></pre>
  
  <p>as far as I know spring security defaults for username and password variable names are "username" and "password", which i am sure are being passed in the request body so when passing some invalid user data like <code>{"username":"admin", "password" : "pass"}</code>I should be redirected to /login?error or something, and when successfully authenticated I should be redirected to /welcome and stay authenticated</p>
  
  <p>I have the user and pass defined in my db and my custom userDetailsService checks against it
   any answers, comments or questions are welcome</p>