Package com.groiss.ldap
Class LDAPUtils
java.lang.Object
com.groiss.ldap.LDAPUtils
Helper class for dealing with LDAP-Servers
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Signifies SSL/TLS encryption.static final String
Signifies unencrypted comunication.static final String
Signifies encryption via StartTLS.static final String
Implicitly trusts all server certificates (no check).static final String
Use system default trust store for server certificate check.static final String
Use @enterprise trust store for server certificate check. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic DirContext
Connect to a directory server.static DirContext
connect
(String server, String port, String searchRoot, String username, String password, String communicationType, String trustLevel, String timeoutMs) Connect to a directory server.static Page
Connect to an LDAP Server and list its contentsstatic DirContext
createSubcontext
(DirContext baseContext, ClassMapping cm) Create a subcontext of a basecontext, as specified by a class mapping.static void
deleteSubtree
(DirContext ctx) Recursivly delete a subtree in the LDAP-Serverstatic String
extractRDNVal
(String dn) Extract the Value of the RDN from a String which is a DNstatic Attribute
getAttribute
(DirectoryServer ds, AttributeMapping am, Persistent o) Construct an Attribute from a Persistent and an Attribute Mappingstatic Object
getAttValue
(DirectoryServer ds, AttributeMapping am, Persistent o) Get an attribute value from an Persistent and an AttributeMappingstatic String
getDN
(ClassMapping cm, Persistent o) Get the distinguished name of an Persistent relative to the rootstatic String
getSearchExpression
(Attributes attribs, Class<?> clazz, ClassMapping cm, DirContext objectCtx, Persistent parentObject, String parentField) Create a SQL search expression for an LDAP object.static String
Get a LDAP search expression for a Persistent based on Attribute entOidstatic List<SearchResult>
getSearchResults
(DirectoryServer ds, DirContext baseContext, SearchControls searchcons) static String
getSearchString
(ClassMapping cm, DirContext ctx) Construct a LDAP search string for a dircontext based on the RDN attributestatic String
getSearchString
(DirectoryServer ds, ClassMapping cm, Persistent o) Construct a LDAP search string for a Persistent based on the RDN attributestatic DirContext
getSubContext
(DirContext baseContext, ClassMapping cm) Get a subcontext of a basecontext, as specified ba a class mappingstatic void
Set a field of the given object to a valuestatic void
Set the given field of an Object to an appropriate value for nullstatic void
setSQLAttributes
(Persistent o, DirContext objectCtx, ClassMapping cm) Set the fields of the Persistent that corresponds to the given DirContext based on the ClassMappingstatic void
sync
(DirectoryServer ds, boolean throwEx) Synchronize with a directory server.Synchronize with a directory Server
-
Field Details
-
CT_PLAIN
Signifies unencrypted comunication.- See Also:
-
CT_ENCRYPTED
Signifies SSL/TLS encryption.- See Also:
-
CT_STARTTLS
Signifies encryption via StartTLS.- See Also:
-
TRUST_ALL
Implicitly trusts all server certificates (no check).- See Also:
-
TRUST_DEFAULT
Use system default trust store for server certificate check.- See Also:
-
TRUST_EP
Use @enterprise trust store for server certificate check.- See Also:
-
-
Constructor Details
-
LDAPUtils
public LDAPUtils()
-
-
Method Details
-
connectAndList
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
Synchronize with a directory Server- Parameters:
r
-- Returns:
- a feedback page
- Throws:
Exception
-
sync
Synchronize with a directory server.- Parameters:
ds
- the server to synchronize with- Throws:
Exception
-
connect
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
Get a subcontext of a basecontext, as specified ba a class mapping- Parameters:
baseContext
- the case contextcm
- the class mapping which specifies the subcontext- Returns:
- a DirContext for the subcontext
- Throws:
Exception
-
createSubcontext
Create a subcontext of a basecontext, as specified by a class mapping. Types for the subcontext are top and organiationalUnit- Parameters:
baseContext
- the case contextcm
- the class mapping which specifies the subcontext- Returns:
- a new DirContext for the subcontext
- Throws:
Exception
-
deleteSubtree
Recursivly delete a subtree in the LDAP-Server- Parameters:
ctx
- the root of the tree to be deleted- Throws:
Exception
-
getSearchString
Construct a LDAP search string for a dircontext based on the RDN attribute- Parameters:
cm
- the appropriate class mapping for the dir contextctx
- 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
- thecm
-o
-- Returns:
- the search string
- Throws:
Exception
-
getSearchOid
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
Get the distinguished name of an Persistent relative to the root- Parameters:
cm
- an appropriate class mapping for the persistento
- 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 serveram
- the attribute mappingo
- 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 serveram
- the attribute mappingo
- 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 filledobjectCtx
- the directory context whose attribute values are to be filled into the Persistentcm
- 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 objectclazz
- the class of the Persistentcm
- an appropriate class mappingobjectCtx
- the LDAP objectparentObject
- the SQL parent object of the LDAP objectparentField
- 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
Set the given field of an Object to an appropriate value for null- Parameters:
ff
- the Field to seto
- the Object whose field is to be set- Throws:
Exception
-
setField
Set a field of the given object to a value- Parameters:
ff
- the field to seto
- the Object whose field is to be setval
- the value to set the field to- Throws:
Exception
-
extractRDNVal
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)
-