Class LDAPSearch

java.lang.Object
de.muehlencord.shared.network.ldap.LDAPSearch

public class LDAPSearch extends Object
Connection to LDAP server to search by different values
Author:
Joern Muehlencord (joern@muehlencord.de)
  • Constructor Details

    • LDAPSearch

      public LDAPSearch(String url, String searchBase, String username, String password)
      Creates a new instance of a LDAP search.
      Important:
      If you want to use LDAPs - usually port 636 make sure you provide a trustkeystore in case your LDAP server does not use a certificate which can be trusted by the build in root certificates. (e.g. self signed certificates)
      To provide access to a trust center you can specify the following parameter to your application by providing the following parameter
      -Djavax.net.ssl.trustStore=/path/to/truststore.keystore
      
      Parameters:
      url - the url of the LDAP server to connect to like ldap://ldapserver.your.domain:389
      searchBase - the search base to use - e.g. DC=domain,DC=tld
      username - the username to connect with
      password - the password to connect with
    • LDAPSearch

      public LDAPSearch(String authentication, String url, String securityProtocol, String searchBase, String username, String password)
      Creates a new instance of a LDAP search.
      Important:
      If you want to use LDAPs - usually port 636 make sure you provide a trustkeystore in case your LDAP server does not use a certificate which can be trusted by the build in root certificates. (e.g. self signed certificates)
      To provide access to a trust center you can specify the following parameter to your application by providing the following parameter
      -Djavax.net.ssl.trustStore=/path/to/truststore.keystore
      
      Parameters:
      authentication - the authentification type to use -e.g. "SIMPLE"
      url - the url of the ldap server to connect to like ldap://ldapserver.your.domain:389
      securityProtocol - the security protocol to use - e.g. SIMPLE
      searchBase - the search base to use - e.g. DC=domain,DC=tld
      username - the username to connect with
      password - the password to connect with
  • Method Details

    • init

      public void init() throws LDAPException
      execute several init steps, connect to LDAP
      Throws:
      LDAPException - if the connection cannot be established
    • close

      public void close() throws LDAPException
      close the LDAP connection
      Throws:
      LDAPException - if an error during closing appears.
    • getSearchBase

      public String getSearchBase()
      Returns the search base of the LDAP connection
      Returns:
      the search base of the LDAP connection
    • searchContactWithEmail

      public LDAPContact searchContactWithEmail(String email) throws LDAPException
      Searches a contact according to emailaddress in the address directory
      Parameters:
      email - emailaddress to search for
      Returns:
      LDAP contact or null if nothing could be found
      Throws:
      LDAPException - when search fails
    • searchContact

      public LDAPContact searchContact(String searchField, String searchValue) throws LDAPException
      Throws:
      LDAPException
    • emailExists

      public boolean emailExists(String email) throws LDAPException
      Returns true, if the given email address can be found in the configured LDAP.
      Parameters:
      email - the email address to search for
      Returns:
      true, if the email address could be found; else false
      Throws:
      LDAPException - if the search fails
    • isMemberOfGroup

      public boolean isMemberOfGroup(String email, String groupDn) throws LDAPException
      Returns true, if the given email address is member of the given group, specified by the DN
      Parameters:
      email - the email to validate
      groupDn - the group search base - all members must be found as "member" in this group
      Returns:
      true, if the given contact, specified by the email address is member of the specified group. Otherwise false is returned.
      Throws:
      LDAPException - if the validation fails.