title: Authenticating using LDAP with spring LDAP API and without using spring security
body: <p>I am using spring-ldap-core plugin in my Sprint boot application. 
  Basically, the LDAPTemplate - <a href="http://docs.spring.io/spring-ldap/docs/current/apidocs/org/springframework/ldap/core/LdapTemplate.html" rel="nofollow">http://docs.spring.io/spring-ldap/docs/current/apidocs/org/springframework/ldap/core/LdapTemplate.html</a></p>
  
  <p>I basically want to convert the xml configuration below into java using Spring LDAP API and want to avoid using spring security. </p>
  
  <p>The xml configuration that I want to convert is - </p>
  
  <pre><code> &lt;ldap-server id="ldapServer"
                   url="ldap://ad.company.com:389"
                   manager-dn="CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com"
                   manager-password="password"/&gt;
  
      &lt;authentication-manager&gt;
          &lt;ldap-authentication-provider
                  server-ref="ldapServer"
                  user-search-base="dc=ad,dc=company,dc=com"
                  user-search-filter="sAMAccountName={0}"
                  group-search-filter="member={0}"
                  group-search-base="ou=Groups,dc=ad,dc=company,dc=com"
                  group-role-attribute="cn"/&gt;
      &lt;/authentication-manager&gt;
  </code></pre>
  
  <p>Here is my java code below- </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.LdapContextSource;
  import org.springframework.ldap.authentication.DefaultValuesAuthenticationSourceDecorator;
  
  @Configuration
  public class LdapConfiguration {
  
      @Bean
      public LdapContextSource contextSource(){
          LdapContextSource contextSource = new LdapContextSource();
  
          contextSource.setUrl("ldap://ad.company.com:389");
          contextSource.setBase("DC=ad,DC=company,DC=com");
          contextSource.setUserDn("CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com");
          contextSource.setPassword("password");
          contextSource.afterPropertiesSet();
          return contextSource;
      }
  
  
      @Bean
      public LdapTemplate ldapTemplate(){
  
          LdapTemplate template = new LdapTemplate(contextSource());
          try {
              template.afterPropertiesSet();
          } catch (Exception e) {
              e.printStackTrace();
          }
          return template;
      }
  }
  </code></pre>
  
  <p>This is how I am trying to invoke authentication - 
  The method that this snippet is a part of returns a boolean value if authentication happens</p>
  
  <pre><code> AndFilter filter = new AndFilter();
  
      filter.and(new EqualsFilter("sAMAccountName", userloginName));
  
      return ldapTemplate.authenticate("OU=Service Accounts", filter.encode(), userPassword);
  </code></pre>
  
  <p>This is not working and the error I get is that :</p>
  
  <pre><code>No results found for search, base: 'OU=Service Accounts'; filter: '(sAMAccountName=usernameIinput)'.
  </code></pre>
  
  <p>I want to know how the following xml properties can be configured using LDAP API?</p>
  
  <pre><code>group-search-filter="member={0}"
  group-search-base="ou=Groups,dc=ad,dc=company,dc=com"
  group-role-attribute="cn"/&gt;
  </code></pre>
  
  <p>Also, what else am I missing? Why is this not working?
  Any help will be really appreciated!</p>