SonarSource/sonarqube · error · LdapException

Unable to retrieve details for user

Error message

Unable to retrieve details for user <username> in <serverKey>

What it means

getUserDetails wraps any NamingException from the user detail search (findUnique) in this LdapException. It means the LDAP operation to fetch email/realName attributes for the user failed at the directory level. A user simply not found returns null instead — this error means an actual directory/protocol failure. The cause is attached and logged at debug.

Solutions

  1. Enable debug logging to inspect the wrapped NamingException for the exact failure (CommunicationException, AuthenticationException, NameNotFoundException...).
  2. Test connectivity and bind with ldapsearch -H <ldap.url> -D <bindDn> -w <password>.
  3. Fix sonar.authenticator.ldap.url / user.baseDn configuration as indicated by the cause.
  4. Check SSL certificate trust for ldaps:// endpoints.

Example fix

// before: unreachable server
sonar.authenticator.ldap.url: ldap://old-dc.example.com:389
// after: reachable controller
sonar.authenticator.ldap.url: ldap://dc1.example.com:389
Defensive patterns

Strategy: try-catch

Try / catch

try {
  details = provider.getUserDetails(username, serverKey);
} catch (LdapException e) {
  LOG.error("LDAP lookup failure for {} on {}: cause={}", username, serverKey, e.getCause(), e);
  throw e; // authentication should fail closed on directory outage
}

Prevention

When it happens

Trigger: getUserDetails with a findUnique() search that throws NamingException — invalid bind credentials, wrong user.baseDn, connection refused to ldap.url, communication exception (timeout), or attribute-read ACL denial.

Common situations: Expired bind password; firewall/network changes blocking port 389/636; certificate trust failure on ldaps://; AD domain controller outage; baseDn pointing at a nonexistent OU.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/89227d7cd825c71f. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/DefaultLdapUsersProvider.java:89

      LOG.debug(errorMessage);
      throw new LdapException(errorMessage);
    }
    SearchResult searchResult;
    try {
      searchResult = ldapUserMapping.createSearch(contextFactories.get(serverKey), username)
        .returns(ldapUserMapping.getEmailAttribute(), ldapUserMapping.getRealNameAttribute())
        .findUnique();

      if (searchResult != null) {
        return mapUserDetails(ldapUserMapping, searchResult);
      } else {
        LOG.debug("User {} not found in {}", username, serverKey);
        return null;
      }
    } catch (NamingException e) {
      // just in case if Sonar silently swallowed exception
      LOG.debug(e.getMessage(), e);
      throw new LdapException("Unable to retrieve details for user " + username + " in " + serverKey, e);
    }
  }

  private static LdapUserDetails mapUserDetails(LdapUserMapping ldapUserMapping, SearchResult searchResult) throws NamingException {
    Attributes attributes = searchResult.getAttributes();
    LdapUserDetails details;
    details = new LdapUserDetails();
    details.setName(getAttributeValue(attributes.get(ldapUserMapping.getRealNameAttribute())));
    details.setEmail(getAttributeValue(attributes.get(ldapUserMapping.getEmailAttribute())));
    return details;
  }

}

View on GitHub (pinned to 184c821202)