title: How to configure spring to use External LDAP Server
body: <p>I am learning about Spring Security to LDAP server, right now i am trying to make spring authenticate to ldap server. However, spring always uses the embedded server  <code>ldap://127.0.0.1:33389/dc=springframework,dc=org</code> instead of my <code>ldap://localhost:389/dc=localdomain,dc=local</code>. I'm trying to configure it using <code>application.properties</code> See below my spring configuration.</p>
  
  <p>WebSecurityConfig.java</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      private static final Logger logger = LoggerFactory.getLogger(WebSecurityConfig.class);
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          logger.info("Loading Global Auth Configuration");
           auth
              .ldapAuthentication();
  
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          logger.info("Configuring HTTP Security.");
          // Configure Web Security
          http
              .csrf().disable()
              .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
              .and()
              .authorizeRequests()
              .antMatchers("/auth/**").permitAll()
              .anyRequest().authenticated();
  
          // disable page caching
          http.headers().cacheControl();
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          logger.info("Configuring Web Security HTTP Security.");
          // AuthenticationTokenFilter will ignore the below paths
          web
              .ignoring()
              .antMatchers(
                  HttpMethod.POST,
                  "/auth"
              );
      }
  }
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>#Ldap Info
  spring.ldap.urls=ldap://localhost:389
  spring.ldap.anonymous-read-only=true
  spring.ldap.username=ldapadm
  spring.ldap.password=root123
  spring.ldap.base=ou=People,dc=localdomain,dc=local
  </code></pre>
  
  <p>Tried using above <code>application.properties</code>, still does not work. </p>
  
  <p>application.properties</p>
  
  <pre><code>#Ldap Info
  ldap.urls=ldap://localhost:389
  ldap.base.dn=dc=localdomain,dc=local
  ldap.username=cn=ldapadm,dc=localdomain,dc=local
  ldap.password=root123
  ldap.user.dn.pattern =uid={0}
  </code></pre>
  
  <p>I also tried above properties, still does not work.</p>
  
  <pre><code>2018-09-04 00:05:31.515  INFO 9948 --- [           main] s.s.l.DefaultSpringSecurityContextSource :  URL 'ldap://127.0.0.1:33389/dc=springframework,dc=org', root DN is 'dc=springframework,dc=org'
  2018-09-04 00:05:31.516  INFO 9948 --- [           main] o.s.l.c.support.AbstractContextSource    : Property 'userDn' not set - anonymous context will be used for read-write operations
  2018-09-04 00:05:31.523  WARN 9948 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: Could not postProcess org.springframework.security.ldap.authentication.BindAuthenticator@3bc735b3 of type class org.springframework.security.ldap.authentication.BindAuthenticator
  2018-09-04 00:05:31.526  INFO 9948 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
  </code></pre>
  
  <p>for both settings in <code>application.properties</code>, i always get this on my server log</p>
  
  <p>Can anyone make sense of these? i am trying to make it read the <code>application.properties</code> but it always uses the embedded ldap in spring</p>