# Sonarqube not switching quickly to second ldap Server

**URL:** <https://community.sonarsource.com/t/sonarqube-not-switching-quickly-to-second-ldap-server/127588>\
**Category:** SonarQube Server / Community Build\
**Tags:** ldap, sonarqube\
**Created:** [October 8, 2024, 9:01am UTC](https://community.sonarsource.com/t/sonarqube-not-switching-quickly-to-second-ldap-server/127588 "2024-10-08T09:01:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Inugami-Sayo](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/inugami-sayo/32/62822_2.png) [@Inugami-Sayo](https://community.sonarsource.com/u/Inugami-Sayo)\
**Post date:** [October 8, 2024, 9:01am UTC](https://community.sonarsource.com/t/sonarqube-not-switching-quickly-to-second-ldap-server/127588/1 "2024-10-08T09:01:02Z")

</div>

Hi all,

I am using two LDAP servers (xxxx.xxxx.xxxx.x / yyyy.yyyy.yyyy.y), and currently, xxxx.xxxx.xxxx.x is linked to SonarQube and running.  
I am trying to improve the setup so that if xxxx.xxxx.xxxx.x goes down, LDAP authentication will be performed through yyyy.yyyy.yyyy.y.  
Both xxxx.xxxx.xxxx.x and yyyy.yyyy.yyyy.y contain the same AD information.

After adding the above configuration to \<SONARQUBE\_HOME\>/conf/sonar.properties, I started SonarQube, and both servers showed ‘test OK’ in the SonarQube logs.

```auto
...
ldap.servers=default,sub
ldap.default.url=ldap://xxxx.xxxx.xxxx.x
...
ldap.sub.url=ldap://yyyy.yyyy.yyyy.y
...

```

```auto
2024.10.03 15:xx:xx INFO web[][o.s.a.l.LdapContextFactory] Test LDAP connection on ldap://xxxx.xxxx.xxxx.x: OK
2024.10.03 15:xx:xx INFO web[][o.s.a.l.LdapContextFactory] Test LDAP connection on ldap://yyyy.yyyy.yyyy.y: OK

```

After that, I tested whether it would switch to yyyy.yyyy.yyyy.y and perform authentication by cutting off communication between the Container running SonarQube and xxxx.xxxx.xxxx.x.  
However, it took more than 10 minutes for the authentication to fail on xxxx.xxxx.xxxx.x, and during that time, the Web UI displayed a 504 error.  
it seems that the LDAP authentication is proceeding in the background, as it eventually results in a ‘login success’.

```auto
2024.10.03 15:20:16 DEBUG web[<hidden>][o.s.a.l.LdapContextFactory] Initializing LDAP context {java.naming.referral=follow, java.naming.security.principal=CN= ****,OU=**** ,OU= ****,DC=**** ,DC= **** , com.sun.jndi.ldap.connect.pool=true, java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory, java.naming.provider.url=ldap://xxxx.xxxx.xxxx.x, java.naming.security.authentication=simple}
2024.10.03 15:33:30 DEBUG web[<hidden>][o.s.a.l.DefaultLdapAuthenticator] User u12345 not found in server <default>: javax.naming.NamingException: LDAP connection has been closed; remaining name 'OU= ****,OU=**** ,DC= ****,DC=****'
2024.10.03 15:33:30 DEBUG web[<hidden>][o.s.a.l.LdapSearch] Search: LdapSearch{baseDn=OU= ****,OU=**** ,DC= ****,DC=**** , scope=subtree, request=(&(objectClass=user)(sAMAccountName={0})), parameters=[u12345], attributes=null}
2024.10.03 15:33:16 DEBUG web[<hidden>][o.s.a.l.LdapContextFactory] Initializing LDAP context {java.naming.referral=follow, java.naming.security.principal=CN= ****,OU=**** ,OU= ****,DC=**** ,DC= **** , com.sun.jndi.ldap.connect.pool=true, java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory, java.naming.provider.url=ldap://yyyy.yyyy.yyyy.y, java.naming.security.authentication=simple}
++++++++++
2024.10.03 15:33:16 DEBUG web[<hidden>][auth.event] login success[method|BASIC][provider|REALM|ldap][IP| ****.****. ****.**** | ****.****. ****.**** , ****.****. ****.****][login|u12345] 

```

Is it possible to change the timeout duration for LDAP authentication failure within SonarQube?

(Additional note:

- Due to project circumstances, I am unable to transfer the logs, so I am picking out only the necessary logs.
- Since the LDAP is managed by a different organization, I am unable to make any changes to the LDAP server settings.
- This post is translated by deepl.)

# sonarqube version

versions: sonarqube 9.9.0 community  
SonarQube deployed: Docker compose

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [October 8, 2024, 9:01am UTC](https://community.sonarsource.com/t/sonarqube-not-switching-quickly-to-second-ldap-server/127588/2 "2024-10-08T09:01:39Z")

</div>

Hey there.

Check this thread:

> [@Authentication with redundant ldap servers](https://community.sonarsource.com/t/authentication-with-redundant-ldap-servers/117846/4):
>
> Hello @sopraf, Thanks for the report. SonarQube’s LDAP support is not designed to connect to multiple LDAP servers in a failover mode. Instead, the feature is designed to allow companies with different LDAP servers hosting different users to allow users of both LDAPs to connect. For security reasons, the user provisioned via LDAP server 2 must always connect with the same LDAP server. Otherwise, this would allow people to create a matching user on LDAP server 1 and potentially impersonate the…

---

<div class="post-metadata">

**Author:** ![Inugami-Sayo](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/inugami-sayo/32/62822_2.png) [@Inugami-Sayo](https://community.sonarsource.com/u/Inugami-Sayo)\
**Post date:** [October 8, 2024, 9:08am UTC](https://community.sonarsource.com/t/sonarqube-not-switching-quickly-to-second-ldap-server/127588/3 "2024-10-08T09:08:19Z")

</div>

Hello. Thank you for your prompt reply.

I have already checked this thread and I understand that sonarqube is not designed to connect to multiple LDAP servers in a failover model.

I understand that using a reverse proxy, as mentioned in this post, can solve the problem,  
Do you have any documentation that you could share that would be helpful?

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [October 8, 2024, 9:09am UTC](https://community.sonarsource.com/t/sonarqube-not-switching-quickly-to-second-ldap-server/127588/4 "2024-10-08T09:09:35Z")

</div>

I have no specific advice. Googling “[2 LDAP servers behind proxy](https://www.google.com/search?q=2+LDAP+servers+behind+proxy)” has some promising results.

[https://www.reddit.com/r/PFSENSE/comments/nfsayn/how\_to\_set\_multiple\_ldap\_servers\_on\_ha\_proxy/](https://www.reddit.com/r/PFSENSE/comments/nfsayn/how_to_set_multiple_ldap_servers_on_ha_proxy/)

---

<div class="post-metadata">

**Author:** ![Inugami-Sayo](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/inugami-sayo/32/62822_2.png) [@Inugami-Sayo](https://community.sonarsource.com/u/Inugami-Sayo)\
**Post date:** [October 8, 2024, 9:16am UTC](https://community.sonarsource.com/t/sonarqube-not-switching-quickly-to-second-ldap-server/127588/5 "2024-10-08T09:16:22Z")

</div>

Thank you for your reply.  
I’ll take a look at these posts for reference.
