Class LDAPHelper
java.lang.Object
com.inductiveautomation.ignition.gateway.authentication.impl.LDAPHelper
Encapsulates lots of the boilerplate code required to connect to and query an LDAP server.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
static enum
static enum
static interface
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBinaryAttributes
(Collection<String> binaryAttributes) Add any LDAP attributes that need to be configured to be retrieved as a byte array instead of as a String.void
closeQuietly
(DirContext ctx) boolean
isUserValid
(String uname, String pwd) Checks the validity of a username/password pair against the ldap servervoid
This method will log a warning message for theLdapReferralException
ifreferral
== throw.openContext
(String uname, String pwd) Opens an LDAP query context with the given username and password.static String[]
parseBasePatternString
(String basePatternString) Given a string containing LDAP patterns for user locations (separated by parentheses in a pseudo-LDAP search string format - "(location1)(location2)", returns an array of those paths.<T> List<T>
search
(String[] bases, String filter, Object[] filterArgs, LDAPHelper.SearchHandler<T> handler) Opens a context using the profile username/password.<T> List<T>
search
(LdapContext ctx, String[] bases, String filter, Object[] filterArgs, SearchControls controls, LDAPHelper.SearchHandler<T> handler) Searches using the filter and args on each base specified on the supplied context.void
setAllowAnon
(boolean allowAnon) void
setLdapHost
(String ldapHost) void
setLdapPort
(String ldapPort) void
setPageSize
(int size) void
setProfilePassword
(SecretConfig profilePassword) void
setProfileUsername
(String profileUsername) void
setReadTimeout
(Long readTimeout) void
setReferral
(LDAPHelper.ReferralType referral) void
setSaslConfig
(SASLConfig saslConfig) void
setSecondaryLdapHost
(String secondaryLdapHost) void
setSecondaryLdapPort
(String secondaryLdapPort) void
setSecurityAuthentication
(LDAPHelper.AuthType securityAuthentication) void
setSecurityProtocol
(LDAPHelper.ProtocolType securityProtocol) void
setUsePrefixAndSuffixForGatewayUser
(boolean usePrefixAndSuffixForGatewayUser) void
setUsernamePrefix
(String usernamePrefix) void
setUsernameSuffix
(String usernameSuffix) void
setUseSSL
(boolean useSSL)
-
Constructor Details
-
LDAPHelper
-
-
Method Details
-
parseBasePatternString
Given a string containing LDAP patterns for user locations (separated by parentheses in a pseudo-LDAP search string format - "(location1)(location2)", returns an array of those paths. Real LDAP search strings are supported as well (though only the "|" "OR" type).- Parameters:
basePatternString
- - a string LDAP search paths surrounded by parentheses
-
openContext
Opens an LDAP query context with the given username and password. Will never return null.- Throws:
Exception
-
closeQuietly
-
isUserValid
Checks the validity of a username/password pair against the ldap server- Throws:
Exception
-
search
public <T> List<T> search(String[] bases, String filter, Object[] filterArgs, LDAPHelper.SearchHandler<T> handler) throws Exception Opens a context using the profile username/password. Uses search scope SUBTREE_SCOPE.- Parameters:
bases
- An array of bases to search through. Each one is searched separately.filter
- The filter string to use.filterArgs
- The arguments for the filter (may be null if not applicable)handler
- The handler to turn search results into useful objects.- Throws:
Exception
-
search
public <T> List<T> search(LdapContext ctx, String[] bases, String filter, Object[] filterArgs, SearchControls controls, LDAPHelper.SearchHandler<T> handler) throws Exception Searches using the filter and args on each base specified on the supplied context. Will close the context afterwards.- Type Parameters:
T
- The type of object returned in the response.- Parameters:
ctx
- The directory context to search.bases
- An array of bases to search through. Each one is searched separately.filter
- The filter string to use.filterArgs
- The arguments for the filter (may be null if not applicable)controls
- The search controls.handler
- The handler to turn search results into useful objects.- Returns:
- The
List
of objects that were searched for. - Throws:
Exception
- If there was an error during the search.
-
setLdapHost
-
setLdapPort
-
setSecondaryLdapHost
-
setSecondaryLdapPort
-
setUsernameSuffix
-
setUsernamePrefix
-
setProfileUsername
-
setProfilePassword
-
setUsePrefixAndSuffixForGatewayUser
public void setUsePrefixAndSuffixForGatewayUser(boolean usePrefixAndSuffixForGatewayUser) -
setUseSSL
public void setUseSSL(boolean useSSL) -
setAllowAnon
public void setAllowAnon(boolean allowAnon) -
setSecurityAuthentication
-
setSecurityProtocol
-
setReadTimeout
-
setPageSize
public void setPageSize(int size) -
setSaslConfig
-
setReferral
-
maybeLogReferralException
This method will log a warning message for theLdapReferralException
ifreferral
== throw.- Parameters:
ex
- TheLdapReferralException
to log.
-
addBinaryAttributes
Add any LDAP attributes that need to be configured to be retrieved as a byte array instead of as a String.- Parameters:
binaryAttributes
- The set of attributes to retrieved as a byte array.
-