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

**Reproduction line:**
`./gradlew ':x-pack:qa:third-party:active-directory:test' --tests "org.elasticsearch.xpack.security.authc.ldap.GroupMappingIT.testGroupMapping" -Dtests.seed=D51FD3E394A6008D -Dtests.locale=es-GT -Dtests.timezone=Europe/Sarajevo -Druntime.java=17`

**Applicable branches:**
master

**Reproduces locally?:**
No

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

**Failure excerpt:**
```
org.elasticsearch.ElasticsearchSecurityException: unable to authenticate user [odin] for action [indices:data/write/index]

  at __randomizedtesting.SeedInfo.seed([D51FD3E394A6008D:9718CF59E5601BBC]:0)
  at org.elasticsearch.xpack.core.security.support.Exceptions.authenticationError(Exceptions.java:20)
  at org.elasticsearch.xpack.core.security.authc.DefaultAuthenticationFailureHandler.createAuthenticationError(DefaultAuthenticationFailureHandler.java:186)
  at org.elasticsearch.xpack.core.security.authc.DefaultAuthenticationFailureHandler.failedAuthentication(DefaultAuthenticationFailureHandler.java:106)
  at org.elasticsearch.xpack.security.authc.AuthenticationService$AuditableTransportRequest.authenticationFailed(AuthenticationService.java:332)
  at org.elasticsearch.xpack.security.authc.RealmsAuthenticator.consumeNullUser(RealmsAuthenticator.java:269)
  at org.elasticsearch.xpack.security.authc.RealmsAuthenticator.lambda$consumeToken$3(RealmsAuthenticator.java:212)
  at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:136)
  at org.elasticsearch.action.support.ContextPreservingActionListener.onResponse(ContextPreservingActionListener.java:31)
  at org.elasticsearch.xpack.core.common.IteratingActionListener.onResponse(IteratingActionListener.java:132)
  at org.elasticsearch.xpack.security.authc.RealmsAuthenticator.lambda$consumeToken$0(RealmsAuthenticator.java:190)
  at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:136)
  at org.elasticsearch.xpack.security.authc.support.CachingUsernamePasswordRealm.lambda$authenticateWithCache$3(CachingUsernamePasswordRealm.java:221)
  at org.elasticsearch.action.ActionListener$1.onResponse(ActionListener.java:136)
  at org.elasticsearch.xpack.security.authc.ldap.LdapRealm$LdapSessionActionListener.onFailure(LdapRealm.java:308)
  at org.elasticsearch.action.support.ContextPreservingActionListener.onFailure(ContextPreservingActionListener.java:38)
  at org.elasticsearch.xpack.security.authc.ldap.ActiveDirectorySessionFactory.lambda$getSessionWithoutPool$2(ActiveDirectorySessionFactory.java:163)
  at org.elasticsearch.action.ActionListener$1.onFailure(ActionListener.java:144)
  at org.elasticsearch.action.ActionRunnable.onFailure(ActionRunnable.java:77)
  at org.elasticsearch.xpack.security.authc.ldap.support.LdapUtils$2.onFailure(LdapUtils.java:204)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:28)
  at org.elasticsearch.xpack.security.authc.ldap.support.LdapUtils.maybeForkAndRun(LdapUtils.java:102)
  at org.elasticsearch.xpack.security.authc.ldap.support.LdapUtils.maybeForkThenBind(LdapUtils.java:212)
  at org.elasticsearch.xpack.security.authc.ldap.ActiveDirectorySessionFactory$ADAuthenticator.authenticate(ActiveDirectorySessionFactory.java:320)
  at org.elasticsearch.xpack.security.authc.ldap.ActiveDirectorySessionFactory.getSessionWithoutPool(ActiveDirectorySessionFactory.java:161)
  at org.elasticsearch.xpack.security.authc.ldap.PoolingSessionFactory.session(PoolingSessionFactory.java:110)
  at org.elasticsearch.xpack.security.authc.ldap.LdapRealm.lambda$doAuthenticate$1(LdapRealm.java:147)
  at org.elasticsearch.xpack.security.authc.ldap.LdapRealm$CancellableLdapRunnable.doRun(LdapRealm.java:343)
  at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:776)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  at java.lang.Thread.run(Thread.java:833)

```
x-pack/qa/third-party/active-directory/src/test/java/org/elasticsearch/xpack/security/authc/ldap/AbstractAdLdapRealmTestCase.java
protected void assertAccessAllowed(String user, String index) throws IOException {
        Client client = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, userHeader(user, PASSWORD)));
        IndexResponse indexResponse = client.prepareIndex(index)
            .setSource(jsonBuilder().startObject().field("name", "value").endObject())
            .execute()
            .actionGet();
        assertEquals(
            "user " + user + " should have write access to index " + index,
            DocWriteResponse.Result.CREATED,
            indexResponse.getResult()
        );
        refresh();
        GetResponse getResponse = client.prepareGet(index, indexResponse.getId()).get();
        assertThat("user " + user + " should have read access to index " + index, getResponse.getId(), equalTo(indexResponse.getId()));
    }
    protected void assertAccessDenied(String user, String index) throws IOException {
        try {
            client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, userHeader(user, PASSWORD)))
                .prepareIndex(index)
                .setSource(jsonBuilder().startObject().field("name", "value").endObject())
                .execute()
                .actionGet();
            fail("Write access to index " + index + " should not be allowed for user " + user);
        } catch (ElasticsearchSecurityException e) {
            
        }
        refresh();
    }
    protected static String userHeader(String username, String password) {
        return UsernamePasswordToken.basicAuthHeaderValue(username, new SecureString(password.toCharArray()));