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 enumstatic enumstatic enumstatic interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcloseQuietly(DirContext ctx) intbooleanbooleanbooleanisUserValid(String uname, String pwd) Checks the validity of a username/password pair against the ldap serverbooleanisUseSSL()voidThis method will log a warning message for theLdapReferralExceptionifreferral== 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.voidsetAllowAnon(boolean allowAnon) voidsetLdapHost(String ldapHost) voidsetLdapPort(String ldapPort) voidsetPageSize(int size) voidsetProfilePassword(String profilePassword) voidsetProfileUsername(String profileUsername) voidsetReadTimeout(Long readTimeout) voidsetReferral(LDAPHelper.ReferralType referral) voidsetSaslConfig(SASLConfig saslConfig) voidsetSecondaryLdapHost(String secondaryLdapHost) voidsetSecondaryLdapPort(String secondaryLdapPort) voidsetSecurityAuthentication(LDAPHelper.AuthType securityAuthentication) voidsetSecurityProtocol(LDAPHelper.ProtocolType securityProtocol) voidsetUsePrefixAndSuffixForGatewayUser(boolean usePrefixAndSuffixForGatewayUser) voidsetUsernamePrefix(String usernamePrefix) voidsetUsernameSuffix(String usernameSuffix) voidsetUseSSL(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
-
maybeLogReferralException
This method will log a warning message for theLdapReferralExceptionifreferral== throw.- Parameters:
ex- TheLdapReferralExceptionto log.
-