title: LDAP Authentication Error
body: <p>Im getting an error in grails when trying to use LDAP authentication to find a user using AD authentication. This is the code I have from the grails side:</p>
  
  <pre><code>@Override
      public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
          ArrayList&lt;String&gt; roles=new ArrayList&lt;String&gt;(2);
          roles.add("ROLE_USER");
          try {
              GldapoSchemaClassForUser.findAll( directory: "user", filter: "(userPrincipalName=${username})" ).each{ user -&gt;
              def userName = user.cn
              user.memberOf.each{ groupListing -&gt;
              String groupName=groupListing.substring(3, groupListing.indexOf(','));
              if (groupName.equals("Admin")) {
                  roles.add("ROLE_ADMIN");
              } else if (groupName.equals("User")) {
                  // Do nothing
              }
          } catch (Throwable e) {
              System.err.println(e.getMessage())
          }
          return new User(username)
      }
  </code></pre>
  
  <p>It hits the catch block when it tries to access this line above: </p>
  
  <blockquote>
    <p>GldapoSchemaClassForUser.findAll( directory: "user", filter:
    "(userPrincipalName=${username})" )</p>
  </blockquote>
  
  <p>showing this error message:</p>
  
  <blockquote>
    <p>org.springframework.ldap.AuthenticationException: [LDAP: error code 49
    - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 525, vece</p>
  </blockquote>
  
  <p>According to documentation this error suggests that a 525 error means an invalid user but I have tested using an LDAP explorer tool and it connects to the user fine with the same details.</p>
  
  <p>In the app-config file I have the following ldap settings: </p>
  
  <ul>
  <li>ldap.directories.user.url=ldap://sbs.testsbs.local</li>
  <li>ldap.directories.user.base=OU=staff,DC=skills,DC=local</li>
  <li>ldap.directories.user.userDn=OU=staff,DC=skills,DC=local</li>
  <li>ldap.directories.user.password=Pa55w0rd</li>
  </ul>
  
  <p>Does anyone have any ideas as to what I am doing wrong? </p>