{"record":{"id":"5dc78dad9c0440e8","repo":"SonarSource/sonarqube","slug":"when-defining-multiple-ldap-servers-with-the-prope","errorCode":null,"errorMessage":"When defining multiple LDAP servers with the property '","messagePattern":"When defining multiple LDAP servers with the property '","errorType":"validation","errorClass":"LdapException","httpStatus":null,"severity":"error","filePath":"server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/LdapSettingsManager.java","lineNumber":173,"sourceCode":"      contextFactories = new LinkedHashMap<>();\n      String[] serverKeys = config.getStringArray(LDAP_SERVERS_PROPERTY);\n      if (serverKeys.length > 0) {\n        initMultiLdapConfiguration(serverKeys);\n      } else {\n        initSimpleLdapConfiguration();\n      }\n    }\n    return contextFactories;\n  }\n\n  private void initSimpleLdapConfiguration() {\n    LdapContextFactory contextFactory = initLdapContextFactory(LDAP_PROPERTY_PREFIX);\n    contextFactories.put(DEFAULT_LDAP_SERVER_KEY, contextFactory);\n  }\n\n  private void initMultiLdapConfiguration(String[] serverKeys) {\n    if (config.hasKey(\"ldap.url\") || config.hasKey(\"ldap.realm\")) {\n      throw new LdapException(\"When defining multiple LDAP servers with the property '\" + LDAP_SERVERS_PROPERTY + \"', \"\n        + \"all LDAP properties must be linked to one of those servers. Please remove properties like 'ldap.url', 'ldap.realm', ...\");\n    }\n    for (String serverKey : serverKeys) {\n      LdapContextFactory contextFactory = initLdapContextFactory(LDAP_PROPERTY_PREFIX + \".\" + serverKey);\n      contextFactories.put(serverKey, contextFactory);\n    }\n  }\n\n  private LdapContextFactory initLdapContextFactory(String prefix) {\n    String ldapUrlKey = prefix + \".url\";\n    String ldapUrl = config.get(ldapUrlKey).orElse(null);\n    if (StringUtils.isBlank(ldapUrl)) {\n      throw new LdapException(String.format(MANDATORY_LDAP_PROPERTY_ERROR, ldapUrlKey));\n    }\n    return new LdapContextFactory(config, prefix, ldapUrl);\n  }\n\n}","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/LdapSettingsManager.java#L155-L191","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Remove the top-level sonar.authenticator.ldap.url / ldap.realm properties.","Move every LDAP property under a server key prefix: sonar.authenticator.ldap.<serverKey>.url, .realm, etc.","Audit sonar.properties (and any included config) for any remaining un-namespaced ldap.* sonar.authenticator properties."],"exampleFix":"// before: mixed config\nsonar.authenticator.ldap.servers: server1,server2\nsonar.authenticator.ldap.url: ldap://ldap.example.com\n// after: fully namespaced\nsonar.authenticator.ldap.servers: server1,server2\nsonar.authenticator.ldap.server1.url: ldap://ldap1.example.com\nsonar.authenticator.ldap.server2.url: ldap://ldap2.example.com","handlingStrategy":"validation","validationCode":"if (config.hasKey(\"sonar.authenticator.ldap.servers\") &&\n    (config.hasKey(\"sonar.authenticator.ldap.url\") || config.hasKey(\"sonar.authenticator.ldap.realm\"))) {\n  throw new IllegalStateException(\"Remove top-level ldap.url/ldap.realm; namespace all properties under server keys\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When migrating to multi-server, script the rename of all top-level ldap.* properties to <serverKey>.* form.","Grep sonar.properties for stray sonar.authenticator.ldap.url after enabling ldap.servers."],"tags":["ldap","configuration","multi-server","conflicting-options"],"backgroundTag":"conflicting-config-options","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}