|
Spring LDAP | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.ldap.core.support.AbstractTlsDirContextAuthenticationStrategy
public abstract class AbstractTlsDirContextAuthenticationStrategy
Abstract superclass for DirContextAuthenticationStrategy
implementations that apply TLS security to the connections. The supported TLS
behavior differs between servers. E.g., some servers expect the TLS
connection be shut down gracefully before the actual target context is
closed, whereas other servers do not support that. The
shutdownTlsGracefully
property controls this behavior; the
property defaults to false
.
The SSLSocketFactory
used for TLS negotiation can be customized
using the sslSocketFactory
property. This allows for example a
socket factory that can load the keystore/truststore using the Spring
Resource abstraction. This provides a much more Spring-like strategy for
configuring PKI credentials for authentication, in addition to allowing
application-specific keystores and truststores running in the same JVM.
In some rare occasions there is a need to supply a
HostnameVerifier
to the TLS processing instructions in order to
have the returned certificate properly validated. If a
HostnameVerifier
is supplied to
setHostnameVerifier(HostnameVerifier)
, that will be applied to the
processing.
For further information regarding TLS, refer to this page.
NB: TLS negotiation is an expensive process, which is why you will most likely want to use connection pooling, to make sure new connections are not created for each individual request. It is imperative however, that the built-in LDAP connection pooling is not used in combination with the TLS AuthenticationStrategy implementations - this will not work. You should use the Spring LDAP PoolingContextSource instead.
Constructor Summary | |
---|---|
AbstractTlsDirContextAuthenticationStrategy()
|
Method Summary | |
---|---|
protected abstract void |
applyAuthentication(LdapContext ctx,
String userDn,
String password)
Apply the actual authentication to the specified LdapContext
. |
DirContext |
processContextAfterCreation(DirContext ctx,
String userDn,
String password)
This method is responsible for post-processing the DirContext instance after it has been created. |
void |
setHostnameVerifier(HostnameVerifier hostnameVerifier)
Set the optional HostnameVerifier |
void |
setShutdownTlsGracefully(boolean shutdownTlsGracefully)
Specify whether the TLS should be shut down gracefully before the target context is closed. |
void |
setSslSocketFactory(SSLSocketFactory sslSocketFactory)
Sets the optional SSL socket factory used for startTLS negotiation. |
void |
setupEnvironment(Hashtable env,
String userDn,
String password)
This method is responsible for preparing the environment to be used when creating the DirContext instance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractTlsDirContextAuthenticationStrategy()
Method Detail |
---|
public void setShutdownTlsGracefully(boolean shutdownTlsGracefully)
false
.
shutdownTlsGracefully
- true
to shut down the TLS
connection explicitly, false
closes the target context
immediately.public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
HostnameVerifier to use for verifying incoming certificates. Defaults to null
, meaning that the default hostname verification will take place.
- Parameters:
hostnameVerifier
- The HostnameVerifier
to use, if any.
public void setSslSocketFactory(SSLSocketFactory sslSocketFactory)
null
to indicate that the default socket factory
provided by the underlying JSSE provider should be used.
sslSocketFactory
- SSL socket factory to use, if any.public final void setupEnvironment(Hashtable env, String userDn, String password)
DirContextAuthenticationStrategy
DirContext
instance. The base environment
(including URL, ContextFactory
etc. will already be set,
and this method is called just before the actual Context is to be
created.
setupEnvironment
in interface DirContextAuthenticationStrategy
env
- The Hashtable
to be sent to the
DirContext
instance on initialization. Pre-configured with
the basic settings; the implementation of this method is responsible for
manipulating the environment as appropriate for the particular
authentication mechanism.userDn
- the user DN to authenticate, as received from the
AuthenticationSource
of the ContextSource
.password
- the password to authenticate with, as received from the
AuthenticationSource
of the ContextSource
.public final DirContext processContextAfterCreation(DirContext ctx, String userDn, String password) throws NamingException
DirContextAuthenticationStrategy
DirContext
instance after it has been created. It will be
called immediately after the instance has been created. Some
authentication mechanisms, e.g. TLS, require particular stuff to happen
before the actual target Context is closed. This method provides the
possibility to replace or wrap the actual DirContext with a proxy so that
any calls on it may be intercepted.
processContextAfterCreation
in interface DirContextAuthenticationStrategy
ctx
- the freshly created DirContext
instance. The
actual implementation class (e.g. InitialLdapContext
)
depends on the ContextSource
implementation.userDn
- the user DN to authenticate, as received from the
AuthenticationSource
of the ContextSource
.password
- the password to authenticate with, as received from the
AuthenticationSource
of the ContextSource
.
NamingException
- if anything goes wrong. This will cause the
DirContext
creation to be aborted and the exception to be
translated and rethrown.protected abstract void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException
LdapContext
. Typically, this will involve adding stuff to the environment.
ctx
- the LdapContext
instance.userDn
- the user dn of the user to authenticate.password
- the password of the user to authenticate.
NamingException
- if any error occurs.
|
Spring LDAP | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |