java.lang.Object
org.elasticsearch.xpack.security.authc.ldap.support.SessionFactory
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
LdapSessionFactory

public abstract class SessionFactory extends Object implements Closeable
This factory holds settings needed for authenticating to LDAP and creating LdapConnections. Each created LdapConnection needs to be closed or else connections will pill up consuming resources.

A standard looking usage pattern could look like this:

 ConnectionFactory factory = ...
 try (LdapConnection session = factory.session(...)) {
 ...do stuff with the session
 }
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.elasticsearch.xpack.core.security.authc.RealmConfig
     
    protected final boolean
     
    protected final org.apache.logging.log4j.Logger
     
    protected final LdapMetadataResolver
     
    protected final com.unboundid.ldap.sdk.ServerSet
     
    protected final org.elasticsearch.xpack.core.ssl.SSLService
     
    protected final boolean
     
    protected final org.elasticsearch.threadpool.ThreadPool
     
    protected final org.elasticsearch.core.TimeValue
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    SessionFactory(org.elasticsearch.xpack.core.security.authc.RealmConfig config, org.elasticsearch.xpack.core.ssl.SSLService sslService, org.elasticsearch.threadpool.ThreadPool threadPool)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected static com.unboundid.ldap.sdk.LDAPConnectionOptions
    connectionOptions(org.elasticsearch.xpack.core.security.authc.RealmConfig config, org.elasticsearch.xpack.core.ssl.SSLService sslService, org.apache.logging.log4j.Logger logger)
     
    protected List<String>
    getDefaultLdapUrls(org.elasticsearch.xpack.core.security.authc.RealmConfig config)
     
    boolean
     
    abstract void
    session(String user, org.elasticsearch.common.settings.SecureString password, org.elasticsearch.action.ActionListener<LdapSession> listener)
    Authenticates the given user and opens a new connection that bound to it (meaning, all operations under the returned connection will be executed on behalf of the authenticated user.
    boolean
    Returns a flag to indicate if this session factory supports unauthenticated sessions.
    void
    unauthenticatedSession(String username, org.elasticsearch.action.ActionListener<LdapSession> listener)
    Returns an LdapSession for the user identified by the String parameter

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      protected final org.apache.logging.log4j.Logger logger
    • config

      protected final org.elasticsearch.xpack.core.security.authc.RealmConfig config
    • timeout

      protected final org.elasticsearch.core.TimeValue timeout
    • sslService

      protected final org.elasticsearch.xpack.core.ssl.SSLService sslService
    • threadPool

      protected final org.elasticsearch.threadpool.ThreadPool threadPool
    • serverSet

      protected final com.unboundid.ldap.sdk.ServerSet serverSet
    • sslUsed

      protected final boolean sslUsed
    • ignoreReferralErrors

      protected final boolean ignoreReferralErrors
    • metadataResolver

      protected final LdapMetadataResolver metadataResolver
  • Constructor Details

    • SessionFactory

      protected SessionFactory(org.elasticsearch.xpack.core.security.authc.RealmConfig config, org.elasticsearch.xpack.core.ssl.SSLService sslService, org.elasticsearch.threadpool.ThreadPool threadPool)
  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • session

      public abstract void session(String user, org.elasticsearch.common.settings.SecureString password, org.elasticsearch.action.ActionListener<LdapSession> listener)
      Authenticates the given user and opens a new connection that bound to it (meaning, all operations under the returned connection will be executed on behalf of the authenticated user.
      Parameters:
      user - The name of the user to authenticate the connection with.
      password - The password of the user
      listener - the listener to call on a failure or result
    • supportsUnauthenticatedSession

      public boolean supportsUnauthenticatedSession()
      Returns a flag to indicate if this session factory supports unauthenticated sessions. This means that a session can be established without providing any credentials in a call to unauthenticatedSession(String, ActionListener)
      Returns:
      true if the factory supports unauthenticated sessions
    • unauthenticatedSession

      public void unauthenticatedSession(String username, org.elasticsearch.action.ActionListener<LdapSession> listener)
      Returns an LdapSession for the user identified by the String parameter
      Parameters:
      username - the identifier for the user
      listener - the listener to call on a failure or result
    • connectionOptions

      protected static com.unboundid.ldap.sdk.LDAPConnectionOptions connectionOptions(org.elasticsearch.xpack.core.security.authc.RealmConfig config, org.elasticsearch.xpack.core.ssl.SSLService sslService, org.apache.logging.log4j.Logger logger)
    • getDefaultLdapUrls

      protected List<String> getDefaultLdapUrls(org.elasticsearch.xpack.core.security.authc.RealmConfig config)
    • isSslUsed

      public boolean isSslUsed()