public class SingleContextSource extends Object implements ContextSource, DisposableBean
ContextSource to be used as a decorator around a target ContextSource
to make sure the target is never actually closed. Useful when working with e.g. paged results,
as these require the same target to be used.| Modifier and Type | Class and Description |
|---|---|
static class |
SingleContextSource.NonClosingDirContextInvocationHandler
A proxy for DirContext forwarding all operation to the target DirContext,
but making sure that no
close operations will be performed. |
| Constructor and Description |
|---|
SingleContextSource(DirContext ctx)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Destroy method that allows the target DirContext to be cleaned up when
the SingleContextSource is not going to be used any more.
|
static <T> T |
doWithSingleContext(ContextSource contextSource,
LdapOperationsCallback<T> callback)
Construct a SingleContextSource and execute the LdapOperationsCallback using the created instance.
|
static <T> T |
doWithSingleContext(ContextSource contextSource,
LdapOperationsCallback<T> callback,
boolean useReadOnly,
boolean ignorePartialResultException,
boolean ignoreNameNotFoundException)
Construct a SingleContextSource and execute the LdapOperationsCallback using the created instance.
|
DirContext |
getContext(String principal,
String credentials)
Gets a
DirContext instance authenticated using the supplied
principal and credentials. |
DirContext |
getReadOnlyContext()
Gets a read-only
DirContext. |
DirContext |
getReadWriteContext()
Gets a read-write
DirContext instance. |
public SingleContextSource(DirContext ctx)
ctx - the target DirContext.public DirContext getReadOnlyContext()
ContextSourceDirContext. The returned
DirContext must be possible to perform read-only operations
on.getReadOnlyContext in interface ContextSourcepublic DirContext getReadWriteContext()
ContextSourceDirContext instance.getReadWriteContext in interface ContextSourceDirContext instance, never null.public DirContext getContext(String principal, String credentials)
ContextSourceDirContext instance authenticated using the supplied
principal and credentials. Typically to be used for plain authentication
purposes. Note that this method will never make use
of native Java LDAP pooling, even though this instance is configured to do so.
This is to force password changes in the target directory to take effect
as soon as possible.getContext in interface ContextSourceprincipal - The principal (typically a distinguished name of a user
in the LDAP tree) to use for authentication.credentials - The credentials to use for authentication.DirContext instance, never
null.public void destroy()
destroy in interface DisposableBeanpublic static <T> T doWithSingleContext(ContextSource contextSource, LdapOperationsCallback<T> callback)
By default, the ContextSource.getReadWriteContext() method
will be used to create the DirContext instance to operate on.
contextSource - The target ContextSource to retrieve a DirContext from.callback - the callback to perform the Ldap operations.doWithSingleContext(org.springframework.ldap.core.ContextSource, LdapOperationsCallback, boolean, boolean, boolean)public static <T> T doWithSingleContext(ContextSource contextSource, LdapOperationsCallback<T> callback, boolean useReadOnly, boolean ignorePartialResultException, boolean ignoreNameNotFoundException)
contextSource - The target ContextSource to retrieve a DirContext fromcallback - the callback to perform the Ldap operationsuseReadOnly - if true, use the ContextSource.getReadOnlyContext()
method on the target ContextSource to get the actual DirContext instance, if false,
use ContextSource.getReadWriteContext().ignorePartialResultException - Used for populating this property on the created LdapTemplate instance.ignoreNameNotFoundException - Used for populating this property on the created LdapTemplate instance.