com.groiss.ldap
Class LDAPUtils

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

public class LDAPUtils
extends java.lang.Object

Helper class for dealing with LDAP-Servers


Constructor Summary
LDAPUtils()
           
 
Method Summary
static javax.naming.directory.DirContext connect(DirectoryServer ds)
          Connect to a directory server.
static Page connectAndList(javax.servlet.http.HttpServletRequest req)
          Connect to an LDAP Server and list its contents
static javax.naming.directory.DirContext createSubcontext(javax.naming.directory.DirContext baseContext, ClassMapping cm)
          Create a subcontext of a basecontext, as specified by a class mapping.
static void deleteSubtree(javax.naming.directory.DirContext ctx)
          Recursivly delete a subtree in the LDAP-Server
static java.lang.String extractRDNVal(java.lang.String dn)
          Extract the Value of the RDN from a String which is a DN
static javax.naming.directory.Attribute getAttribute(DirectoryServer ds, AttributeMapping am, Persistent o)
          Construct an Attribute from a Persistent and an Attribute Mapping
static java.lang.Object getAttValue(DirectoryServer ds, AttributeMapping am, Persistent o)
          Get an attribute value from an Persistent and an AttributeMapping
static java.lang.String getDN(ClassMapping cm, Persistent o)
          Get the distinguished name of an Persistent relative to the root
static java.lang.String getSearchExpression(javax.naming.directory.Attributes attribs, java.lang.Class<?> clazz, ClassMapping cm, javax.naming.directory.DirContext objectCtx, Persistent parentObject, java.lang.String parentField)
          Create a SQL search expression for an LDAP object.
static java.lang.String getSearchOid(Persistent o)
          Get a LDAP search expression for a Persistent based on Attribute entOid
static java.util.List<javax.naming.directory.SearchResult> getSearchResults(DirectoryServer ds, javax.naming.directory.DirContext baseContext, javax.naming.directory.SearchControls searchcons)
           
static java.lang.String getSearchString(ClassMapping cm, javax.naming.directory.DirContext ctx)
          Construct a LDAP search string for a dircontext based on the RDN attribute
static java.lang.String getSearchString(DirectoryServer ds, ClassMapping cm, Persistent o)
          Construct a LDAP search string for a Persistent based on the RDN attribute
static javax.naming.directory.DirContext getSubContext(javax.naming.directory.DirContext baseContext, ClassMapping cm)
          Get a subcontext of a basecontext, as specified ba a class mapping
static void setField(java.lang.reflect.Field ff, java.lang.Object o, java.lang.Object val)
          Set a field of the given object to a value
static void setNull(java.lang.reflect.Field ff, java.lang.Object o)
          Set the given field of an Object to an appropriate value for null
static void setSQLAttributes(Persistent o, javax.naming.directory.DirContext objectCtx, ClassMapping cm)
          Set the fields of the Persistent that corresponds to the given DirContext based on the ClassMapping
static void sync(DirectoryServer ds, boolean throwEx)
          Synchronize with a directory server.
 Page sync(javax.servlet.http.HttpServletRequest req)
          Synchronize with a directory Server
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LDAPUtils

public LDAPUtils()
Method Detail

connectAndList

public static Page connectAndList(javax.servlet.http.HttpServletRequest req)
                           throws java.lang.Exception
Connect to an LDAP Server and list its contents

Parameters:
req -
Returns:
a Page containing the content
Throws:
java.lang.Exception

getSearchResults

public static java.util.List<javax.naming.directory.SearchResult> getSearchResults(DirectoryServer ds,
                                                                                   javax.naming.directory.DirContext baseContext,
                                                                                   javax.naming.directory.SearchControls searchcons)
                                                                            throws javax.naming.NamingException,
                                                                                   java.io.IOException
Throws:
javax.naming.NamingException
java.io.IOException

sync

public Page sync(javax.servlet.http.HttpServletRequest req)
          throws java.lang.Exception
Synchronize with a directory Server

Parameters:
req -
Returns:
a feedback page
Throws:
java.lang.Exception

sync

public static void sync(DirectoryServer ds,
                        boolean throwEx)
                 throws java.lang.Exception
Synchronize with a directory server.

Parameters:
ds - the server to synchronize with
Throws:
java.lang.Exception

connect

public static javax.naming.directory.DirContext connect(DirectoryServer ds)
                                                 throws javax.naming.NamingException
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:
javax.naming.NamingException

getSubContext

public static javax.naming.directory.DirContext getSubContext(javax.naming.directory.DirContext baseContext,
                                                              ClassMapping cm)
                                                       throws java.lang.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:
java.lang.Exception

createSubcontext

public static javax.naming.directory.DirContext createSubcontext(javax.naming.directory.DirContext baseContext,
                                                                 ClassMapping cm)
                                                          throws java.lang.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:
java.lang.Exception

deleteSubtree

public static void deleteSubtree(javax.naming.directory.DirContext ctx)
                          throws java.lang.Exception
Recursivly delete a subtree in the LDAP-Server

Parameters:
ctx - the root of the tree to be deleted
Throws:
java.lang.Exception

getSearchString

public static java.lang.String getSearchString(ClassMapping cm,
                                               javax.naming.directory.DirContext ctx)
                                        throws java.lang.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:
java.lang.Exception

getSearchString

public static java.lang.String getSearchString(DirectoryServer ds,
                                               ClassMapping cm,
                                               Persistent o)
                                        throws java.lang.Exception
Construct a LDAP search string for a Persistent based on the RDN attribute

Parameters:
ds - the
cm -
o -
Returns:
the search string
Throws:
java.lang.Exception

getSearchOid

public static java.lang.String getSearchOid(Persistent o)
                                     throws java.lang.Exception
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
Throws:
java.lang.Exception

getDN

public static java.lang.String getDN(ClassMapping cm,
                                     Persistent o)
                              throws java.lang.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:
java.lang.Exception

getAttribute

public static javax.naming.directory.Attribute getAttribute(DirectoryServer ds,
                                                            AttributeMapping am,
                                                            Persistent o)
                                                     throws java.lang.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:
java.lang.Exception

getAttValue

public static java.lang.Object getAttValue(DirectoryServer ds,
                                           AttributeMapping am,
                                           Persistent o)
                                    throws java.lang.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:
java.lang.Exception

setSQLAttributes

public static void setSQLAttributes(Persistent o,
                                    javax.naming.directory.DirContext objectCtx,
                                    ClassMapping cm)
                             throws java.lang.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:
java.lang.Exception

getSearchExpression

public static java.lang.String getSearchExpression(javax.naming.directory.Attributes attribs,
                                                   java.lang.Class<?> clazz,
                                                   ClassMapping cm,
                                                   javax.naming.directory.DirContext objectCtx,
                                                   Persistent parentObject,
                                                   java.lang.String parentField)
                                            throws java.lang.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:
java.lang.Exception

setNull

public static void setNull(java.lang.reflect.Field ff,
                           java.lang.Object o)
                    throws java.lang.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:
java.lang.Exception

setField

public static void setField(java.lang.reflect.Field ff,
                            java.lang.Object o,
                            java.lang.Object val)
                     throws java.lang.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:
java.lang.Exception

extractRDNVal

public static java.lang.String extractRDNVal(java.lang.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)


@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.