**Build scan:**
https://gradle-enterprise.elastic.co/s/lbk5ynxsss7ym/tests/:x-pack:qa:third-party:active-directory:test/org.elasticsearch.xpack.security.authc.ldap.ActiveDirectoryGroupsResolverTests/testResolveSubTree

**Reproduction line:**
`./gradlew ':x-pack:qa:third-party:active-directory:test' --tests "org.elasticsearch.xpack.security.authc.ldap.ActiveDirectoryGroupsResolverTests.testResolveSubTree" -Dtests.seed=B75C7A14E63A1ABB -Dtests.locale=is-IS -Dtests.timezone=Australia/Adelaide -Druntime.java=18`

**Applicable branches:**
master

**Reproduces locally?:**
Didn't try

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.xpack.security.authc.ldap.ActiveDirectoryGroupsResolverTests&tests.test=testResolveSubTree

**Failure excerpt:**
```
com.unboundid.ldap.sdk.LDAPException: A client-side timeout was encountered while waiting 5005ms for a response to simple bind request with message ID 1 for user 'cn=Bruce Banner,CN=Users,DC=ad,DC=test,DC=elasticsearch,DC=com' from server localhost:49182.

  at __randomizedtesting.SeedInfo.seed([B75C7A14E63A1ABB:3CE0D99C8300612D]:0)
  at com.unboundid.ldap.sdk.SimpleBindRequest.handleResponse(SimpleBindRequest.java:738)
  at com.unboundid.ldap.sdk.SimpleBindRequest.process(SimpleBindRequest.java:619)
  at com.unboundid.ldap.sdk.LDAPConnection.processBindOperation(LDAPConnection.java:4560)
  at com.unboundid.ldap.sdk.LDAPConnection.bind(LDAPConnection.java:2393)
  at com.unboundid.ldap.sdk.LDAPConnection.<init>(LDAPConnection.java:700)
  at org.elasticsearch.xpack.security.authc.ldap.LdapTestUtils.lambda$openConnection$0(LdapTestUtils.java:60)
  at java.security.AccessController.doPrivileged(AccessController.java:569)
  at org.elasticsearch.xpack.security.authc.ldap.support.LdapUtils.privilegedConnect(LdapUtils.java:76)
  at org.elasticsearch.xpack.security.authc.ldap.LdapTestUtils.openConnection(LdapTestUtils.java:55)
  at org.elasticsearch.xpack.security.authc.ldap.GroupsResolverTestCase.setUpLdapConnection(GroupsResolverTestCase.java:58)
  at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
  at java.lang.reflect.Method.invoke(Method.java:577)
  at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1758)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$9.evaluate(RandomizedRunner.java:980)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$10.evaluate(RandomizedRunner.java:996)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleSetupTeardownChained$1.evaluate(TestRuleSetupTeardownChained.java:44)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at org.apache.lucene.tests.util.TestRuleThreadAndTestName$1.evaluate(TestRuleThreadAndTestName.java:45)
  at org.apache.lucene.tests.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:60)
  at org.apache.lucene.tests.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:44)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:375)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl.forkTimeoutingTask(ThreadLeakControl.java:824)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$3.evaluate(ThreadLeakControl.java:475)
  at com.carrotsearch.randomizedtesting.RandomizedRunner.runSingleTest(RandomizedRunner.java:955)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$5.evaluate(RandomizedRunner.java:840)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$6.evaluate(RandomizedRunner.java:891)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$7.evaluate(RandomizedRunner.java:902)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:38)
  at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
  at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:53)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at org.apache.lucene.tests.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:44)
  at org.apache.lucene.tests.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:60)
  at org.apache.lucene.tests.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:47)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:375)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl.lambda$forkTimeoutingTask$0(ThreadLeakControl.java:831)
  at java.lang.Thread.run(Thread.java:833)

```
x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapTestUtils.java
builder.put("xpack.security.authc.realms.ldap.foo.ssl.truststore.path", truststore);
        builder.put("xpack.security.authc.realms.ldap.foo.ssl.verification_mode", SslVerificationMode.FULL);
        builder.put("xpack.security.authc.realms.ldap.bar.ssl.truststore.path", truststore);
        builder.put("xpack.security.authc.realms.ldap.bar.ssl.verification_mode", SslVerificationMode.CERTIFICATE);
        secureSettings.setString("xpack.security.authc.realms.ldap.foo.ssl.truststore.secure_password", "changeit");
        secureSettings.setString("xpack.security.authc.realms.ldap.bar.ssl.truststore.secure_password", "changeit");
        Settings settings = builder.build();
        Environment env = TestEnvironment.newEnvironment(settings);
        SSLService sslService = new SSLService(env);
        LDAPURL ldapurl = new LDAPURL(url);
        LDAPConnectionOptions options = new LDAPConnectionOptions();
        options.setFollowReferrals(true);
        options.setAllowConcurrentSocketFactoryUse(true);
        options.setConnectTimeoutMillis(Math.toIntExact(SessionFactorySettings.TIMEOUT_DEFAULT.millis()));
        options.setResponseTimeoutMillis(SessionFactorySettings.TIMEOUT_DEFAULT.millis());
        final SslConfiguration sslConfiguration = sslService.getSSLConfiguration("xpack.security.authc.realms.ldap.foo.ssl");
        return LdapUtils.privilegedConnect(
            () -> new LDAPConnection(
                sslService.sslSocketFactory(sslConfiguration),
                options,
                ldapurl.getHost(),
                ldapurl.getPort(),
                bindDN,
                bindPassword
            )
        );
    }
}