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

**Reproduction line:**
`./gradlew ':x-pack:qa:third-party:active-directory:test' --tests "org.elasticsearch.xpack.security.authc.ldap.MultiGroupMappingIT.testGroupMapping" -Dtests.seed=6F6F32CBCD52E4DD -Dtests.locale=de-CH -Dtests.timezone=America/Anguilla -Druntime.java=17`

**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.MultiGroupMappingIT&tests.test=testGroupMapping

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

  at __randomizedtesting.SeedInfo.seed([6F6F32CBCD52E4DD:2D682E71BC94FFEC]: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:214)
  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:192)
  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.LdapSessionFactory$1.onFailure(LdapSessionFactory.java:105)
  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.LdapSessionFactory$1.loop(LdapSessionFactory.java:115)
  at org.elasticsearch.xpack.security.authc.ldap.LdapSessionFactory.session(LdapSessionFactory.java:117)
  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
public static void cleanupRealm() {
        realmConfig = null;
    }
    @Override
    protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
        final RealmConfig realm = AbstractAdLdapRealmTestCase.realmConfig;
        Settings.Builder builder = Settings.builder();
        builder.put(super.nodeSettings(nodeOrdinal, otherSettings), true);
        builder.put(buildRealmSettings(realm, roleMappings, getNodeTrustedCertificates()));
        return builder.build();
    }
    protected Settings buildRealmSettings(
        RealmConfig realm,
        List<RoleMappingEntry> roleMappingEntries,
        List<String> certificateAuthorities
    ) {
        Settings.Builder builder = Settings.builder();
        builder.put(realm.buildSettings(certificateAuthorities));
        configureFileRoleMappings(builder, realm.type, roleMappingEntries);
        return builder.build();
    }
    @Before
    public void setupRoleMappings() throws Exception {
        assertSecurityIndexActive();
        List<String> content = getRoleMappingContent(RoleMappingEntry::nativeContent);
        if (content.isEmpty()) {
            return;
        }
        Map<String, ActionFuture<PutRoleMappingResponse>> futures = Maps.newLinkedHashMapWithExpectedSize(content.size());
        for (int i = 0; i < content.size(); i++) {