Class LdapConnectionPoolConfigurer

java.lang.Object
io.micronaut.security.ldap.context.LdapConnectionPoolConfigurer
All Implemented Interfaces:
io.micronaut.context.event.BeanCreatedEventListener<LdapConfiguration>, EventListener

@Internal @Singleton public final class LdapConnectionPoolConfigurer extends Object implements io.micronaut.context.event.BeanCreatedEventListener<LdapConfiguration>
Bounds the JNDI LDAP connection pool for every LdapConfiguration whose manager context is pooled.

The JDK configures its pool with system properties only, read once when the first pooled connection of the JVM is opened, and leaves the pool unbounded by default. This listener runs when an LdapConfiguration bean is created, which precedes the creation of its LdapAuthenticationProvider and therefore the first pooled connection Micronaut Security opens, and, for an enabled configuration, applies LdapConfiguration.ContextConfiguration.PoolConfiguration as the com.sun.jndi.ldap.connect.pool.maxsize, com.sun.jndi.ldap.connect.pool.prefsize and com.sun.jndi.ldap.connect.pool.timeout system properties. A configured value always wins; a value that is not configured keeps a system property that is already set and otherwise falls back to the default.

Since:
5.5.2
Author:
Sergio del Amo
  • Field Details

    • MAX_SIZE_PROPERTY

      public static final String MAX_SIZE_PROPERTY
      System property holding the maximum number of pooled connections per connection identity.
      See Also:
    • PREF_SIZE_PROPERTY

      public static final String PREF_SIZE_PROPERTY
      System property holding the preferred number of pooled connections per connection identity.
      See Also:
    • IDLE_TIMEOUT_PROPERTY

      public static final String IDLE_TIMEOUT_PROPERTY
      System property holding the milliseconds after which an idle pooled connection is closed.
      See Also:
    • CONNECT_TIMEOUT_PROPERTY

      public static final String CONNECT_TIMEOUT_PROPERTY
      JNDI environment property, set on the pooled context itself, holding the milliseconds a context waits for a pooled connection when the pool is saturated and the time allowed to open a new connection. Without it the JDK waits indefinitely.
      See Also:
  • Constructor Details

    • LdapConnectionPoolConfigurer

      public LdapConnectionPoolConfigurer()
  • Method Details

    • applyDefaults

      public static void applyDefaults()
      Applies the default bound to every pool system property that is not set. DefaultContextBuilder calls this before opening a pooled context, so that a pooled context built outside an LdapConfiguration, through ContextBuilder.build(String, String, String, String, boolean), never uses an unbounded pool either. Properties that are already set, by this listener or on the command line, are left untouched.
    • applyConnectTimeout

      public static void applyConnectTimeout(Map<? super String, ? super String> environment, @Nullable Duration connectTimeout)
      Adds the connect timeout of a pooled context to its JNDI environment, unless the environment already sets it.
      Parameters:
      environment - The JNDI environment of a pooled context
      connectTimeout - The configured connect timeout, or null for the default
    • onCreated

      public LdapConfiguration onCreated(io.micronaut.context.event.BeanCreatedEvent<LdapConfiguration> event)
      Specified by:
      onCreated in interface io.micronaut.context.event.BeanCreatedEventListener<LdapConfiguration>