edu.vt.middleware.ldap
T
- type of LdapConfigpublic abstract class AbstractLdap<T extends LdapConfig> extends java.lang.Object implements BaseLdap
AbstractLdap
contains the functions for basic interaction with a
LDAP. Methods are provided for connecting, binding, querying and updating.Modifier and Type | Field and Description |
---|---|
protected static CopyResultHandler<javax.naming.Binding> |
BINDING_COPY_RESULT_HANDLER
Default copy binding handler.
|
protected T |
config
LDAP configuration environment.
|
protected ConnectionHandler |
connectionHandler
LDAP connection handler.
|
protected static CopyResultHandler<java.lang.Object> |
COPY_RESULT_HANDLER
Default copy result handler.
|
protected org.apache.commons.logging.Log |
logger
Log for this class.
|
protected static CopyResultHandler<javax.naming.NameClassPair> |
NCP_COPY_RESULT_HANDLER
Default copy name class pair handler.
|
protected static CopyResultHandler<javax.naming.directory.SearchResult> |
SR_COPY_RESULT_HANDLER
Default copy search result handler, used if none supplied.
|
Constructor and Description |
---|
AbstractLdap() |
Modifier and Type | Method and Description |
---|---|
void |
close()
This will close the connection to the LDAP.
|
protected boolean |
compare(java.lang.String dn,
java.lang.String filter,
java.lang.Object[] filterArgs)
This will perform an LDAP compare operation with the supplied filter and
dn.
|
boolean |
connect()
This will establish a connection if one does not already exist by binding
to the LDAP using parameters given by
LdapConfig.getBindDn() and
LdapConfig.getBindCredential() . |
protected 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.
|
protected void |
delete(java.lang.String dn)
This will delete the supplied dn from the LDAP namespace.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
protected 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.
|
protected javax.naming.ldap.LdapContext |
getContext()
This will return an initialized connection to the LDAP.
|
protected java.util.Iterator<javax.naming.directory.SearchResult> |
getSchema(java.lang.String dn)
This will return the LDAP schema associated with the supplied dn.
|
protected 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.
|
protected 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.
|
protected void |
modifyAttributes(java.lang.String dn,
int modOp,
javax.naming.directory.Attributes attrs)
This will modify the supplied attributes for the supplied value given by
the modification operation.
|
protected void |
modifyAttributes(java.lang.String dn,
javax.naming.directory.ModificationItem[] mods)
This will modify the supplied dn using the supplied modifications.
|
protected void |
operationRetry(javax.naming.ldap.LdapContext ctx,
javax.naming.NamingException e,
int count)
Confirms whether the supplied exception matches an exception from
LdapConfig.getOperationRetryExceptions() and the supplied count is less
than LdapConfig.getOperationRetry() . |
protected java.util.Iterator<javax.naming.directory.SearchResult> |
pagedSearch(java.lang.String dn,
java.lang.String filter,
java.lang.Object[] filterArgs,
javax.naming.directory.SearchControls searchControls,
SearchResultHandler... handler)
This will query the LDAP with the supplied dn, filter, filter arguments,
and search controls.
|
boolean |
reconnect()
This will close the current connection to the LDAP and establish a new
connection to the LDAP using
connect() . |
protected void |
rename(java.lang.String oldDn,
java.lang.String newDn)
This will rename the supplied dn in the LDAP namespace.
|
protected java.util.Iterator<javax.naming.directory.SearchResult> |
search(java.lang.String dn,
java.lang.String filter,
java.lang.Object[] filterArgs,
javax.naming.directory.SearchControls searchControls,
SearchResultHandler... handler)
This will query the LDAP with the supplied dn, filter, filter arguments,
and search controls.
|
protected 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.
|
protected void |
setLdapConfig(T ldapConfig)
This will set the config parameters of this
Ldap . |
java.lang.String |
toString()
Provides a descriptive string representation of this instance.
|
protected static final CopyResultHandler<javax.naming.directory.SearchResult> SR_COPY_RESULT_HANDLER
protected static final CopyResultHandler<javax.naming.NameClassPair> NCP_COPY_RESULT_HANDLER
protected static final CopyResultHandler<javax.naming.Binding> BINDING_COPY_RESULT_HANDLER
protected static final CopyResultHandler<java.lang.Object> COPY_RESULT_HANDLER
protected final org.apache.commons.logging.Log logger
protected ConnectionHandler connectionHandler
protected T extends LdapConfig config
protected void setLdapConfig(T ldapConfig)
Ldap
.ldapConfig
- LdapConfig
protected boolean compare(java.lang.String dn, java.lang.String filter, java.lang.Object[] filterArgs) throws javax.naming.NamingException
dn
- String
name to comparefilter
- String
expression to use for comparefilterArgs
- Object[]
to substitute for variables in
the filterboolean
- result of compare operationjavax.naming.NamingException
- if the LDAP returns an errorprotected java.util.Iterator<javax.naming.directory.SearchResult> search(java.lang.String dn, java.lang.String filter, java.lang.Object[] filterArgs, javax.naming.directory.SearchControls searchControls, SearchResultHandler... handler) throws javax.naming.NamingException
Iterator
is a
deep copy of the original search results. If filterArgs is null, then no
variable substitution will occur. See javax.naming.DirContext#search( String, String, Object[], SearchControls)
.dn
- String
name to begin search atfilter
- String
expression to use for the searchfilterArgs
- Object[]
to substitute for variables in
the filtersearchControls
- SearchControls
to perform search withhandler
- SearchResultHandler[]
to post process resultsIterator
- of LDAP search resultsjavax.naming.NamingException
- if the LDAP returns an errorprotected java.util.Iterator<javax.naming.directory.SearchResult> pagedSearch(java.lang.String dn, java.lang.String filter, java.lang.Object[] filterArgs, javax.naming.directory.SearchControls searchControls, SearchResultHandler... handler) throws javax.naming.NamingException
search(String, String, Object[],
SearchControls, SearchResultHandler...)
. The PagedResultsControl is used
in conjunction with LdapConfig.getPagedResultsSize()
to produce the
results.dn
- String
name to begin search atfilter
- String
expression to use for the searchfilterArgs
- Object[]
to substitute for variables in
the filtersearchControls
- SearchControls
to perform search withhandler
- SearchResultHandler[]
to post process resultsIterator
- of LDAP search resultsjavax.naming.NamingException
- if the LDAP returns an errorprotected 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
Iterator
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. See javax.naming.DirContext#search(String, Attributes,
String[])
.dn
- String
name to search inmatchAttrs
- Attributes
attributes to matchretAttrs
- String[]
attributes to returnhandler
- SearchResultHandler[]
to post process resultsIterator
- of LDAP search resultsjavax.naming.NamingException
- if the LDAP returns an errorprotected java.util.Iterator<javax.naming.NameClassPair> list(java.lang.String dn) throws javax.naming.NamingException
Iterator
is a deep copy of the original search results. See Context.list(String)
.dn
- String
LDAP context to listIterator
- LDAP search resultjavax.naming.NamingException
- if the LDAP returns an errorprotected java.util.Iterator<javax.naming.Binding> listBindings(java.lang.String dn) throws javax.naming.NamingException
Iterator
is a deep
copy of the original search results. See Context.listBindings(String)
.dn
- String
LDAP context to listIterator
- LDAP search resultjavax.naming.NamingException
- if the LDAP returns an errorprotected javax.naming.directory.Attributes getAttributes(java.lang.String dn, java.lang.String[] retAttrs, AttributeHandler... handler) throws javax.naming.NamingException
javax.naming.DirContext#getAttributes(String, String[])
.dn
- String
named object in the LDAPretAttrs
- String[]
attributes to returnhandler
- AttributeHandler[]
to post process resultsAttributes
javax.naming.NamingException
- if the LDAP returns an errorprotected java.util.Iterator<javax.naming.directory.SearchResult> getSchema(java.lang.String dn) throws javax.naming.NamingException
Iterator
is a deep copy of the original search
results. See javax.naming.DirContext#getSchema(String)
.dn
- String
named object in the LDAPIterator
- LDAP search resultjavax.naming.NamingException
- if the LDAP returns an errorprotected void modifyAttributes(java.lang.String dn, int modOp, javax.naming.directory.Attributes attrs) throws javax.naming.NamingException
javax.naming.DirContext#modifyAttributes( String, int, Attributes)
.dn
- String
named object in the LDAPmodOp
- int
modification operationattrs
- Attributes
attributes to be used for the
operation, may be nulljavax.naming.NamingException
- if the LDAP returns an errorprotected void modifyAttributes(java.lang.String dn, javax.naming.directory.ModificationItem[] mods) throws javax.naming.NamingException
javax.naming.DirContext#modifyAttributes(String,
ModificationItem[])
.dn
- String
named object in the LDAPmods
- ModificationItem[]
modificationsjavax.naming.NamingException
- if the LDAP returns an errorprotected void create(java.lang.String dn, javax.naming.directory.Attributes attrs) throws javax.naming.NamingException
javax.naming.DirContext#createSubcontext(String,
Attributes)
. Note that the context created by this operation is
immediately closed.dn
- String
named object in the LDAPattrs
- Attributes
attributes to be added to this entryjavax.naming.NamingException
- if the LDAP returns an errorprotected void rename(java.lang.String oldDn, java.lang.String newDn) throws javax.naming.NamingException
Context.rename(String, String)
.oldDn
- String
object to renamenewDn
- String
new namejavax.naming.NamingException
- if the LDAP returns an errorprotected void delete(java.lang.String dn) throws javax.naming.NamingException
Context.destroySubcontext(String)
.dn
- String
named object in the LDAPjavax.naming.NamingException
- if the LDAP returns an errorpublic boolean connect() throws javax.naming.NamingException
LdapConfig.getBindDn()
and
LdapConfig.getBindCredential()
. If these parameters have not been
set then an anonymous bind will be attempted. This connection must be
closed using close()
. Any method which requires an LDAP connection
will call this method independently. This method should only be used if you
need to verify that you can connect to the LDAP.public boolean reconnect() throws javax.naming.NamingException
connect()
.public void close()
protected javax.naming.ldap.LdapContext getContext() throws javax.naming.NamingException
LdapContext
javax.naming.NamingException
- if the LDAP returns an errorprotected void operationRetry(javax.naming.ldap.LdapContext ctx, javax.naming.NamingException e, int count) throws javax.naming.NamingException
LdapConfig.getOperationRetryExceptions()
and the supplied count is less
than LdapConfig.getOperationRetry()
. LdapConfig.getOperationRetryWait()
is used in conjunction with LdapConfig.getOperationRetryBackoff()
to delay retries. Calls close()
if no exception is thrown, which allows the client to reconnect
when the operation is performed again.ctx
- LdapContext
that performed the operatione
- NamingException
that was throwncount
- int
operation attemptsjavax.naming.NamingException
- if the operation won't be retriedpublic java.lang.String toString()
toString
in class java.lang.Object
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- if an exception is thrown by this methodCopyright © 2014. All Rights Reserved.