Class LdapNetworkConnector<C>

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.util.net.NetworkConnector
org.apache.sshd.ldap.LdapNetworkConnector<C>
Type Parameters:
C - Type of context being passed to resolveAttributes(String, String, Object)
Direct Known Subclasses:
LdapAuthenticator

public class LdapNetworkConnector<C> extends org.apache.sshd.common.util.net.NetworkConnector
  • Field Details

    • DEFAULT_LDAP_PROTOCOL

      public static final String DEFAULT_LDAP_PROTOCOL
      See Also:
    • DEFAULT_LDAP_PORT

      public static final int DEFAULT_LDAP_PORT
      See Also:
    • DEFAULT_LDAP_FACTORY_PROPNAME

      public static final String DEFAULT_LDAP_FACTORY_PROPNAME
      Property used to override the default LDAP context factory class
      See Also:
    • DEFAULT_LDAP_FACTORY_PROPVAL

      public static final String DEFAULT_LDAP_FACTORY_PROPVAL
      Default LDAP context factory class - unless overridden via the DEFAULT_LDAP_FACTORY_PROPNAME property
      See Also:
    • DEFAULT_LDAP_SEARCH_SCOPE

      public static final int DEFAULT_LDAP_SEARCH_SCOPE
      See Also:
    • DEFAULT_LDAP_TIME_LIMIT

      public static final long DEFAULT_LDAP_TIME_LIMIT
    • DEFAULT_LDAP_REFERRAL_MODE

      public static final String DEFAULT_LDAP_REFERRAL_MODE
      See Also:
    • DEFAULT_LDAP_COUNT_LIMIT

      public static final long DEFAULT_LDAP_COUNT_LIMIT
      See Also:
    • DEFAULT_LDAP_DEREF_ENABLED

      public static final boolean DEFAULT_LDAP_DEREF_ENABLED
      See Also:
    • ALL_LDAP_ATTRIBUTES

      public static final String ALL_LDAP_ATTRIBUTES
      A special value used to indicate that all attributes are required
      See Also:
    • DEFAULT_LDAP_RETURN_OBJVALUE

      public static final boolean DEFAULT_LDAP_RETURN_OBJVALUE
      See Also:
    • DEFAULT_LDAP_ACCUMULATE_MULTIVALUES

      public static final boolean DEFAULT_LDAP_ACCUMULATE_MULTIVALUES
      See Also:
    • DEFAULT_LDAP_BIND_DN_PATTERN

      public static final String DEFAULT_LDAP_BIND_DN_PATTERN
      See Also:
    • DEFAULT_LDAP_BIND_PASSWORD_PATTERN

      public static final String DEFAULT_LDAP_BIND_PASSWORD_PATTERN
      See Also:
    • DEFAULT_BINARY_ATTRIBUTES

      public static final String DEFAULT_BINARY_ATTRIBUTES
      A list of known binary attributes
      See Also:
    • searchControls

      protected final SearchControls searchControls
    • ldapEnv

      protected final Map<String,Object> ldapEnv
    • bindDNPattern

      protected MessageFormat bindDNPattern
    • bindPasswordPattern

      protected MessageFormat bindPasswordPattern
    • searchFilterPattern

      protected MessageFormat searchFilterPattern
    • baseDNPattern

      protected MessageFormat baseDNPattern
    • accumulateMultiValues

      private boolean accumulateMultiValues
  • Constructor Details

    • LdapNetworkConnector

      public LdapNetworkConnector()
  • Method Details

    • setConnectTimeout

      public void setConnectTimeout(long connectTimeout)
      Overrides:
      setConnectTimeout in class org.apache.sshd.common.util.net.NetworkConnector
    • setReadTimeout

      public void setReadTimeout(long readTimeout)
      Overrides:
      setReadTimeout in class org.apache.sshd.common.util.net.NetworkConnector
    • getLdapFactory

      public String getLdapFactory()
    • setLdapFactory

      public void setLdapFactory(String factory)
      Parameters:
      factory - The LDAP context factory
    • getBaseDN

      public String getBaseDN()
    • setBaseDN

      public void setBaseDN(String p)
      Parameters:
      p - The base DN pattern - the arguments to the pattern depend on the actual usage
      See Also:
    • getBindDNPattern

      public String getBindDNPattern()
    • setBindDNPattern

      public void setBindDNPattern(String p)
    • getBindPasswordPattern

      public String getBindPasswordPattern()
    • setBindPasswordPattern

      public void setBindPasswordPattern(String p)
    • getSearchFilterPattern

      public String getSearchFilterPattern()
    • setSearchFilterPattern

      public void setSearchFilterPattern(String p)
    • getSearchScope

      public int getSearchScope()
      Returns:
      The search scope
      See Also:
    • setSearchScope

      public void setSearchScope(int scope)
      Parameters:
      scope - The search scope
      See Also:
    • getTimeLimit

      public long getTimeLimit()
      Returns:
      Time limit (millis) to wait for result - zero means forever
    • setTimeLimit

      public void setTimeLimit(long limit)
    • getCountLimit

      public long getCountLimit()
      Returns:
      Maximum number of entries to be returned in a query
    • setCountLimit

      public void setCountLimit(long count)
    • isDerefLink

      public boolean isDerefLink()
      Returns:
      true whether links should be de-referenced
      See Also:
    • setDerefLink

      public void setDerefLink(boolean enabled)
    • getRetrievedAttributes

      public String getRetrievedAttributes()
      Returns:
      Comma separated list of attributes to retrieve
    • setRetrievedAttributes

      public void setRetrievedAttributes(String attrs)
      Parameters:
      attrs - Comma separated list of attributes to retrieve - if null/empty then no attributes are retrieved
      See Also:
    • isAccumulateMultiValues

      public boolean isAccumulateMultiValues()
    • setAccumulateMultiValues

      public void setAccumulateMultiValues(boolean enabled)
    • isReturningObjFlag

      public boolean isReturningObjFlag()
      Returns:
      true if objects are returned as result of the query
      See Also:
    • setReturningObjFlag

      public void setReturningObjFlag(boolean enabled)
    • getAuthenticationMode

      public String getAuthenticationMode()
      Returns:
      Authentication mode to use: &qout;none", "simple", etc.
      See Also:
    • setAuthenticationMode

      public void setAuthenticationMode(String mode)
    • getReferralMode

      public String getReferralMode()
      Returns:
      How referrals encountered by the service provider are to be processed
      See Also:
    • setReferralMode

      public void setReferralMode(String mode)
    • getProtocolVersion

      public int getProtocolVersion()
      Returns:
      The specified protocol version - non-positive if default provider version used
    • setProtocolVersion

      public void setProtocolVersion(int value)
    • getBinaryAttributes

      public String getBinaryAttributes()
      Returns:
      Comma separated list of attributes known to be binary so that they are returned as byte[] value rather than strings
    • setBinaryAttributes

      public void setBinaryAttributes(String value)
      Parameters:
      value - Comma separated list of attributes known to be binary so that they are returned as byte[] value rather than strings
      See Also:
    • resolveAttributes

      public Map<String,Object> resolveAttributes(String username, String password, C queryContext) throws NamingException
      Parameters:
      username - Username to be used either to access the LDAP or retrieve the user's attributes - may be null/empty if not required for the specific query
      password - Password Password to be used if necessary - may be null/empty if not required for the specific query
      queryContext - User specific query context - relevant for derived classes that want to override some of query processing methods
      Returns:
      A Map of the retrieved attributes - Note: if isAccumulateMultiValues() is true and multiple values are encountered for an attribute then a List of them is mapped as its value
      Throws:
      NamingException - If failed to executed the LDAP query
      See Also:
    • queryAttributes

      protected Map<String,Object> queryAttributes(C queryContext, DirContext context, Map<?,?> ldapConfig, String username, String password) throws NamingException
      Parameters:
      queryContext - The user-specific query context
      context - The initialized DirContext
      ldapConfig - The LDAP environment setup
      username - The username
      password - The password
      Returns:
      A Map of the retrieved attributes - Note: if isAccumulateMultiValues() is true and multiple values are encountered for an attribute then a List of them is mapped as its value
      Throws:
      NamingException - If failed to executed the LDAP query
    • initializeDirContext

      protected DirContext initializeDirContext(C queryContext, Map<String,Object> env, String username, String password) throws NamingException
      Throws:
      NamingException
    • setupDirContextEnvironment

      protected Map<String,Object> setupDirContextEnvironment(C queryContext, Map<String,Object> env, String username, String password) throws NamingException
      Called in order to set up the environment configuration passed to the InitialDirContext(Hashtable) constructor
      Parameters:
      queryContext - The caller-specific query context
      env - The current environment setup
      username - The username - may be null/empty
      password - The password - may be null/empty
      Returns:
      An updated environment configuration - can be a new instance or just the original one with some changes in it
      Throws:
      NamingException - If failed to set up the environment
    • resolveBaseDN

      protected String resolveBaseDN(C queryContext, Map<?,?> ldapConfig, String username, String password) throws NamingException
      Throws:
      NamingException
    • resolveSearchFilter

      protected String resolveSearchFilter(C queryContext, Map<?,?> ldapConfig, String username, String password) throws NamingException
      Throws:
      NamingException
    • processSearchResult

      protected void processSearchResult(C queryContext, Map<?,?> ldapConfig, Map<String,Object> attrsMap, int resultIndex, SearchResult result) throws NamingException
      Throws:
      NamingException
    • processResultAttributeValue

      protected Object processResultAttributeValue(C queryContext, Map<?,?> ldapConfig, String dn, int resultIndex, Map<String,Object> attrsMap, Attribute a) throws NamingException
      Throws:
      NamingException
    • accumulateAttributeValue

      protected Object accumulateAttributeValue(C queryContext, Map<String,Object> attrsMap, String attrID, Object attrVal)
    • toString

      public static String toString(Object attrVal)