Package edu.vt.middleware.ldap
Class Ldap
- java.lang.Object
-
- edu.vt.middleware.ldap.AbstractLdap<LdapConfig>
-
- edu.vt.middleware.ldap.Ldap
-
- All Implemented Interfaces:
BaseLdap
,java.io.Serializable
public class Ldap extends AbstractLdap<LdapConfig> implements java.io.Serializable
Ldap
contains functions for basic interaction with an LDAP. Methods are provided for connecting, binding, querying and updating.- Version:
- $Revision: 1330 $ $Date: 2010-05-24 00:10:53 +0200 (Mon, 24 May 2010) $
- Author:
- Middleware Services
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Ldap.AttributeModification
Enum to define the type of attribute modification.
-
Field Summary
-
Fields inherited from class edu.vt.middleware.ldap.AbstractLdap
BINDING_COPY_RESULT_HANDLER, config, connectionHandler, COPY_RESULT_HANDLER, logger, NCP_COPY_RESULT_HANDLER, SR_COPY_RESULT_HANDLER
-
-
Constructor Summary
Constructors Constructor Description Ldap()
Default constructor.Ldap(LdapConfig ldapConfig)
This will create a newLdap
with the suppliedLdapConfig
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
compare(SearchFilter filter)
This will perform an LDAP compare operation with the supplied filter.boolean
compare(java.lang.String dn, SearchFilter filter)
This will perform an LDAP compare operation with the supplied filter and dn.void
create(java.lang.String dn, javax.naming.directory.Attributes attrs)
This will create the supplied dn in the LDAP namespace with the supplied attributes.void
delete(java.lang.String dn)
This will delete the supplied dn from the LDAP namespace.javax.naming.directory.Attributes
getAttributes(java.lang.String dn)
This will return all the attributes associated with the supplied dn.javax.naming.directory.Attributes
getAttributes(java.lang.String dn, java.lang.String[] retAttrs)
This will return the matching attributes associated with the supplied dn.javax.naming.directory.Attributes
getAttributes(java.lang.String dn, java.lang.String[] retAttrs, AttributeHandler... handler)
This will return the matching attributes associated with the supplied dn.LdapConfig
getLdapConfig()
This returns theLdapConfig
of theLdap
.java.lang.String[]
getSaslMechanisms()
This will return a list of SASL mechanisms that this LDAP supports.java.util.Iterator<javax.naming.directory.SearchResult>
getSchema(java.lang.String dn)
This will return the LDAP schema associated with the supplied dn.java.lang.String[]
getSupportedControls()
This will return a list of controls that this LDAP supports.java.util.Iterator<javax.naming.NameClassPair>
list(java.lang.String dn)
This will enumerate the names bounds to the specified context, along with the class names of objects bound to them.java.util.Iterator<javax.naming.Binding>
listBindings(java.lang.String dn)
This will enumerate the names bounds to the specified context, along with the objects bound to them.void
loadFromProperties()
This will set the config parameters of thisLdap
using the default properties file, which must be located in your classpath.void
loadFromProperties(java.io.InputStream is)
This will set the config parameters of thisLdap
using the supplied input stream.void
modifyAttributes(java.lang.String dn, Ldap.AttributeModification mod, javax.naming.directory.Attributes attrs)
This will modify the supplied attributes for the supplied value given by the modification operation.void
modifyAttributes(java.lang.String dn, javax.naming.directory.ModificationItem[] mods)
This will modify the supplied dn using the supplied modifications.void
rename(java.lang.String oldDn, java.lang.String newDn)
This will rename the supplied dn in the LDAP namespace.java.util.Iterator<javax.naming.directory.SearchResult>
search(SearchFilter filter)
This will query the LDAP with the supplied filter.java.util.Iterator<javax.naming.directory.SearchResult>
search(SearchFilter filter, java.lang.String[] retAttrs)
This will query the LDAP with the supplied filter and return attributes.java.util.Iterator<javax.naming.directory.SearchResult>
search(SearchFilter filter, javax.naming.directory.SearchControls searchControls)
This will query the LDAP with the supplied filter and search controls.java.util.Iterator<javax.naming.directory.SearchResult>
search(java.lang.String dn, SearchFilter filter)
This will query the LDAP with the supplied dn and filter.java.util.Iterator<javax.naming.directory.SearchResult>
search(java.lang.String dn, SearchFilter filter, java.lang.String[] retAttrs)
This will query the LDAP with the supplied dn, filter, and return attributes.java.util.Iterator<javax.naming.directory.SearchResult>
search(java.lang.String dn, SearchFilter filter, java.lang.String[] retAttrs, SearchResultHandler... handler)
This will query the LDAP with the supplied dn, filter, return attributes, and search result handler.java.util.Iterator<javax.naming.directory.SearchResult>
search(java.lang.String dn, SearchFilter filter, javax.naming.directory.SearchControls searchControls)
This will query the LDAP with the supplied dn, filter, and search controls.java.util.Iterator<javax.naming.directory.SearchResult>
search(java.lang.String dn, SearchFilter filter, javax.naming.directory.SearchControls searchControls, SearchResultHandler... handler)
This will query the LDAP with the supplied dn, filter, search controls, and search result handler.java.util.Iterator<javax.naming.directory.SearchResult>
searchAttributes(java.lang.String dn, javax.naming.directory.Attributes matchAttrs)
This will query the LDAP for the supplied dn and matching attributes.java.util.Iterator<javax.naming.directory.SearchResult>
searchAttributes(java.lang.String dn, javax.naming.directory.Attributes matchAttrs, java.lang.String[] retAttrs)
This will query the LDAP for the supplied dn, matching attributes and return attributes.java.util.Iterator<javax.naming.directory.SearchResult>
searchAttributes(java.lang.String dn, javax.naming.directory.Attributes matchAttrs, java.lang.String[] retAttrs, SearchResultHandler... handler)
This will query the LDAP for the supplied dn, matching attributes and return attributes.java.util.Iterator<javax.naming.directory.SearchResult>
searchAttributes(javax.naming.directory.Attributes matchAttrs)
This will query the LDAP for the supplied matching attributes.java.util.Iterator<javax.naming.directory.SearchResult>
searchAttributes(javax.naming.directory.Attributes matchAttrs, java.lang.String[] retAttrs)
This will query the LDAP for the supplied matching attributes and return attributes.void
setLdapConfig(LdapConfig ldapConfig)
This will set the config parameters of thisLdap
.-
Methods inherited from class edu.vt.middleware.ldap.AbstractLdap
close, compare, connect, finalize, getContext, modifyAttributes, operationRetry, pagedSearch, reconnect, search, toString
-
-
-
-
Constructor Detail
-
Ldap
public Ldap()
Default constructor.
-
Ldap
public Ldap(LdapConfig ldapConfig)
This will create a newLdap
with the suppliedLdapConfig
.- Parameters:
ldapConfig
-LdapConfig
-
-
Method Detail
-
setLdapConfig
public void setLdapConfig(LdapConfig ldapConfig)
This will set the config parameters of thisLdap
.- Overrides:
setLdapConfig
in classAbstractLdap<LdapConfig>
- Parameters:
ldapConfig
-LdapConfig
-
getLdapConfig
public LdapConfig getLdapConfig()
This returns theLdapConfig
of theLdap
.- Returns:
LdapConfig
-
loadFromProperties
public void loadFromProperties()
This will set the config parameters of thisLdap
using the default properties file, which must be located in your classpath.
-
loadFromProperties
public void loadFromProperties(java.io.InputStream is)
This will set the config parameters of thisLdap
using the supplied input stream.- Parameters:
is
-InputStream
-
compare
public boolean compare(SearchFilter filter) throws javax.naming.NamingException
This will perform an LDAP compare operation with the supplied filter.LdapConfig.getBaseDn()
is used as the dn to compare. Seecompare(String, SearchFilter)
.- Parameters:
filter
-SearchFilter
expression to use for compare- Returns:
boolean
- result of compare operation- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
compare
public boolean compare(java.lang.String dn, SearchFilter filter) throws javax.naming.NamingException
This will perform an LDAP compare operation with the supplied filter and dn.- Parameters:
dn
-String
name to comparefilter
-SearchFilter
expression to use for compare- Returns:
boolean
- result of compare operation- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
search
public java.util.Iterator<javax.naming.directory.SearchResult> search(SearchFilter filter) throws javax.naming.NamingException
This will query the LDAP with the supplied filter. All attributes will be returned.LdapConfig.getBaseDn()
is used as the start point for searching. Search controls will be created fromLdapConfig.getSearchControls(String[])
. Seesearch(String,SearchFilter,String[])
.- Parameters:
filter
-SearchFilter
expression to use for the search- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
search
public java.util.Iterator<javax.naming.directory.SearchResult> search(SearchFilter filter, java.lang.String[] retAttrs) throws javax.naming.NamingException
This will query the LDAP with the supplied filter and return attributes.LdapConfig.getBaseDn()
is used as the start point for searching. Search controls will be created fromLdapConfig.getSearchControls(String[])
. Seesearch(String,SearchFilter,String[])
.- Parameters:
filter
-SearchFilter
expression to use for the searchretAttrs
-String[]
attributes to return- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
search
public java.util.Iterator<javax.naming.directory.SearchResult> search(SearchFilter filter, javax.naming.directory.SearchControls searchControls) throws javax.naming.NamingException
This will query the LDAP with the supplied filter and search controls.LdapConfig.getBaseDn()
is used as the start point for searching. Seesearch(String,SearchFilter,SearchControls)
.- Parameters:
filter
-SearchFilter
expression to use for the searchsearchControls
-SearchControls
to search with- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
search
public java.util.Iterator<javax.naming.directory.SearchResult> search(java.lang.String dn, SearchFilter filter) throws javax.naming.NamingException
This will query the LDAP with the supplied dn and filter. All attributes will be returned. Search controls will be created fromLdapConfig.getSearchControls(String[])
. Seesearch(String,SearchFilter,String[])
.- Parameters:
dn
-String
name to begin search atfilter
-SearchFilter
expression to use for the search- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
search
public java.util.Iterator<javax.naming.directory.SearchResult> search(java.lang.String dn, SearchFilter filter, java.lang.String[] retAttrs) throws javax.naming.NamingException
This will query the LDAP with the supplied dn, filter, and return attributes. Search controls will be created fromLdapConfig.getSearchControls(String[])
. Seesearch(String,SearchFilter,SearchControls,SearchResultHandler[])
.- Parameters:
dn
-String
name to begin search atfilter
-SearchFilter
expression to use for the searchretAttrs
-String[]
attributes to return- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
search
public java.util.Iterator<javax.naming.directory.SearchResult> search(java.lang.String dn, SearchFilter filter, javax.naming.directory.SearchControls searchControls) throws javax.naming.NamingException
This will query the LDAP with the supplied dn, filter, and search controls. Seesearch(String,SearchFilter,SearchControls,SearchResultHandler[])
.- Parameters:
dn
-String
name to begin search atfilter
-SearchFilter
expression to use for the searchsearchControls
-SearchControls
to search with- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
search
public java.util.Iterator<javax.naming.directory.SearchResult> search(java.lang.String dn, SearchFilter filter, java.lang.String[] retAttrs, SearchResultHandler... handler) throws javax.naming.NamingException
This will query the LDAP with the supplied dn, filter, return attributes, and search result handler. Search controls will be created fromLdapConfig.getSearchControls(String[])
. Seesearch( String,SearchFilter,SearchControls,SearchResultHandler...)
.- Parameters:
dn
-String
name to begin search atfilter
-SearchFilter
expression to use for the searchretAttrs
-String[]
attributes to returnhandler
-SearchResultHandler[]
of handlers to execute- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
search
public java.util.Iterator<javax.naming.directory.SearchResult> search(java.lang.String dn, SearchFilter filter, javax.naming.directory.SearchControls searchControls, SearchResultHandler... handler) throws javax.naming.NamingException
This will query the LDAP with the supplied dn, filter, search controls, and search result handler. IfLdapConfig.getPagedResultsSize()
is greater than 0, the PagedResultsControl will be invoked. See#search(String,String,Object[],SearchControls,SearchResultHandler[])
.- Parameters:
dn
-String
name to begin search atfilter
-SearchFilter
expression to use for the searchsearchControls
-SearchControls
to search withhandler
-SearchResultHandler[]
of handlers to execute- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
searchAttributes
public java.util.Iterator<javax.naming.directory.SearchResult> searchAttributes(javax.naming.directory.Attributes matchAttrs) throws javax.naming.NamingException
This will query the LDAP for the supplied matching attributes. All attributes will be returned.LdapConfig.getBaseDn()
is used as the name to search. SeesearchAttributes(String, Attributes, String[])
.- Parameters:
matchAttrs
-Attributes
attributes to match- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
searchAttributes
public java.util.Iterator<javax.naming.directory.SearchResult> searchAttributes(javax.naming.directory.Attributes matchAttrs, java.lang.String[] retAttrs) throws javax.naming.NamingException
This will query the LDAP for the supplied matching attributes and return attributes.LdapConfig.getBaseDn()
is used as the name to search. SeesearchAttributes(String, Attributes, String[])
.- Parameters:
matchAttrs
-Attributes
attributes to matchretAttrs
-String[]
attributes to return- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
searchAttributes
public java.util.Iterator<javax.naming.directory.SearchResult> searchAttributes(java.lang.String dn, javax.naming.directory.Attributes matchAttrs) throws javax.naming.NamingException
This will query the LDAP for the supplied dn and matching attributes. All attributes will be returned. SeesearchAttributes(String, Attributes, String[])
.- Parameters:
dn
-String
name to search inmatchAttrs
-Attributes
attributes to match- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
searchAttributes
public java.util.Iterator<javax.naming.directory.SearchResult> searchAttributes(java.lang.String dn, javax.naming.directory.Attributes matchAttrs, java.lang.String[] retAttrs) throws javax.naming.NamingException
This will query the LDAP for the supplied dn, matching attributes and return attributes. SeesearchAttributes( String, Attributes, String[], SearchResultHandler[])
. This method converts relative DNs to fully qualified DNs, no post processing is required- Parameters:
dn
-String
name to search inmatchAttrs
-Attributes
attributes to matchretAttrs
-String[]
attributes to return- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
searchAttributes
public java.util.Iterator<javax.naming.directory.SearchResult> searchAttributes(java.lang.String dn, javax.naming.directory.Attributes matchAttrs, java.lang.String[] retAttrs, SearchResultHandler... handler) throws javax.naming.NamingException
This will query the LDAP for the supplied dn, matching attributes and return attributes. This method will always perform a one level search. The resultingIterator
is a deep copy of the original search results. If matchAttrs is empty or null then all objects in the target context are returned. If retAttrs is null then all attributes will be returned. If retAttrs is an empty array then no attributes will be returned. Seejavax.naming.DirContext#search(String, Attributes, String[])
.- Overrides:
searchAttributes
in classAbstractLdap<LdapConfig>
- Parameters:
dn
-String
name to search inmatchAttrs
-Attributes
attributes to matchretAttrs
-String[]
attributes to returnhandler
-SearchResultHandler[]
to post process results- Returns:
Iterator
- of LDAP search results- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
list
public java.util.Iterator<javax.naming.NameClassPair> list(java.lang.String dn) throws javax.naming.NamingException
This will enumerate the names bounds to the specified context, along with the class names of objects bound to them. The resultingIterator
is a deep copy of the original search results. SeeContext.list(String)
.- Overrides:
list
in classAbstractLdap<LdapConfig>
- Parameters:
dn
-String
LDAP context to list- Returns:
Iterator
- LDAP search result- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
listBindings
public java.util.Iterator<javax.naming.Binding> listBindings(java.lang.String dn) throws javax.naming.NamingException
This will enumerate the names bounds to the specified context, along with the objects bound to them. The resultingIterator
is a deep copy of the original search results. SeeContext.listBindings(String)
.- Overrides:
listBindings
in classAbstractLdap<LdapConfig>
- Parameters:
dn
-String
LDAP context to list- Returns:
Iterator
- LDAP search result- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
getAttributes
public javax.naming.directory.Attributes getAttributes(java.lang.String dn) throws javax.naming.NamingException
This will return all the attributes associated with the supplied dn. SeegetAttributes(String, String[])
.- Parameters:
dn
-String
named object in the LDAP- Returns:
Attributes
- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
getAttributes
public javax.naming.directory.Attributes getAttributes(java.lang.String dn, java.lang.String[] retAttrs) throws javax.naming.NamingException
This will return the matching attributes associated with the supplied dn. If retAttrs is null then all attributes will be returned. If retAttrs is an empty array then no attributes will be returned. SeegetAttributes(String, String[], AttributeHandler[])
.- Parameters:
dn
-String
named object in the LDAPretAttrs
-String[]
attributes to return- Returns:
Attributes
- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
getAttributes
public javax.naming.directory.Attributes getAttributes(java.lang.String dn, java.lang.String[] retAttrs, AttributeHandler... handler) throws javax.naming.NamingException
This will return the matching attributes associated with the supplied dn. If retAttrs is null then all attributes will be returned. If retAttrs is an empty array then no attributes will be returned. Seejavax.naming.DirContext#getAttributes(String, String[])
.- Overrides:
getAttributes
in classAbstractLdap<LdapConfig>
- Parameters:
dn
-String
named object in the LDAPretAttrs
-String[]
attributes to returnhandler
-AttributeHandler[]
to post process results- Returns:
Attributes
- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
getSchema
public java.util.Iterator<javax.naming.directory.SearchResult> getSchema(java.lang.String dn) throws javax.naming.NamingException
This will return the LDAP schema associated with the supplied dn. The resultingIterator
is a deep copy of the original search results. Seejavax.naming.DirContext#getSchema(String)
.- Overrides:
getSchema
in classAbstractLdap<LdapConfig>
- Parameters:
dn
-String
named object in the LDAP- Returns:
Iterator
- LDAP search result- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
modifyAttributes
public void modifyAttributes(java.lang.String dn, Ldap.AttributeModification mod, javax.naming.directory.Attributes attrs) throws javax.naming.NamingException
This will modify the supplied attributes for the supplied value given by the modification operation. SeeAbstractLdap.modifyAttributes(String, int, Attributes)
.- Parameters:
dn
-String
named object in the LDAPmod
-AttributeModification
modification operationattrs
-Attributes
attributes to be used for the operation, may be null- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
modifyAttributes
public void modifyAttributes(java.lang.String dn, javax.naming.directory.ModificationItem[] mods) throws javax.naming.NamingException
This will modify the supplied dn using the supplied modifications. The modifications are performed in the order specified. Each modification specifies a modification operation code and an attribute on which to operate. Where possible, the modifications are performed atomically. Seejavax.naming.DirContext#modifyAttributes(String, ModificationItem[])
.- Overrides:
modifyAttributes
in classAbstractLdap<LdapConfig>
- Parameters:
dn
-String
named object in the LDAPmods
-ModificationItem[]
modifications- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
create
public void create(java.lang.String dn, javax.naming.directory.Attributes attrs) throws javax.naming.NamingException
This will create the supplied dn in the LDAP namespace with the supplied attributes. Seejavax.naming.DirContext#createSubcontext(String, Attributes)
. Note that the context created by this operation is immediately closed.- Overrides:
create
in classAbstractLdap<LdapConfig>
- Parameters:
dn
-String
named object in the LDAPattrs
-Attributes
attributes to be added to this entry- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
rename
public void rename(java.lang.String oldDn, java.lang.String newDn) throws javax.naming.NamingException
This will rename the supplied dn in the LDAP namespace. SeeContext.rename(String, String)
.- Overrides:
rename
in classAbstractLdap<LdapConfig>
- Parameters:
oldDn
-String
object to renamenewDn
-String
new name- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
delete
public void delete(java.lang.String dn) throws javax.naming.NamingException
This will delete the supplied dn from the LDAP namespace. Note that this method does not throw NameNotFoundException if the supplied dn does not exist. SeeContext.destroySubcontext(String)
.- Overrides:
delete
in classAbstractLdap<LdapConfig>
- Parameters:
dn
-String
named object in the LDAP- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
getSaslMechanisms
public java.lang.String[] getSaslMechanisms() throws javax.naming.NamingException
This will return a list of SASL mechanisms that this LDAP supports.- Returns:
String[]
- supported SASL mechanisms- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
getSupportedControls
public java.lang.String[] getSupportedControls() throws javax.naming.NamingException
This will return a list of controls that this LDAP supports.- Returns:
String[]
- supported controls- Throws:
javax.naming.NamingException
- if the LDAP returns an error
-
-