Class LDAPHelper
- java.lang.Object
- 
- com.inductiveautomation.ignition.gateway.authentication.impl.LDAPHelper
 
- 
 public class LDAPHelper extends java.lang.ObjectEncapsulates lots of the boilerplate code required to connect to and query an LDAP server.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classLDAPHelper.AuthTypestatic classLDAPHelper.ProtocolTypestatic classLDAPHelper.ReferralTypestatic interfaceLDAPHelper.SearchHandler<T>
 - 
Constructor SummaryConstructors Constructor Description LDAPHelper(LoggerEx log)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseQuietly(javax.naming.directory.DirContext ctx)java.lang.StringgetLdapHost()java.lang.StringgetLdapPort()intgetPageSize()java.lang.StringgetProfilePassword()java.lang.StringgetProfileUsername()java.lang.LonggetReadTimeout()LDAPHelper.ReferralTypegetReferral()SASLConfiggetSaslConfig()java.lang.StringgetSecondaryLdapHost()java.lang.StringgetSecondaryLdapPort()LDAPHelper.AuthTypegetSecurityAuthentication()LDAPHelper.ProtocolTypegetSecurityProtocol()java.lang.StringgetUsernamePrefix()java.lang.StringgetUsernameSuffix()booleanisAllowAnon()booleanisUserValid(java.lang.String uname, java.lang.String pwd)Checks the validity of a username/password pair against the ldap serverbooleanisUseSSL()javax.naming.ldap.LdapContextopenContext(java.lang.String uname, java.lang.String pwd)Opens an LDAP query context with the given username and password.static java.lang.String[]parseBasePatternString(java.lang.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> java.util.List<T>search(java.lang.String[] bases, java.lang.String filter, java.lang.Object[] filterArgs, LDAPHelper.SearchHandler<T> handler)Opens a context using the profile username/password.<T> java.util.List<T>search(javax.naming.ldap.LdapContext ctx, java.lang.String[] bases, java.lang.String filter, java.lang.Object[] filterArgs, javax.naming.directory.SearchControls controls, LDAPHelper.SearchHandler<T> handler)Searches using the filter and args on each base specified on the supplied context.voidsetAllowAnon(boolean allowAnon)voidsetLdapHost(java.lang.String ldapHost)voidsetLdapPort(java.lang.String ldapPort)voidsetPageSize(int size)voidsetProfilePassword(java.lang.String profilePassword)voidsetProfileUsername(java.lang.String profileUsername)voidsetReadTimeout(java.lang.Long readTimeout)voidsetReferral(LDAPHelper.ReferralType referral)voidsetSaslConfig(SASLConfig saslConfig)voidsetSecondaryLdapHost(java.lang.String secondaryLdapHost)voidsetSecondaryLdapPort(java.lang.String secondaryLdapPort)voidsetSecurityAuthentication(LDAPHelper.AuthType securityAuthentication)voidsetSecurityProtocol(LDAPHelper.ProtocolType securityProtocol)voidsetUsernamePrefix(java.lang.String usernamePrefix)voidsetUsernameSuffix(java.lang.String usernameSuffix)voidsetUseSSL(boolean useSSL)
 
- 
- 
- 
Constructor Detail- 
LDAPHelperpublic LDAPHelper(LoggerEx log) 
 
- 
 - 
Method Detail- 
parseBasePatternStringpublic static java.lang.String[] parseBasePatternString(java.lang.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. Real LDAP search strings are supported as well (though only the "|" "OR" type).- Parameters:
- basePatternString- - a string LDAP search paths surrounded by parentheses
 
 - 
openContextpublic javax.naming.ldap.LdapContext openContext(java.lang.String uname, java.lang.String pwd) throws java.lang.ExceptionOpens an LDAP query context with the given username and password. Will never return null.- Throws:
- java.lang.Exception
 
 - 
closeQuietlypublic void closeQuietly(javax.naming.directory.DirContext ctx) 
 - 
isUserValidpublic boolean isUserValid(java.lang.String uname, java.lang.String pwd) throws java.lang.ExceptionChecks the validity of a username/password pair against the ldap server- Throws:
- java.lang.Exception
 
 - 
searchpublic <T> java.util.List<T> search(java.lang.String[] bases, java.lang.String filter, java.lang.Object[] filterArgs, LDAPHelper.SearchHandler<T> handler) throws java.lang.ExceptionOpens 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:
- java.lang.Exception
 
 - 
searchpublic <T> java.util.List<T> search(javax.naming.ldap.LdapContext ctx, java.lang.String[] bases, java.lang.String filter, java.lang.Object[] filterArgs, javax.naming.directory.SearchControls controls, LDAPHelper.SearchHandler<T> handler) throws java.lang.ExceptionSearches 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:
- java.lang.Exception
 
 - 
getLdapHostpublic java.lang.String getLdapHost() 
 - 
setLdapHostpublic void setLdapHost(java.lang.String ldapHost) 
 - 
getLdapPortpublic java.lang.String getLdapPort() 
 - 
setLdapPortpublic void setLdapPort(java.lang.String ldapPort) 
 - 
getSecondaryLdapHostpublic java.lang.String getSecondaryLdapHost() 
 - 
setSecondaryLdapHostpublic void setSecondaryLdapHost(java.lang.String secondaryLdapHost) 
 - 
getSecondaryLdapPortpublic java.lang.String getSecondaryLdapPort() 
 - 
setSecondaryLdapPortpublic void setSecondaryLdapPort(java.lang.String secondaryLdapPort) 
 - 
getUsernameSuffixpublic java.lang.String getUsernameSuffix() 
 - 
setUsernameSuffixpublic void setUsernameSuffix(java.lang.String usernameSuffix) 
 - 
getUsernamePrefixpublic java.lang.String getUsernamePrefix() 
 - 
setUsernamePrefixpublic void setUsernamePrefix(java.lang.String usernamePrefix) 
 - 
getProfileUsernamepublic java.lang.String getProfileUsername() 
 - 
setProfileUsernamepublic void setProfileUsername(java.lang.String profileUsername) 
 - 
getProfilePasswordpublic java.lang.String getProfilePassword() 
 - 
setProfilePasswordpublic void setProfilePassword(java.lang.String profilePassword) 
 - 
setUseSSLpublic void setUseSSL(boolean useSSL) 
 - 
isUseSSLpublic boolean isUseSSL() 
 - 
setAllowAnonpublic void setAllowAnon(boolean allowAnon) 
 - 
isAllowAnonpublic boolean isAllowAnon() 
 - 
setSecurityAuthenticationpublic void setSecurityAuthentication(LDAPHelper.AuthType securityAuthentication) 
 - 
getSecurityAuthenticationpublic LDAPHelper.AuthType getSecurityAuthentication() 
 - 
setSecurityProtocolpublic void setSecurityProtocol(LDAPHelper.ProtocolType securityProtocol) 
 - 
getSecurityProtocolpublic LDAPHelper.ProtocolType getSecurityProtocol() 
 - 
getReadTimeoutpublic java.lang.Long getReadTimeout() 
 - 
setReadTimeoutpublic void setReadTimeout(java.lang.Long readTimeout) 
 - 
setPageSizepublic void setPageSize(int size) 
 - 
getPageSizepublic int getPageSize() 
 - 
getSaslConfigpublic SASLConfig getSaslConfig() 
 - 
setSaslConfigpublic void setSaslConfig(SASLConfig saslConfig) 
 - 
getReferralpublic LDAPHelper.ReferralType getReferral() 
 - 
setReferralpublic void setReferral(LDAPHelper.ReferralType referral) 
 
- 
 
-