java.lang.Object
com.inductiveautomation.ignition.gateway.authentication.impl.LDAPHelper

public class LDAPHelper extends Object
Encapsulates lots of the boilerplate code required to connect to and query an LDAP server.
  • Constructor Details

    • LDAPHelper

      public LDAPHelper(LoggerEx log)
  • Method Details

    • parseBasePatternString

      public 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. Real LDAP search strings are supported as well (though only the "|" "OR" type).
      Parameters:
      basePatternString - - a string LDAP search paths surrounded by parentheses
    • openContext

      public LdapContext openContext(String uname, String pwd) throws Exception
      Opens an LDAP query context with the given username and password. Will never return null.
      Throws:
      Exception
    • closeQuietly

      public void closeQuietly(DirContext ctx)
    • isUserValid

      public boolean isUserValid(String uname, String pwd) throws Exception
      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

      public String getLdapHost()
    • setLdapHost

      public void setLdapHost(String ldapHost)
    • getLdapPort

      public String getLdapPort()
    • setLdapPort

      public void setLdapPort(String ldapPort)
    • getSecondaryLdapHost

      public String getSecondaryLdapHost()
    • setSecondaryLdapHost

      public void setSecondaryLdapHost(String secondaryLdapHost)
    • getSecondaryLdapPort

      public String getSecondaryLdapPort()
    • setSecondaryLdapPort

      public void setSecondaryLdapPort(String secondaryLdapPort)
    • getUsernameSuffix

      public String getUsernameSuffix()
    • setUsernameSuffix

      public void setUsernameSuffix(String usernameSuffix)
    • getUsernamePrefix

      public String getUsernamePrefix()
    • setUsernamePrefix

      public void setUsernamePrefix(String usernamePrefix)
    • getProfileUsername

      public String getProfileUsername()
    • setProfileUsername

      public void setProfileUsername(String profileUsername)
    • getProfilePassword

      public String getProfilePassword()
    • setProfilePassword

      public void setProfilePassword(String profilePassword)
    • 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

      public void setSecurityAuthentication(LDAPHelper.AuthType securityAuthentication)
    • getSecurityAuthentication

      public LDAPHelper.AuthType getSecurityAuthentication()
    • setSecurityProtocol

      public void setSecurityProtocol(LDAPHelper.ProtocolType securityProtocol)
    • getSecurityProtocol

      public LDAPHelper.ProtocolType getSecurityProtocol()
    • getReadTimeout

      public Long getReadTimeout()
    • setReadTimeout

      public void setReadTimeout(Long readTimeout)
    • setPageSize

      public void setPageSize(int size)
    • getPageSize

      public int getPageSize()
    • getSaslConfig

      public SASLConfig getSaslConfig()
    • setSaslConfig

      public void setSaslConfig(SASLConfig saslConfig)
    • getReferral

      public LDAPHelper.ReferralType getReferral()
    • setReferral

      public void setReferral(LDAPHelper.ReferralType referral)