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
Ldapcontains 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 classLdap.AttributeModificationEnum 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 newLdapwith the suppliedLdapConfig.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancompare(SearchFilter filter)This will perform an LDAP compare operation with the supplied filter.booleancompare(java.lang.String dn, SearchFilter filter)This will perform an LDAP compare operation with the supplied filter and dn.voidcreate(java.lang.String dn, javax.naming.directory.Attributes attrs)This will create the supplied dn in the LDAP namespace with the supplied attributes.voiddelete(java.lang.String dn)This will delete the supplied dn from the LDAP namespace.javax.naming.directory.AttributesgetAttributes(java.lang.String dn)This will return all the attributes associated with the supplied dn.javax.naming.directory.AttributesgetAttributes(java.lang.String dn, java.lang.String[] retAttrs)This will return the matching attributes associated with the supplied dn.javax.naming.directory.AttributesgetAttributes(java.lang.String dn, java.lang.String[] retAttrs, AttributeHandler... handler)This will return the matching attributes associated with the supplied dn.LdapConfiggetLdapConfig()This returns theLdapConfigof 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.voidloadFromProperties()This will set the config parameters of thisLdapusing the default properties file, which must be located in your classpath.voidloadFromProperties(java.io.InputStream is)This will set the config parameters of thisLdapusing the supplied input stream.voidmodifyAttributes(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.voidmodifyAttributes(java.lang.String dn, javax.naming.directory.ModificationItem[] mods)This will modify the supplied dn using the supplied modifications.voidrename(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.voidsetLdapConfig(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 newLdapwith the suppliedLdapConfig.- Parameters:
ldapConfig-LdapConfig
-
-
Method Detail
-
setLdapConfig
public void setLdapConfig(LdapConfig ldapConfig)
This will set the config parameters of thisLdap.- Overrides:
setLdapConfigin classAbstractLdap<LdapConfig>- Parameters:
ldapConfig-LdapConfig
-
getLdapConfig
public LdapConfig getLdapConfig()
This returns theLdapConfigof theLdap.- Returns:
LdapConfig
-
loadFromProperties
public void loadFromProperties()
This will set the config parameters of thisLdapusing 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 thisLdapusing 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-SearchFilterexpression 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.NamingExceptionThis will perform an LDAP compare operation with the supplied filter and dn.- Parameters:
dn-Stringname to comparefilter-SearchFilterexpression 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-SearchFilterexpression 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-SearchFilterexpression 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-SearchFilterexpression to use for the searchsearchControls-SearchControlsto 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.NamingExceptionThis 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-Stringname to begin search atfilter-SearchFilterexpression 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.NamingExceptionThis 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-Stringname to begin search atfilter-SearchFilterexpression 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.NamingExceptionThis will query the LDAP with the supplied dn, filter, and search controls. Seesearch(String,SearchFilter,SearchControls,SearchResultHandler[]).- Parameters:
dn-Stringname to begin search atfilter-SearchFilterexpression to use for the searchsearchControls-SearchControlsto 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.NamingExceptionThis 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-Stringname to begin search atfilter-SearchFilterexpression 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.NamingExceptionThis 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-Stringname to begin search atfilter-SearchFilterexpression to use for the searchsearchControls-SearchControlsto 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.NamingExceptionThis 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-Attributesattributes 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.NamingExceptionThis 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-Attributesattributes 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.NamingExceptionThis will query the LDAP for the supplied dn and matching attributes. All attributes will be returned. SeesearchAttributes(String, Attributes, String[]).- Parameters:
dn-Stringname to search inmatchAttrs-Attributesattributes 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.NamingExceptionThis 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-Stringname to search inmatchAttrs-Attributesattributes 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.NamingExceptionThis will query the LDAP for the supplied dn, matching attributes and return attributes. This method will always perform a one level search. The resultingIteratoris 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:
searchAttributesin classAbstractLdap<LdapConfig>- Parameters:
dn-Stringname to search inmatchAttrs-Attributesattributes 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.NamingExceptionThis will enumerate the names bounds to the specified context, along with the class names of objects bound to them. The resultingIteratoris a deep copy of the original search results. SeeContext.list(String).- Overrides:
listin classAbstractLdap<LdapConfig>- Parameters:
dn-StringLDAP 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.NamingExceptionThis will enumerate the names bounds to the specified context, along with the objects bound to them. The resultingIteratoris a deep copy of the original search results. SeeContext.listBindings(String).- Overrides:
listBindingsin classAbstractLdap<LdapConfig>- Parameters:
dn-StringLDAP 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.NamingExceptionThis will return all the attributes associated with the supplied dn. SeegetAttributes(String, String[]).- Parameters:
dn-Stringnamed 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.NamingExceptionThis 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-Stringnamed 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.NamingExceptionThis 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:
getAttributesin classAbstractLdap<LdapConfig>- Parameters:
dn-Stringnamed 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.NamingExceptionThis will return the LDAP schema associated with the supplied dn. The resultingIteratoris a deep copy of the original search results. Seejavax.naming.DirContext#getSchema(String).- Overrides:
getSchemain classAbstractLdap<LdapConfig>- Parameters:
dn-Stringnamed 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.NamingExceptionThis will modify the supplied attributes for the supplied value given by the modification operation. SeeAbstractLdap.modifyAttributes(String, int, Attributes).- Parameters:
dn-Stringnamed object in the LDAPmod-AttributeModificationmodification operationattrs-Attributesattributes 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.NamingExceptionThis 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:
modifyAttributesin classAbstractLdap<LdapConfig>- Parameters:
dn-Stringnamed 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.NamingExceptionThis 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:
createin classAbstractLdap<LdapConfig>- Parameters:
dn-Stringnamed object in the LDAPattrs-Attributesattributes 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.NamingExceptionThis will rename the supplied dn in the LDAP namespace. SeeContext.rename(String, String).- Overrides:
renamein classAbstractLdap<LdapConfig>- Parameters:
oldDn-Stringobject to renamenewDn-Stringnew name- Throws:
javax.naming.NamingException- if the LDAP returns an error
-
delete
public void delete(java.lang.String dn) throws javax.naming.NamingExceptionThis 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:
deletein classAbstractLdap<LdapConfig>- Parameters:
dn-Stringnamed object in the LDAP- Throws:
javax.naming.NamingException- if the LDAP returns an error
-
getSaslMechanisms
public java.lang.String[] getSaslMechanisms() throws javax.naming.NamingExceptionThis 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.NamingExceptionThis will return a list of controls that this LDAP supports.- Returns:
String[]- supported controls- Throws:
javax.naming.NamingException- if the LDAP returns an error
-
-