title: GlassFish Security Realm, Active Directory and Referral
body: <p>I've setup up a Security Realm in Glassfish to authenticate against an Active Directory server. The configuration of the realm is as follows:</p>
  
  <pre><code>Class Name: com.sun.enterprise.security.auth.realm.ldap.LDAPRealm
  JAAS context:  ldapRealm
  Directory: ldap://172.16.76.10:389/
  Base DN:  dc=smallbusiness,dc=local
  search-filter: (&amp;(objectClass=user)(sAMAccountName=%s))
  group-search-filter: (&amp;(objectClass=group)(member=%d))
  search-bind-dn: cN=Administrator,CN=Users,dc=smallbusiness,dc=local
  search-bind-password: abcd1234!
  </code></pre>
  
  <p>The realm is functional and I can log-in, but when ever I log in I get the following error in the log:</p>
  
  <pre><code>SEC1106: Error during LDAP search with filter [(&amp;(objectClass=group)(member=CN=Administrator,CN=Users,dc=smallbusiness,dc=local))].
  SEC1000: Caught exception.
      javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name 'dc=smallbusiness,dc=local'
          at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2820)
          ....
          ....
  ldaplm.searcherror
  </code></pre>
  
  <p>While searching for a solution I found that it was recommended to add <code>java.naming.referral=follow</code> to the properties of the realm. However, after I add this it takes 20 minutes for GlassFish to authenticate against Active Directory. I suspect it is a DNS problem on the Active Directory server. The Active Directory server is a vanilla Windows Server 2003 setup in a Virtual Machine.</p>
  
  <p>Any help/recommendation is highly appreciated!</p>