public static LoginManager acquireLoginManager(JaasContext jaasContext, String saslMechanism,
                                                   Class<? extends Login> defaultLoginClass,
                                                   Map<String, ?> configs) throws LoginException {
        Class<? extends Login> loginClass = configuredClassOrDefault(configs, jaasContext,
                saslMechanism, SaslConfigs.SASL_LOGIN_CLASS, defaultLoginClass);
        Class<? extends AuthenticateCallbackHandler> defaultLoginCallbackHandlerClass = OAuthBearerLoginModule.OAUTHBEARER_MECHANISM
                .equals(saslMechanism) ? OAuthBearerUnsecuredLoginCallbackHandler.class
                        : AbstractLogin.DefaultLoginCallbackHandler.class;
        Class<? extends AuthenticateCallbackHandler> loginCallbackClass = configuredClassOrDefault(configs, jaasContext,
                saslMechanism, SaslConfigs.SASL_LOGIN_CALLBACK_HANDLER_CLASS, defaultLoginCallbackHandlerClass);
        synchronized (LoginManager.class) {
            LoginManager loginManager;
            Password jaasConfigValue = jaasContext.dynamicJaasConfig();
            if (jaasConfigValue != null) {
                LoginMetadata<Password> loginMetadata = new LoginMetadata<>(jaasConfigValue, loginClass, loginCallbackClass, configs);
                loginManager = DYNAMIC_INSTANCES.get(loginMetadata);
                if (loginManager == null) {
                    loginManager = new LoginManager(jaasContext, saslMechanism, configs, loginMetadata);
                    DYNAMIC_INSTANCES.put(loginMetadata, loginManager);
                }
            } else {
                LoginMetadata<String> loginMetadata = new LoginMetadata<>(jaasContext.name(), loginClass, loginCallbackClass, configs);
                loginManager = STATIC_INSTANCES.get(loginMetadata);
                if (loginManager == null) {
                    loginManager = new LoginManager(jaasContext, saslMechanism, configs, loginMetadata);
                    STATIC_INSTANCES.put(loginMetadata, loginManager);
                }
            }
            SecurityUtils.addConfiguredSecurityProviders(configs);
            return loginManager.acquire();
        }
    }
Returns an instance of `LoginManager` and increases its reference count.

`release()` should be invoked when the `LoginManager` is no longer needed. This method will try to reuse an
existing `LoginManager` for the provided context type. If `jaasContext` was loaded from a dynamic config,
login managers are reused for the same dynamic config value. For `jaasContext` loaded from static JAAS
configuration, login managers are reused for static contexts with the same login context name.

This is a bit ugly and it would be nicer if we could pass the `LoginManager` to `ChannelBuilders.create` and
shut it down when the broker or clients are closed. It's straightforward to do the former, but it's more
complicated to do the latter without making the consumer API more complex.

@param jaasContext Static or dynamic JAAS context. `jaasContext.dynamicJaasConfig()` is non-null for dynamic context.
                   For static contexts, this may contain multiple login modules if the context type is SERVER.
                   For CLIENT static contexts and dynamic contexts of CLIENT and SERVER, `jaasContext` contains
                   only one login module.
@param saslMechanism SASL mechanism for which login manager is being acquired. For dynamic contexts, the single
                     login module in `jaasContext` corresponds to this SASL mechanism. Hence `Login` class is
                     chosen based on this mechanism.
@param defaultLoginClass Default login class to use if an override is not specified in `configs`
@param configs Config options used to configure `Login` if a new login manager is created.
clients/src/main/java/org/apache/kafka/common/security/authenticator/LoginManager.java