title: Http basic authentication using ldap credentials in spring security(spring-boot project) to secure rest service calls
body: <p>Using Spring Security
  Basic authentication setup works against some hardcoded username passwords as shown here:</p>
  
  <p><a href="http://thoughtfulsoftware.wordpress.com/2013/12/08/adding-security-to-spring-guides-rest-service/" rel="nofollow">http://thoughtfulsoftware.wordpress.com/2013/12/08/adding-security-to-spring-guides-rest-service/</a></p>
  
  <p>So trying to extend it to use LDAP.</p>
  
  <p>Completed the set up for LDAP authentication with our LDAP server</p>
  
  <p>Now when I try to call my rest service through REST Console plug-in an authorization window keeps on popping up for username password. If I cancel it authorization fails, not sure where I am going wrong</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(securedEnabled = true)
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  @Override
      protected void configure(HttpSecurity http) throws Exception {http
          .authorizeRequests()
              .anyRequest().authenticated()
              .and()
              .csrf().disable()
          .httpBasic();
  
  
      @Override
      protected void configure(AuthenticationManagerBuilder authManagerBuilder) throws Exception {
          authManagerBuilder
              .ldapAuthentication()
              .userSearchFilter("(uid={0})").userSearchBase("ou=people,dc=zzz,dc=xxxx,dc=yyy")
              .groupRoleAttribute("cn").groupSearchFilter("(member={0})")
                  //.userDnPatterns("uid={0},ou=people")
                  //.groupSearchBase("ou=groups")
                  .contextSource().url("ldaps://ldap.xxxx.yyy:636/cn=cw-grpreader,ou=people,dc=xxx,dc=xxxx,dc=xxx")
                  .managerDn("cn=xx-xxr,ou=people,dc=med,dc=xxxx,dc=xxx")
                  .managerPassword("#$%^^");
      }
  </code></pre>
  
  <p>This is one way I tried which give the recurring authentication popup
  if I cancel the popup I get
  HTTP Status 401 - [LDAP: error code 49 - NDS error: failed authentication (-669)]; error even if the credentials are correct
  Link to some tutorial will be really helpful</p>