Package org.apache.sshd.ldap
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 toresolveAttributes(String, String, Object)
- Direct Known Subclasses:
LdapAuthenticator
public class LdapNetworkConnector<C>
extends org.apache.sshd.common.util.net.NetworkConnector
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
static final String
A special value used to indicate that all attributes are requiredprotected MessageFormat
protected MessageFormat
protected MessageFormat
static final String
A list of known binary attributesstatic final boolean
static final String
static final String
static final long
static final boolean
static final String
Property used to override the default LDAP context factory classstatic final String
Default LDAP context factory class - unless overridden via theDEFAULT_LDAP_FACTORY_PROPNAME
propertystatic final int
static final String
static final String
static final boolean
static final int
static final long
protected final SearchControls
protected MessageFormat
Fields inherited from class org.apache.sshd.common.util.net.NetworkConnector
DEFAULT_CONNECT_TIMEOUT, DEFAULT_HOST, DEFAULT_READ_TIMEOUT
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
accumulateAttributeValue
(C queryContext, Map<String, Object> attrsMap, String attrID, Object attrVal) long
int
int
long
protected DirContext
boolean
boolean
boolean
protected Object
processResultAttributeValue
(C queryContext, Map<?, ?> ldapConfig, String dn, int resultIndex, Map<String, Object> attrsMap, Attribute a) protected void
processSearchResult
(C queryContext, Map<?, ?> ldapConfig, Map<String, Object> attrsMap, int resultIndex, SearchResult result) queryAttributes
(C queryContext, DirContext context, Map<?, ?> ldapConfig, String username, String password) resolveAttributes
(String username, String password, C queryContext) protected String
resolveBaseDN
(C queryContext, Map<?, ?> ldapConfig, String username, String password) protected String
resolveSearchFilter
(C queryContext, Map<?, ?> ldapConfig, String username, String password) void
setAccumulateMultiValues
(boolean enabled) void
setAuthenticationMode
(String mode) void
void
setBinaryAttributes
(String value) void
void
void
setConnectTimeout
(long connectTimeout) void
setCountLimit
(long count) void
setDerefLink
(boolean enabled) void
setLdapFactory
(String factory) void
setProtocolVersion
(int value) void
setReadTimeout
(long readTimeout) void
setReferralMode
(String mode) void
setRetrievedAttributes
(String attrs) void
setReturningObjFlag
(boolean enabled) void
void
setSearchScope
(int scope) void
setTimeLimit
(long limit) setupDirContextEnvironment
(C queryContext, Map<String, Object> env, String username, String password) Called in order to set up the environment configuration passed to theInitialDirContext(Hashtable)
constructorstatic String
Methods inherited from class org.apache.sshd.common.util.net.NetworkConnector
getConnectTimeout, getHost, getPort, getProtocol, getReadTimeout, setHost, setPort, setProtocol, toString
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
-
Field Details
-
DEFAULT_LDAP_PROTOCOL
- See Also:
-
DEFAULT_LDAP_PORT
public static final int DEFAULT_LDAP_PORT- See Also:
-
DEFAULT_LDAP_FACTORY_PROPNAME
Property used to override the default LDAP context factory class- See Also:
-
DEFAULT_LDAP_FACTORY_PROPVAL
Default LDAP context factory class - unless overridden via theDEFAULT_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
- 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
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
- See Also:
-
DEFAULT_LDAP_BIND_PASSWORD_PATTERN
- See Also:
-
DEFAULT_BINARY_ATTRIBUTES
A list of known binary attributes- See Also:
-
searchControls
-
ldapEnv
-
bindDNPattern
-
bindPasswordPattern
-
searchFilterPattern
-
baseDNPattern
-
accumulateMultiValues
private boolean accumulateMultiValues
-
-
Constructor Details
-
LdapNetworkConnector
public LdapNetworkConnector()
-
-
Method Details
-
setConnectTimeout
public void setConnectTimeout(long connectTimeout) - Overrides:
setConnectTimeout
in classorg.apache.sshd.common.util.net.NetworkConnector
-
setReadTimeout
public void setReadTimeout(long readTimeout) - Overrides:
setReadTimeout
in classorg.apache.sshd.common.util.net.NetworkConnector
-
getLdapFactory
-
setLdapFactory
- Parameters:
factory
- The LDAP context factory
-
getBaseDN
-
setBaseDN
- Parameters:
p
- The base DN pattern - the arguments to the pattern depend on the actual usage- See Also:
-
getBindDNPattern
-
setBindDNPattern
-
getBindPasswordPattern
-
setBindPasswordPattern
-
getSearchFilterPattern
-
setSearchFilterPattern
-
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
- Returns:
- Comma separated list of attributes to retrieve
-
setRetrievedAttributes
- Parameters:
attrs
- Comma separated list of attributes to retrieve - ifnull
/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
- Returns:
- Authentication mode to use: &qout;none", "simple", etc.
- See Also:
-
setAuthenticationMode
-
getReferralMode
- Returns:
- How referrals encountered by the service provider are to be processed
- See Also:
-
setReferralMode
-
getProtocolVersion
public int getProtocolVersion()- Returns:
- The specified protocol version - non-positive if default provider version used
-
setProtocolVersion
public void setProtocolVersion(int value) -
getBinaryAttributes
- Returns:
- Comma separated list of attributes known to be binary so that they are returned as
byte[]
value rather than strings
-
setBinaryAttributes
- Parameters:
value
- Comma separated list of attributes known to be binary so that they are returned asbyte[]
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 benull
/empty if not required for the specific querypassword
- Password Password to be used if necessary - may benull
/empty if not required for the specific queryqueryContext
- 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: ifisAccumulateMultiValues()
istrue
and multiple values are encountered for an attribute then aList
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 contextcontext
- The initializedDirContext
ldapConfig
- The LDAP environment setupusername
- The usernamepassword
- The password- Returns:
- A
Map
of the retrieved attributes - Note: ifisAccumulateMultiValues()
istrue
and multiple values are encountered for an attribute then aList
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 NamingExceptionCalled in order to set up the environment configuration passed to theInitialDirContext(Hashtable)
constructor- Parameters:
queryContext
- The caller-specific query contextenv
- The current environment setupusername
- The username - may benull
/emptypassword
- The password - may benull
/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, throws NamingExceptionObject> attrsMap, int resultIndex, SearchResult result) - Throws:
NamingException
-
processResultAttributeValue
protected Object processResultAttributeValue(C queryContext, Map<?, ?> ldapConfig, String dn, int resultIndex, Map<String, throws NamingExceptionObject> attrsMap, Attribute a) - Throws:
NamingException
-
accumulateAttributeValue
-
toString
-