SonarSource/sonarqube · error · LdapException

Unable to retrieve details for user %s and server key %s: No

Error message

Unable to retrieve details for user %s and server key %s: No user mapping found.

What it means

getUserDetails looks up the LdapUserMapping for the requested server key; if none exists it throws this LdapException. It guards the case where multi-LDAP configuration defines servers but the given serverKey has no sonar.authenticator.ldap.<serverKey>.user.* mapping. This is a configuration error thrown before any LDAP call.

Source

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

  }

  @Override
  public LdapUserDetails doGetUserDetails(Context context) {
    return getUserDetails(context.serverKey(), context.username());
  }

  /**
   * @return details for specified user, or null if such user doesn't exist
   * @throws LdapException if unable to retrieve details
   */
  private LdapUserDetails getUserDetails(String serverKey, String username) {
    LOG.debug("Requesting details for user {}", username);
    // If there are no userMappings available, we can not retrieve user details.
    LdapUserMapping ldapUserMapping = userMappings.get(serverKey);
    if (ldapUserMapping == null) {
      String errorMessage = format("Unable to retrieve details for user %s and server key %s: No user mapping found.", username, serverKey);
      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);
    }

View on GitHub (pinned to 184c821202)

Solutions

  1. Add user mapping properties for every server key listed in sonar.authenticator.ldap.servers: sonar.authenticator.ldap.<key>.user.baseDn, .request, .emailAttribute, .realNameAttribute.
  2. Verify the serverKey spelling matches exactly the key used in sonar.authenticator.ldap.servers.
  3. If single-server, drop the multi-server config and use the plain sonar.authenticator.ldap.* prefix.

Example fix

// before: servers lists two keys but only one has user mapping
sonar.authenticator.ldap.servers: server1,server2
sonar.authenticator.ldap.server1.user.baseDn: ou=users,dc=example,dc=org
// after: map both
sonar.authenticator.ldap.server2.user.baseDn: ou=people,dc=other,dc=org
Defensive patterns

Strategy: validation

Validate before calling

// every server in servers must have a user mapping
String[] keys = config.get("sonar.authenticator.ldap.servers").split(",");
for (String key : keys) {
  if (!config.hasKey("sonar.authenticator.ldap." + key + ".user.baseDn")) {
    throw new IllegalStateException("Missing user mapping for server key: " + key);
  }
}

Try / catch

try {
  details = provider.getUserDetails(username, serverKey);
} catch (LdapException e) {
  if (e.getMessage().contains("No user mapping found")) {
    throw new IllegalStateException("Fix config: add sonar.authenticator.ldap." + serverKey + ".user.*", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getUserDetails (via doGetUserDetails) with a serverKey (e.g. from a multi-server setup) for which userMappings.get(serverKey) returns null — the server has no user mapping configured.

Common situations: Multi-LDAP setups where sonar.authenticator.ldap.servers lists a key but corresponding sonar.authenticator.ldap.<key>.user.baseDn etc. were never set; server key typo (case-sensitive mismatch); partially migrated single-server configs.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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