title: How to properly configure ldap authentication in spring boot? Every time I log in, it redirects to /login after calling /auth
body: <p><strong>NOTE</strong>
  Suggested answer didn't work.</p>
  
  <p>I have the following configuration in WebSecurityConfigurerAdapter:</p>
  
  <pre><code>@Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.ldapAuthentication()
              .userSearchBase("somevalue")
              .userSearchFilter("somevalue")
              .contextSource().url("somevalue").port("somevalue")
              .managerDn("somevalue").managerPassword("somevalue");
  }
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http.authorizeRequests()
              .antMatchers("/*.css", "/*.html", "/*.js", "/*.jpg").permitAll()
              .anyRequest().authenticated()
              .and()
              .formLogin().loginPage("/login")
              .loginProcessingUrl("/auth")
              .permitAll();
  }
  </code></pre>
  
  <p>And this is my configuration in WebMvcConfigurer:</p>
  
  <pre><code>@Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/*.css", "/*.html", "/*.js", "/*.jpg")
              .addResourceLocations("classpath:/static/");
  
      registry.addResourceHandler("/", "/login", "/myapp")
              .addResourceLocations("classpath:/static/index.html")
              .resourceChain(true)
              .addResolver(new PathResourceResolver() {
                  @Override
                  protected Resource getResource(String resourcePath, Resource location) {
                      if (resourcePath.startsWith("/api") || resourcePath.startsWith("/api".substring(1))) {
                          return null;
                      }
                      return location.exists() &amp;&amp; location.isReadable() ? location : null;
                  }
              });
  }
  </code></pre>
  
  <p>WHen I click on login button I send the following request in angular:</p>
  
  <pre><code>this.http.post(`localhost:8080/auth`, {username: 'user', password: 'password'})...
  </code></pre>
  
  <p>But I only got redirected to /login.  Here's the network console:</p>
  
  <pre><code>auth                        302
  login                       200
  </code></pre>
  
  <p>Here's the request (/auth) headers and body:</p>
  
  <pre><code>Accept: application/json, text/plain, */*
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9
  Connection: keep-alive
  Content-Length: 47
  Content-Type: application/json
  Cookie: JSESSIONID=*****somecookie*****
  Host: localhost:8080
  Origin: http://localhost:8080
  Referer: http://localhost:8080/login
  </code></pre>
  
  <p>Payload:</p>
  
  <pre><code>{username: "user", password: "password"}
  </code></pre>
  
  <p>General:</p>
  
  <pre><code>Request URL: http://localhost:8080/auth
  Request Method: POST
  Status Code: 302 
  Remote Address: [::1]:8080
  Referrer Policy: no-referrer-when-downgrade
  </code></pre>
  
  <p>Response headers:</p>
  
  <pre><code>Cache-Control: no-cache, no-store, max-age=0, must-revalidate
  Content-Length: 0
  Date: Fri, 01 Mar 2019 10:49:09 GMT
  Expires: 0
  Location: http://localhost:8080/login
  Pragma: no-cache
  X-Content-Type-Options: nosniff
  X-Frame-Options: DENY
  X-XSS-Protection: 1; mode=block
  </code></pre>
  
  <p>And here's when it redirects to /login:</p>
  
  <p>General:</p>
  
  <pre><code>Request URL: http://localhost:8080/login
  Request Method: GET
  Status Code: 200 
  Remote Address: [::1]:8080
  Referrer Policy: no-referrer-when-downgrade
  </code></pre>
  
  <p>Request:</p>
  
  <pre><code>Accept: application/json, text/plain, */*
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9
  Connection: keep-alive
  Cookie: JSESSIONID=*****somecookie*****
  Host: localhost:8080
  Referer: http://localhost:8080/login
  </code></pre>
  
  <p>Basically, the response body is the content of my index.html.</p>
  
  <p>And in the console it says:</p>
  
  <pre><code>error: {error: SyntaxError: Unexpected token &lt; in JSON at position 0 at JSON.parse...
  headers: e {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
  message: "Http failure during parsing for http://localhost:8080/login"
  name: "HttpErrorResponse"
  ok: false
  status: 200
  statusText: "OK"
  url: "http://localhost:8080/login"
  </code></pre>
  
  <p>Also, is my ldap config correct?
  How to properly configure for ldap authentication?</p>
  
  <p><strong>UPDATE</strong>
  As per recommendation, I changed my code to send the body as http params.  The request is now this:</p>
  
  <p>Request Headers:
  <code>Content-Type: application/x-www.form-urlencoded;charset=UTF-8</code></p>
  
  <p>Form Data
  <code>username=user&amp;password=password</code></p>
  
  <p>It still the same issue</p>