title: Spring LDAP not working with LDAP template
body: <p>I am trying to connect to LDAP server using spring<br />
  The available information about LDAP server is the following:</p>
  <ol>
  <li>host/ip</li>
  <li>port</li>
  <li>domain =&gt; ou=x,dc=y,dc=z<br />
  I don't have any info about the filtration method such as uid = {0} or cn = {0} which matches the username</li>
  </ol>
  <p>Here is my code</p>
  <pre><code>import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.ldap.core.LdapTemplate;
  import org.springframework.ldap.core.support.DefaultDirObjectFactory;
  import org.springframework.ldap.core.support.LdapContextSource;
  
  @Configuration
  public class LdapConfiguration {
      
    @Bean
    public LdapContextSource contextSource() {
        LdapContextSource contextSource = new LdapContextSource();
        contextSource.setUrl(&quot;ldap://ip:port&quot;);
        contextSource.setBase(&quot;dc=y,dc=z&quot;);
        return contextSource;
    }
      
      @Bean
      public LdapTemplate ldapTemplate() {
          LdapTemplate template = new LdapTemplate(contextSource());
      
          return template;
      }
  }
  </code></pre>
  <p>Then in another class here is the authentication method</p>
  <pre><code>@Service
  public class LdapUserServiceImpl implements LdapUserService, BaseLdapNameAware {
  
    @Autowired
    protected LdapTemplate ldapTemplate;
    
    @Autowired
    protected ContextSource contextSource;
  
    @Override
    public Boolean authenticate(String userDn, String credentials) {
  
        AndFilter filter = new AndFilter();
        filter.and(new EqualsFilter(&quot;uid&quot;, userDn));
        boolean authenticated = ldapTemplate.authenticate(LdapUtils.emptyLdapName(), filter.toString(), credentials);
        
        return authenticated;
     }
  }
        
  </code></pre>
  <p>I have got the following error:</p>
  <blockquote>
  <p>m.m.a.ExceptionHandlerExceptionResolver : Resolved
  [org.springframework.ldap.UncategorizedLdapException: Uncategorized
  exception occured during LDAP processing; nested exception is
  javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr:
  DSID-0C090A7D, comment: In order to perform this operation a
  successful bind must be completed on the connection., data 0, v3839</p>
  </blockquote>
  <p>My question is what is the reason for this error, also what can I do if no pattern is known as uid={0} or it is standard<br />
  Also, I tried to put in the ContextSource initialization username and password, although they are assumed not to be available by me</p>
  <pre><code>  contextSource.setUserDn(&quot;uid=username,ou=x,dc=y,dc=z&quot;); 
    contextSource.setPassword(&quot;password&quot;);
  </code></pre>
  <p>This gives me the following error:</p>
  <blockquote>
  <p>[nio-8005-exec-5] .m.m.a.ExceptionHandlerExceptionResolver : Resolved
  [org.springframework.ldap.AuthenticationException: [LDAP: error code
  49 - 80090308: LdapErr: DSID-0C090453, comment: AcceptSecurityContext
  error, data 52e, v3839</p>
  </blockquote>
  <p>In the application.properties file, I put</p>
  <pre><code>spring.ldap.embedded.base-dn=dc=y,dc=z
  spring.ldap.embedded.port=port
  </code></pre>