title: Error authenticating with LDAP in Spring Boot Reason: [LDAP: error code 50 - Insufficient Access Rights]
body: <p>I am trying to make a validation page with spring boot that validates user that exists in an LDAP server. My code is this: </p>
  
  <pre><code>import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.authentication.encoding.LdapShaPasswordEncoder;
  import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
  import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
  
  import java.util.Arrays;
  
  @Configuration
  @EnableGlobalMethodSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http
          .authorizeRequests()
          .anyRequest().fullyAuthenticated()
          .and()
          .formLogin();
  }
  
  @Override
  public void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth
          .ldapAuthentication()
          .userSearchBase("ou=people")
          .userSearchFilter("(cn={0})")
          .contextSource(contextSource())
          .passwordCompare()
          .passwordAttribute("userPassword");
  }
  
  @Bean
  public DefaultSpringSecurityContextSource contextSource(){
      return new DefaultSpringSecurityContextSource(Arrays.asList("ldap://localhost:389"),"dc=myCompany,dc=org");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The problem is that I am getting the following error and I don't seem to understand where it is coming from. </p>
  
  <blockquote>
    <p>Reason: [LDAP: error code 50 - Insufficient Access Rights]; nested exception is javax.naming.NoPermissionException: [LDAP: error code 50 - Insufficient Access Rights]; remaining name 'cn=nameEntered,ou=people'</p>
  </blockquote>
  
  <p>Any help would helpful. </p>