SonarSource/sonarqube · error · LdapException
Unable to retrieve details for user <username> in <serverKey
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.
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)
Solutions
- Enable debug logging to inspect the wrapped NamingException for the exact failure (CommunicationException, AuthenticationException, NameNotFoundException...).
- Test connectivity and bind with ldapsearch -H <ldap.url> -D <bindDn> -w <password>.
- Fix sonar.authenticator.ldap.url / user.baseDn configuration as indicated by the cause.
- 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
- Test bind credentials and URL with ldapsearch before each SonarQube upgrade.
- Import ldaps certificates into the JVM truststore proactively.
- Watch for expired service-account passwords; rotate with monitoring.
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
- Unable to retrieve groups for user %s in server with key <%s
- Unable to open LDAP connection
- Callback not supported
- Unable to retrieve details for user %s: No user or group map
- Unable to retrieve details for user %s and server key %s: No
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/89227d7cd825c71f.
Report an issue: GitHub.