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
closeQuietly
(DirContext ctx) int
boolean
boolean
boolean
isUserValid
(String uname, String pwd) Checks the validity of a username/password pair against the ldap serverboolean
isUseSSL()
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
(String 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.- 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.- Throws:
Exception
-
getLdapHost
-
setLdapHost
-
getLdapPort
-
setLdapPort
-
getSecondaryLdapHost
-
setSecondaryLdapHost
-
getSecondaryLdapPort
-
setSecondaryLdapPort
-
getUsernameSuffix
-
setUsernameSuffix
-
getUsernamePrefix
-
setUsernamePrefix
-
getProfileUsername
-
setProfileUsername
-
getProfilePassword
-
setProfilePassword
-
isUsePrefixAndSuffixForGatewayUser
public boolean isUsePrefixAndSuffixForGatewayUser() -
setUsePrefixAndSuffixForGatewayUser
public void setUsePrefixAndSuffixForGatewayUser(boolean usePrefixAndSuffixForGatewayUser) -
setUseSSL
public void setUseSSL(boolean useSSL) -
isUseSSL
public boolean isUseSSL() -
setAllowAnon
public void setAllowAnon(boolean allowAnon) -
isAllowAnon
public boolean isAllowAnon() -
setSecurityAuthentication
-
getSecurityAuthentication
-
setSecurityProtocol
-
getSecurityProtocol
-
getReadTimeout
-
setReadTimeout
-
setPageSize
public void setPageSize(int size) -
getPageSize
public int getPageSize() -
getSaslConfig
-
setSaslConfig
-
getReferral
-
setReferral
-