title: Spring LDAP: InvalidNameException: /: [LDAP: error code 34
body: <p>I am getting following exception while authenticating a user:</p>
  
  <p>If I use values in applicationContext  like this:</p>
  
  <pre><code>&lt;property name="url" value="ldap://10.10.10.10:389/DC=lab2,DC=ins" /&gt;
  &lt;property name="base" value="DC=lab2,DC=ins" /&gt;
  &lt;property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" /&gt;
  </code></pre>
  
  <p>Exception will be:</p>
  
  <pre><code>Exception in thread "main" org.springframework.ldap.InvalidNameException: /: [LDAP: error code 34 - 0000208F: NameErr: DSID-031001BA, problem 2006 (BAD_NAME), data 8349, best match of:
      'DC=lab2,DC=ins/dc=lab2,dc=ins'
  </code></pre>
  
  <p>else if application context like this:</p>
  
  <pre><code>&lt;property name="url" value="ldap://10.10.10.10:389" /&gt;
  &lt;property name="base" value="DC=lab2,DC=ins" /&gt;
  &lt;property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" /&gt;
  </code></pre>
  
  <p>Exception will be:</p>
  
  <pre><code>Exception in thread "main" org.springframework.ldap.PartialResultException: nested exception is javax.naming.PartialResultException [Root exception is javax.naming.CommunicationException: lab2.ins:389 [Root exception is java.net.UnknownHostException: lab2.ins]]
      at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:205)
  </code></pre>
  
  <p>Authenticate method:</p>
  
  <pre><code>public boolean authenticate(String userName, String password) {
      AndFilter filter = new AndFilter();
      filter.and(new EqualsFilter("objectclass", "person")).and(
                  new EqualsFilter("sAMAccountName", userName));
      return ldapTemplate.authenticate(DistinguishedName.EMPTY_PATH, filter
                  .toString(), password);
  }
  </code></pre>
  
  <p>Applicationcontext.xml</p>
  
  <pre><code>&lt;bean id="contextSource"
          class="org.springframework.ldap.core.support.LdapContextSource"&gt;
      &lt;property name="url" value="ldap://10.10.10.10:389" /&gt;
      &lt;property name="base" value="DC=lab2,DC=ins" /&gt;
      &lt;property name="userDn" value="CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins" /&gt;
      &lt;property name="password" value="secret" /&gt;
      &lt;property name="baseEnvironmentProperties"&gt;
          &lt;map&gt;
              &lt;entry key="java.naming.referral"&gt;
                  &lt;value&gt;follow&lt;/value&gt;
              &lt;/entry&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"&gt;
      &lt;constructor-arg ref="contextSource" /&gt;
  &lt;/bean&gt;
  &lt;bean id="ldapContact"
          class="ldap.ContactLDAP "&gt;
      &lt;property name="ldapTemplate" ref="ldapTemplate" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>testClass:</p>
  
  <pre><code>Resource r = new ClassPathResource("applicationContext.xml");
  BeanFactory factory = new XmlBeanFactory(r);
  ContactLDAP contact = (ContactLDAP) factory.getBean("ldapContact"); 
  
  System.out.println(contact.authenticate("username", "secret"));
  </code></pre>
  
  <p>What am I missing here?</p>