title: LDAP: Empty binddn"" and Authentication type becomes simple from none
body: <p>Am Developing an application in Spring MVC &amp; JPA with Spring Security. Now Integrating the OUD (Oracle Unified Directory) through LDAP. While User authentication the response from the LDAP in OUD log file is</p>
  
  <p><strong>CONNECT</strong> conn=909681 from ******* to *******:1636 protocol=LDAPS</p>
  
  <p><strong>Bind REQ</strong> conn=909681 op=0 msgID=1 <strong>type=SIMPLE dn=""</strong> version=3</p>
  
  <p><strong>BindRES</strong> conn=909681 op=0 msgID=1 result=1 message="The directory server could not find a network group for the bind dn "" because the client connection does not match the connection criteria for any network groups."</p>
  
  <p><strong>DISCONNECT</strong> conn=909681 reason="Client Disconnect"</p>
  
  <p>Mapping between application and LDAP in security.xml file</p>
  
  <pre><code>&lt;bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"&gt;
      &lt;constructor-arg value="ldaps://192.168.0.182:1636/o=company"/&gt;
      &lt;property name="userDn" value="cn=userid,o=company,ou=groups"/&gt;
      &lt;property name="password" value="password"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="ldapAuthProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider" &gt;
       &lt;constructor-arg&gt;
            &lt;bean class="in.web.service.impl.CustomLdapBindAuthenticator"&gt;
                 &lt;constructor-arg ref="contextSource"/&gt;
                 &lt;property name="userDnPatterns"&gt;
                     &lt;list&gt;
                         &lt;value&gt;cn={0},ou=groups&lt;/value&gt;
                     &lt;/list&gt;
                 &lt;/property&gt;
             &lt;/bean&gt;
       &lt;/constructor-arg&gt;
       &lt;constructor-arg&gt;
             &lt;bean class="in.web.service.impl.CustomLdapUserAuthoritiesPopulator"&gt;
             &lt;/bean&gt;
       &lt;/constructor-arg&gt;     
   &lt;/bean&gt;
  </code></pre>
  
  <p>Code in CustomLdapBindAuthenticator</p>
  
  <pre><code>public LdapUserDetails search(String cn) throws Exception {
          Hashtable env = new Hashtable();
          String sp = "com.sun.jndi.ldap.LdapCtxFactory";
          env.put(Context.INITIAL_CONTEXT_FACTORY, sp);
  
          String [] urls = contextSource.getUrls();
          for(String url: urls){
              System.out.println("ldapurls="+url);
          }
          env.put(Context.PROVIDER_URL, urls[0]);
  
          DirContext dctx = new InitialDirContext(env);
  
          String base = "ou=groups,o=company";
          System.out.println("BASE DN="+base);
  
          SearchControls sc = new SearchControls();
          String[] attributeFilter = {"cn", "fullName", "mail", "l", "mobile"};
          sc.setReturningAttributes(attributeFilter);
          sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
  
          String filter = "(&amp;(cn="+cn+")(objectClass=*))";
  
          NamingEnumeration results = dctx.search(base, filter, sc);
          LdapUserDetails user = new LdapUserDetails();
          while (results.hasMore()) {
              SearchResult sr = (SearchResult) results.next();
              Attributes attrs = sr.getAttributes();
  
              user.setCn(getAttribute(attrs, "cn"));
              user.setFullName(getAttribute(attrs, "fullName"));
              user.setMail(getAttribute(attrs, "mail"));
              user.setMobile(getAttribute(attrs, "mobile"));
              user.setLocation(getAttribute(attrs, "l")); 
          }
          dctx.close();
          return user;
          }
  </code></pre>
  
  <p>Pl. Help me to solve the issues</p>
  
  <ol>
  <li>I didn't mention the authentication as simple. From where i am getting <strong>type=simple</strong> in log file</li>
  <li>Why I am getting dn=""</li>
  </ol>
  
  <p>Thanks in advance</p>