SonarSource/sonarqube · error · LdapException

When defining multiple LDAP servers with the property '

Error message

When defining multiple LDAP servers with the property '

What it means

When multiple LDAP servers are declared via sonar.authenticator.ldap.servers, every LDAP property must be namespaced under a server key. initMultiLdapConfiguration rejects configurations that still contain top-level properties like ldap.url or ldap.realm, throwing this LdapException to prevent ambiguous configuration.

Source

Thrown at server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/LdapSettingsManager.java:173

      contextFactories = new LinkedHashMap<>();
      String[] serverKeys = config.getStringArray(LDAP_SERVERS_PROPERTY);
      if (serverKeys.length > 0) {
        initMultiLdapConfiguration(serverKeys);
      } else {
        initSimpleLdapConfiguration();
      }
    }
    return contextFactories;
  }

  private void initSimpleLdapConfiguration() {
    LdapContextFactory contextFactory = initLdapContextFactory(LDAP_PROPERTY_PREFIX);
    contextFactories.put(DEFAULT_LDAP_SERVER_KEY, contextFactory);
  }

  private void initMultiLdapConfiguration(String[] serverKeys) {
    if (config.hasKey("ldap.url") || config.hasKey("ldap.realm")) {
      throw new LdapException("When defining multiple LDAP servers with the property '" + LDAP_SERVERS_PROPERTY + "', "
        + "all LDAP properties must be linked to one of those servers. Please remove properties like 'ldap.url', 'ldap.realm', ...");
    }
    for (String serverKey : serverKeys) {
      LdapContextFactory contextFactory = initLdapContextFactory(LDAP_PROPERTY_PREFIX + "." + serverKey);
      contextFactories.put(serverKey, contextFactory);
    }
  }

  private LdapContextFactory initLdapContextFactory(String prefix) {
    String ldapUrlKey = prefix + ".url";
    String ldapUrl = config.get(ldapUrlKey).orElse(null);
    if (StringUtils.isBlank(ldapUrl)) {
      throw new LdapException(String.format(MANDATORY_LDAP_PROPERTY_ERROR, ldapUrlKey));
    }
    return new LdapContextFactory(config, prefix, ldapUrl);
  }

}

View on GitHub (pinned to 184c821202)

Solutions

  1. Remove the top-level sonar.authenticator.ldap.url / ldap.realm properties.
  2. Move every LDAP property under a server key prefix: sonar.authenticator.ldap.<serverKey>.url, .realm, etc.
  3. Audit sonar.properties (and any included config) for any remaining un-namespaced ldap.* sonar.authenticator properties.

Example fix

// before: mixed config
sonar.authenticator.ldap.servers: server1,server2
sonar.authenticator.ldap.url: ldap://ldap.example.com
// after: fully namespaced
sonar.authenticator.ldap.servers: server1,server2
sonar.authenticator.ldap.server1.url: ldap://ldap1.example.com
sonar.authenticator.ldap.server2.url: ldap://ldap2.example.com
Defensive patterns

Strategy: validation

Validate before calling

if (config.hasKey("sonar.authenticator.ldap.servers") &&
    (config.hasKey("sonar.authenticator.ldap.url") || config.hasKey("sonar.authenticator.ldap.realm"))) {
  throw new IllegalStateException("Remove top-level ldap.url/ldap.realm; namespace all properties under server keys");
}

Prevention

When it happens

Trigger: Setting sonar.authenticator.ldap.servers to multiple keys while also defining sonar.authenticator.ldap.url or sonar.authenticator.ldap.realm (top-level, un-namespaced properties).

Common situations: Upgrading from single-server to multi-server config without moving old top-level properties under server keys; copy-pasting sample configs that mix both styles; leftover defaults in sonar.properties.

Related errors


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