Class LDAPUtils

java.lang.Object
com.groiss.ldap.LDAPUtils

public class LDAPUtils extends Object
Helper class for dealing with LDAP-Servers
  • Field Details

  • Constructor Details

    • LDAPUtils

      public LDAPUtils()
  • Method Details

    • connectAndList

      public static Page connectAndList(HttpServletRequest r) throws Exception
      Connect to an LDAP Server and list its contents
      Parameters:
      r -
      Returns:
      a Page containing the content
      Throws:
      Exception
    • getSearchResults

      public static List<SearchResult> getSearchResults(DirectoryServer ds, DirContext baseContext, SearchControls searchcons) throws NamingException, IOException
      Throws:
      NamingException
      IOException
    • sync

      public Page sync(HttpServletRequest r) throws Exception
      Synchronize with a directory Server
      Parameters:
      r -
      Returns:
      a feedback page
      Throws:
      Exception
    • sync

      public static void sync(DirectoryServer ds, boolean throwEx) throws Exception
      Synchronize with a directory server.
      Parameters:
      ds - the server to synchronize with
      Throws:
      Exception
    • connect

      public static DirContext connect(DirectoryServer ds) throws NamingException, IOException
      Connect to a directory server. Return the basic directory context
      Parameters:
      ds - the directory server to connect to
      Returns:
      the basic directory context as specified
      Throws:
      NamingException
      IOException
    • connect

      public static DirContext connect(String server, String port, String searchRoot, String username, String password, String communicationType, String trustLevel, String timeoutMs) throws NamingException, IOException
      Connect to a directory server. Return the basic directory context
      Returns:
      the basic directory context as specified
      Throws:
      NamingException
      IOException
    • getSubContext

      public static DirContext getSubContext(DirContext baseContext, ClassMapping cm) throws Exception
      Get a subcontext of a basecontext, as specified ba a class mapping
      Parameters:
      baseContext - the case context
      cm - the class mapping which specifies the subcontext
      Returns:
      a DirContext for the subcontext
      Throws:
      Exception
    • createSubcontext

      public static DirContext createSubcontext(DirContext baseContext, ClassMapping cm) throws Exception
      Create a subcontext of a basecontext, as specified by a class mapping. Types for the subcontext are top and organiationalUnit
      Parameters:
      baseContext - the case context
      cm - the class mapping which specifies the subcontext
      Returns:
      a new DirContext for the subcontext
      Throws:
      Exception
    • deleteSubtree

      public static void deleteSubtree(DirContext ctx) throws Exception
      Recursivly delete a subtree in the LDAP-Server
      Parameters:
      ctx - the root of the tree to be deleted
      Throws:
      Exception
    • getSearchString

      public static String getSearchString(ClassMapping cm, DirContext ctx) throws Exception
      Construct a LDAP search string for a dircontext based on the RDN attribute
      Parameters:
      cm - the appropriate class mapping for the dir context
      ctx - the context to construct the search string for
      Returns:
      a search string for the diretory context
      Throws:
      Exception
    • getSearchString

      public static String getSearchString(DirectoryServer ds, ClassMapping cm, Persistent o) throws Exception
      Construct a LDAP search string for a Persistent based on the RDN attribute
      Parameters:
      ds - the
      cm -
      o -
      Returns:
      the search string
      Throws:
      Exception
    • getSearchOid

      public static String getSearchOid(Persistent o)
      Get a LDAP search expression for a Persistent based on Attribute entOid
      Parameters:
      o - the Persistent for which the search expression is to be generated
      Returns:
      a string with the search expression
    • getDN

      public static String getDN(ClassMapping cm, Persistent o) throws Exception
      Get the distinguished name of an Persistent relative to the root
      Parameters:
      cm - an appropriate class mapping for the persistent
      o - the object to generate the DN for
      Returns:
      a DN identifying the object
      Throws:
      Exception
    • getAttribute

      public static Attribute getAttribute(DirectoryServer ds, AttributeMapping am, Persistent o) throws Exception
      Construct an Attribute from a Persistent and an Attribute Mapping
      Parameters:
      ds - the directory server
      am - the attribute mapping
      o - the Persistent
      Returns:
      an Attribute object for the specified Persistent and AttributeMapping
      Throws:
      Exception
    • getAttValue

      public static Object getAttValue(DirectoryServer ds, AttributeMapping am, Persistent o) throws Exception
      Get an attribute value from an Persistent and an AttributeMapping
      Parameters:
      ds - the directory server
      am - the attribute mapping
      o - the Persistent
      Returns:
      an value for the attribute for the specified Persistent and AttributeMapping combination
      Throws:
      Exception
    • setSQLAttributes

      public static void setSQLAttributes(Persistent o, DirContext objectCtx, ClassMapping cm) throws Exception
      Set the fields of the Persistent that corresponds to the given DirContext based on the ClassMapping
      Parameters:
      o - the Persistent whose fields are to be filled
      objectCtx - the directory context whose attribute values are to be filled into the Persistent
      cm - an appropriate ClassMapping between o and objectCtx
      Throws:
      Exception
    • getSearchExpression

      public static String getSearchExpression(Attributes attribs, Class<?> clazz, ClassMapping cm, DirContext objectCtx, Persistent parentObject, String parentField) throws Exception
      Create a SQL search expression for an LDAP object.
      Parameters:
      attribs - the Attributes of the LDAP object
      clazz - the class of the Persistent
      cm - an appropriate class mapping
      objectCtx - the LDAP object
      parentObject - the SQL parent object of the LDAP object
      parentField - the SQL field by which the parent object is linked to the Persistent (foreign key)
      Returns:
      an SQL search expression for the LDAP Object
      Throws:
      Exception
    • setNull

      public static void setNull(Field ff, Object o) throws Exception
      Set the given field of an Object to an appropriate value for null
      Parameters:
      ff - the Field to set
      o - the Object whose field is to be set
      Throws:
      Exception
    • setField

      public static void setField(Field ff, Object o, Object val) throws Exception
      Set a field of the given object to a value
      Parameters:
      ff - the field to set
      o - the Object whose field is to be set
      val - the value to set the field to
      Throws:
      Exception
    • extractRDNVal

      public static String extractRDNVal(String dn)
      Extract the Value of the RDN from a String which is a DN
      Parameters:
      dn - the distinguidhed name
      Returns:
      the RDN of the DN (the value of the first comma separated component of the dn)