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
Fields Modifier and Type Field Description private booleanaccumulateMultiValuesstatic java.lang.StringALL_LDAP_ATTRIBUTESA special value used to indicate that all attributes are requiredprotected java.text.MessageFormatbaseDNPatternprotected java.text.MessageFormatbindDNPatternprotected java.text.MessageFormatbindPasswordPatternstatic java.lang.StringDEFAULT_BINARY_ATTRIBUTESA list of known binary attributesstatic booleanDEFAULT_LDAP_ACCUMULATE_MULTIVALUESstatic java.lang.StringDEFAULT_LDAP_BIND_DN_PATTERNstatic java.lang.StringDEFAULT_LDAP_BIND_PASSWORD_PATTERNstatic longDEFAULT_LDAP_COUNT_LIMITstatic booleanDEFAULT_LDAP_DEREF_ENABLEDstatic java.lang.StringDEFAULT_LDAP_FACTORY_PROPNAMEProperty used to override the default LDAP context factory classstatic java.lang.StringDEFAULT_LDAP_FACTORY_PROPVALDefault LDAP context factory class - unless overridden via theDEFAULT_LDAP_FACTORY_PROPNAMEpropertystatic intDEFAULT_LDAP_PORTstatic java.lang.StringDEFAULT_LDAP_PROTOCOLstatic java.lang.StringDEFAULT_LDAP_REFERRAL_MODEstatic booleanDEFAULT_LDAP_RETURN_OBJVALUEstatic intDEFAULT_LDAP_SEARCH_SCOPEstatic longDEFAULT_LDAP_TIME_LIMITprotected java.util.Map<java.lang.String,java.lang.Object>ldapEnvprotected javax.naming.directory.SearchControlssearchControlsprotected java.text.MessageFormatsearchFilterPattern
-
Constructor Summary
Constructors Constructor Description LdapNetworkConnector()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.ObjectaccumulateAttributeValue(C queryContext, java.util.Map<java.lang.String,java.lang.Object> attrsMap, java.lang.String attrID, java.lang.Object attrVal)java.lang.StringgetAuthenticationMode()java.lang.StringgetBaseDN()java.lang.StringgetBinaryAttributes()java.lang.StringgetBindDNPattern()java.lang.StringgetBindPasswordPattern()longgetCountLimit()java.lang.StringgetLdapFactory()intgetProtocolVersion()java.lang.StringgetReferralMode()java.lang.StringgetRetrievedAttributes()java.lang.StringgetSearchFilterPattern()intgetSearchScope()longgetTimeLimit()protected javax.naming.directory.DirContextinitializeDirContext(C queryContext, java.util.Map<java.lang.String,java.lang.Object> env, java.lang.String username, java.lang.String password)booleanisAccumulateMultiValues()booleanisDerefLink()booleanisReturningObjFlag()protected java.lang.ObjectprocessResultAttributeValue(C queryContext, java.util.Map<?,?> ldapConfig, java.lang.String dn, int resultIndex, java.util.Map<java.lang.String,java.lang.Object> attrsMap, javax.naming.directory.Attribute a)protected voidprocessSearchResult(C queryContext, java.util.Map<?,?> ldapConfig, java.util.Map<java.lang.String,java.lang.Object> attrsMap, int resultIndex, javax.naming.directory.SearchResult result)protected java.util.Map<java.lang.String,java.lang.Object>queryAttributes(C queryContext, javax.naming.directory.DirContext context, java.util.Map<?,?> ldapConfig, java.lang.String username, java.lang.String password)java.util.Map<java.lang.String,java.lang.Object>resolveAttributes(java.lang.String username, java.lang.String password, C queryContext)protected java.lang.StringresolveBaseDN(C queryContext, java.util.Map<?,?> ldapConfig, java.lang.String username, java.lang.String password)protected java.lang.StringresolveSearchFilter(C queryContext, java.util.Map<?,?> ldapConfig, java.lang.String username, java.lang.String password)voidsetAccumulateMultiValues(boolean enabled)voidsetAuthenticationMode(java.lang.String mode)voidsetBaseDN(java.lang.String p)voidsetBinaryAttributes(java.lang.String value)voidsetBindDNPattern(java.lang.String p)voidsetBindPasswordPattern(java.lang.String p)voidsetConnectTimeout(long connectTimeout)voidsetCountLimit(long count)voidsetDerefLink(boolean enabled)voidsetLdapFactory(java.lang.String factory)voidsetProtocolVersion(int value)voidsetReadTimeout(long readTimeout)voidsetReferralMode(java.lang.String mode)voidsetRetrievedAttributes(java.lang.String attrs)voidsetReturningObjFlag(boolean enabled)voidsetSearchFilterPattern(java.lang.String p)voidsetSearchScope(int scope)voidsetTimeLimit(long limit)protected java.util.Map<java.lang.String,java.lang.Object>setupDirContextEnvironment(C queryContext, java.util.Map<java.lang.String,java.lang.Object> env, java.lang.String username, java.lang.String password)Called in order to set up the environment configuration passed to theInitialDirContext(Hashtable)constructorstatic java.lang.StringtoString(java.lang.Object attrVal)-
Methods inherited from class org.apache.sshd.common.util.net.NetworkConnector
getConnectTimeout, getHost, getPort, getProtocol, getReadTimeout, setHost, setPort, setProtocol, toString
-
-
-
-
Field Detail
-
DEFAULT_LDAP_PROTOCOL
public static final java.lang.String DEFAULT_LDAP_PROTOCOL
- See Also:
- Constant Field Values
-
DEFAULT_LDAP_PORT
public static final int DEFAULT_LDAP_PORT
- See Also:
- Constant Field Values
-
DEFAULT_LDAP_FACTORY_PROPNAME
public static final java.lang.String DEFAULT_LDAP_FACTORY_PROPNAME
Property used to override the default LDAP context factory class- See Also:
- Constant Field Values
-
DEFAULT_LDAP_FACTORY_PROPVAL
public static final java.lang.String DEFAULT_LDAP_FACTORY_PROPVAL
Default LDAP context factory class - unless overridden via theDEFAULT_LDAP_FACTORY_PROPNAMEproperty- See Also:
- Constant Field Values
-
DEFAULT_LDAP_SEARCH_SCOPE
public static final int DEFAULT_LDAP_SEARCH_SCOPE
- See Also:
- Constant Field Values
-
DEFAULT_LDAP_TIME_LIMIT
public static final long DEFAULT_LDAP_TIME_LIMIT
-
DEFAULT_LDAP_REFERRAL_MODE
public static final java.lang.String DEFAULT_LDAP_REFERRAL_MODE
- See Also:
- Constant Field Values
-
DEFAULT_LDAP_COUNT_LIMIT
public static final long DEFAULT_LDAP_COUNT_LIMIT
- See Also:
- Constant Field Values
-
DEFAULT_LDAP_DEREF_ENABLED
public static final boolean DEFAULT_LDAP_DEREF_ENABLED
- See Also:
- Constant Field Values
-
ALL_LDAP_ATTRIBUTES
public static final java.lang.String ALL_LDAP_ATTRIBUTES
A special value used to indicate that all attributes are required- See Also:
- Constant Field Values
-
DEFAULT_LDAP_RETURN_OBJVALUE
public static final boolean DEFAULT_LDAP_RETURN_OBJVALUE
- See Also:
- Constant Field Values
-
DEFAULT_LDAP_ACCUMULATE_MULTIVALUES
public static final boolean DEFAULT_LDAP_ACCUMULATE_MULTIVALUES
- See Also:
- Constant Field Values
-
DEFAULT_LDAP_BIND_DN_PATTERN
public static final java.lang.String DEFAULT_LDAP_BIND_DN_PATTERN
- See Also:
- Constant Field Values
-
DEFAULT_LDAP_BIND_PASSWORD_PATTERN
public static final java.lang.String DEFAULT_LDAP_BIND_PASSWORD_PATTERN
- See Also:
- Constant Field Values
-
DEFAULT_BINARY_ATTRIBUTES
public static final java.lang.String DEFAULT_BINARY_ATTRIBUTES
A list of known binary attributes- See Also:
- LDAP Attributes, Constant Field Values
-
searchControls
protected final javax.naming.directory.SearchControls searchControls
-
ldapEnv
protected final java.util.Map<java.lang.String,java.lang.Object> ldapEnv
-
bindDNPattern
protected java.text.MessageFormat bindDNPattern
-
bindPasswordPattern
protected java.text.MessageFormat bindPasswordPattern
-
searchFilterPattern
protected java.text.MessageFormat searchFilterPattern
-
baseDNPattern
protected java.text.MessageFormat baseDNPattern
-
accumulateMultiValues
private boolean accumulateMultiValues
-
-
Method Detail
-
setConnectTimeout
public void setConnectTimeout(long connectTimeout)
- Overrides:
setConnectTimeoutin classorg.apache.sshd.common.util.net.NetworkConnector
-
setReadTimeout
public void setReadTimeout(long readTimeout)
- Overrides:
setReadTimeoutin classorg.apache.sshd.common.util.net.NetworkConnector
-
getLdapFactory
public java.lang.String getLdapFactory()
-
setLdapFactory
public void setLdapFactory(java.lang.String factory)
- Parameters:
factory- The LDAP context factory
-
getBaseDN
public java.lang.String getBaseDN()
-
setBaseDN
public void setBaseDN(java.lang.String p)
- Parameters:
p- The base DN pattern - the arguments to the pattern depend on the actual usage- See Also:
MessageFormat.format(String, Object...)
-
getBindDNPattern
public java.lang.String getBindDNPattern()
-
setBindDNPattern
public void setBindDNPattern(java.lang.String p)
-
getBindPasswordPattern
public java.lang.String getBindPasswordPattern()
-
setBindPasswordPattern
public void setBindPasswordPattern(java.lang.String p)
-
getSearchFilterPattern
public java.lang.String getSearchFilterPattern()
-
setSearchFilterPattern
public void setSearchFilterPattern(java.lang.String p)
-
getSearchScope
public int getSearchScope()
- Returns:
- The search scope
- See Also:
SearchControls.OBJECT_SCOPE,SearchControls.ONELEVEL_SCOPE,SearchControls.SUBTREE_SCOPE
-
setSearchScope
public void setSearchScope(int scope)
- Parameters:
scope- The search scope- See Also:
SearchControls.OBJECT_SCOPE,SearchControls.ONELEVEL_SCOPE,SearchControls.SUBTREE_SCOPE
-
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:
truewhether links should be de-referenced- See Also:
SearchControls.getDerefLinkFlag()
-
setDerefLink
public void setDerefLink(boolean enabled)
-
getRetrievedAttributes
public java.lang.String getRetrievedAttributes()
- Returns:
- Comma separated list of attributes to retrieve
-
setRetrievedAttributes
public void setRetrievedAttributes(java.lang.String attrs)
- Parameters:
attrs- Comma separated list of attributes to retrieve - ifnull/empty then no attributes are retrieved- See Also:
SearchControls.setReturningAttributes(String[])
-
isAccumulateMultiValues
public boolean isAccumulateMultiValues()
-
setAccumulateMultiValues
public void setAccumulateMultiValues(boolean enabled)
-
isReturningObjFlag
public boolean isReturningObjFlag()
- Returns:
trueif objects are returned as result of the query- See Also:
SearchControls.getReturningObjFlag()
-
setReturningObjFlag
public void setReturningObjFlag(boolean enabled)
-
getAuthenticationMode
public java.lang.String getAuthenticationMode()
- Returns:
- Authentication mode to use: &qout;none", "simple", etc.
- See Also:
Context.SECURITY_AUTHENTICATION
-
setAuthenticationMode
public void setAuthenticationMode(java.lang.String mode)
-
getReferralMode
public java.lang.String getReferralMode()
- Returns:
- How referrals encountered by the service provider are to be processed
- See Also:
Context.REFERRAL
-
setReferralMode
public void setReferralMode(java.lang.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 java.lang.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(java.lang.String value)
- Parameters:
value- Comma separated list of attributes known to be binary so that they are returned asbyte[]value rather than strings- See Also:
- LDAP Attributes
-
resolveAttributes
public java.util.Map<java.lang.String,java.lang.Object> resolveAttributes(java.lang.String username, java.lang.String password, C queryContext) throws javax.naming.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
Mapof the retrieved attributes - Note: ifisAccumulateMultiValues()istrueand multiple values are encountered for an attribute then aListof them is mapped as its value - Throws:
javax.naming.NamingException- If failed to executed the LDAP query- See Also:
queryAttributes(Object, DirContext, Map, String, String)
-
queryAttributes
protected java.util.Map<java.lang.String,java.lang.Object> queryAttributes(C queryContext, javax.naming.directory.DirContext context, java.util.Map<?,?> ldapConfig, java.lang.String username, java.lang.String password) throws javax.naming.NamingException
- Parameters:
queryContext- The user-specific query contextcontext- The initializedDirContextldapConfig- The LDAP environment setupusername- The usernamepassword- The password- Returns:
- A
Mapof the retrieved attributes - Note: ifisAccumulateMultiValues()istrueand multiple values are encountered for an attribute then aListof them is mapped as its value - Throws:
javax.naming.NamingException- If failed to executed the LDAP query
-
initializeDirContext
protected javax.naming.directory.DirContext initializeDirContext(C queryContext, java.util.Map<java.lang.String,java.lang.Object> env, java.lang.String username, java.lang.String password) throws javax.naming.NamingException
- Throws:
javax.naming.NamingException
-
setupDirContextEnvironment
protected java.util.Map<java.lang.String,java.lang.Object> setupDirContextEnvironment(C queryContext, java.util.Map<java.lang.String,java.lang.Object> env, java.lang.String username, java.lang.String password) throws javax.naming.NamingException
Called 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:
javax.naming.NamingException- If failed to set up the environment
-
resolveBaseDN
protected java.lang.String resolveBaseDN(C queryContext, java.util.Map<?,?> ldapConfig, java.lang.String username, java.lang.String password) throws javax.naming.NamingException
- Throws:
javax.naming.NamingException
-
resolveSearchFilter
protected java.lang.String resolveSearchFilter(C queryContext, java.util.Map<?,?> ldapConfig, java.lang.String username, java.lang.String password) throws javax.naming.NamingException
- Throws:
javax.naming.NamingException
-
processSearchResult
protected void processSearchResult(C queryContext, java.util.Map<?,?> ldapConfig, java.util.Map<java.lang.String,java.lang.Object> attrsMap, int resultIndex, javax.naming.directory.SearchResult result) throws javax.naming.NamingException
- Throws:
javax.naming.NamingException
-
processResultAttributeValue
protected java.lang.Object processResultAttributeValue(C queryContext, java.util.Map<?,?> ldapConfig, java.lang.String dn, int resultIndex, java.util.Map<java.lang.String,java.lang.Object> attrsMap, javax.naming.directory.Attribute a) throws javax.naming.NamingException
- Throws:
javax.naming.NamingException
-
accumulateAttributeValue
protected java.lang.Object accumulateAttributeValue(C queryContext, java.util.Map<java.lang.String,java.lang.Object> attrsMap, java.lang.String attrID, java.lang.Object attrVal)
-
toString
public static java.lang.String toString(java.lang.Object attrVal)
-
-