org.ldaptive.provider.jndi
Class JndiConnection

java.lang.Object
  extended by org.ldaptive.provider.jndi.JndiConnection
All Implemented Interfaces:
ProviderConnection
Direct Known Subclasses:
JndiStartTLSConnection

public class JndiConnection
extends Object
implements ProviderConnection

JNDI provider implementation of ldap operations.

Version:
$Revision: 3211 $ $Date: 2016-11-08 11:47:09 -0500 (Tue, 08 Nov 2016) $
Author:
Middleware Services

Nested Class Summary
protected static class JndiConnection.JndiExtendedRequest
          Class for exposing extended request properties.
protected static class JndiConnection.JndiExtendedResponse
          Class for exposing extended response properties.
protected  class JndiConnection.JndiSearchIterator
          Search iterator for JNDI naming enumeration.
 
Field Summary
static String AUTHENTICATION
          The value of this property is a string that specifies the authentication mechanism(s) for the provider to use.
static String BINARY_ATTRIBUTES
          The value of this property is a string that specifies additional binary attributes.
static String CREDENTIALS
          The value of this property is an object that specifies the credentials of the principal to be authenticated.
static String DELETE_RDN
          The value of this property is a string that specifies whether the RDN attribute should be deleted for a modify dn operation.
static String DEREF_ALIASES
          The value of this property is a string that specifies how aliases shall be handled by the provider.
protected  org.slf4j.Logger logger
          Logger for this class.
static String PRINCIPAL
          The value of this property is a string that specifies the identity of the principal to be authenticated.
static String REFERRAL
          The value of this property is a string that specifies how referrals shall be handled by the provider.
static String SASL_AUTHZ_ID
          The value of this property is a string that specifies the sasl authorization id.
static String SASL_MUTUAL_AUTH
          The value of this property is a string that specifies the sasl mutual authentication flag.
static String SASL_QOP
          The value of this property is a string that specifies the sasl quality of protection.
static String SASL_REALM
          The value of this property is a string that specifies the sasl realm.
static String SASL_STRENGTH
          The value of this property is a string that specifies the sasl security strength.
static String TYPES_ONLY
          The value of this property is a string that specifies to only return attribute type names, no values.
 
Constructor Summary
JndiConnection(LdapContext lc, JndiProviderConfig pc)
          Creates a new jndi connection.
 
Method Summary
 void abandon(int messageId, RequestControl[] controls)
          Abandon an operation.
 Response<Void> add(AddRequest request)
          Add an entry to an ldap.
 void addUnsolicitedNotificationListener(UnsolicitedNotificationListener listener)
          Adds a listener to receive unsolicited notifications.
protected  Response<Void> anonymousBind(BindRequest request)
          Performs an anonymous bind.
 Response<Void> bind(BindRequest request)
          Bind to the ldap.
 void close(RequestControl[] controls)
          Tear down this connection to an LDAP.
 Response<Boolean> compare(CompareRequest request)
          Compare an entry in the ldap.
protected
<T> Response<T>
createResponse(Request request, T result, NamingException e, String[] urls, LdapContext ctx)
          Creates an operation response with the supplied referral response data.
protected
<T> Response<T>
createResponse(Request request, T result, ResultCode code, String[] urls, LdapContext ctx)
          Creates an operation response with the supplied response data.
 Response<Void> delete(DeleteRequest request)
          Delete an entry in the ldap.
 Response<?> extendedOperation(ExtendedRequest request)
          Perform an extended operation in the ldap.
static SearchControls getCompareSearchControls()
          Returns a search controls object configured to perform an LDAP compare operation.
 LdapContext getLdapContext()
          Returns the underlying ldap context.
protected static Map<String,Object> getSaslProperties(SaslConfig config)
          Returns the JNDI properties for the supplied sasl configuration.
protected  LdapContext initializeContext(Request request)
          Creates a new ldap context using LdapContext.newInstance(Control[]).
 Response<Void> modify(ModifyRequest request)
          Modify an entry in the ldap.
 Response<Void> modifyDn(ModifyDnRequest request)
          Modify the DN of an entry in the ldap.
protected  void processNamingException(Request request, NamingException e, String[] urls, LdapContext ctx)
          Determines if the supplied naming exception should result in an operation retry.
protected  ResponseControl[] processResponseControls(ControlProcessor<Control> processor, RequestControl[] requestControls, LdapContext ctx)
          Retrieves the response controls from the supplied context and processes them with the supplied control processor.
 void removeUnsolicitedNotificationListener(UnsolicitedNotificationListener listener)
          Removes a listener from receiving unsolicited notifications.
protected  Response<Void> saslBind(BindRequest request)
          Performs a sasl bind.
 SearchIterator search(SearchRequest request)
          Search the ldap.
 void searchAsync(SearchRequest request, SearchListener listener)
          Search the ldap asynchronously.
protected  Response<Void> simpleBind(BindRequest request)
          Performs a simple bind.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTHENTICATION

public static final String AUTHENTICATION
The value of this property is a string that specifies the authentication mechanism(s) for the provider to use. The value of this constant is "java.naming.security.authentication".

See Also:
Constant Field Values

CREDENTIALS

public static final String CREDENTIALS
The value of this property is an object that specifies the credentials of the principal to be authenticated. The value of this constant is "java.naming.security.credentials".

See Also:
Constant Field Values

PRINCIPAL

public static final String PRINCIPAL
The value of this property is a string that specifies the identity of the principal to be authenticated. The value of this constant is "java.naming.security.principal".

See Also:
Constant Field Values

SASL_AUTHZ_ID

public static final String SASL_AUTHZ_ID
The value of this property is a string that specifies the sasl authorization id. The value of this constant is "java.naming.security.sasl.authorizationId".

See Also:
Constant Field Values

SASL_QOP

public static final String SASL_QOP
The value of this property is a string that specifies the sasl quality of protection. The value of this constant is "javax.security.sasl.qop".

See Also:
Constant Field Values

SASL_STRENGTH

public static final String SASL_STRENGTH
The value of this property is a string that specifies the sasl security strength. The value of this constant is "javax.security.sasl.strength".

See Also:
Constant Field Values

SASL_MUTUAL_AUTH

public static final String SASL_MUTUAL_AUTH
The value of this property is a string that specifies the sasl mutual authentication flag. The value of this constant is "javax.security.sasl.server.authentication".

See Also:
Constant Field Values

SASL_REALM

public static final String SASL_REALM
The value of this property is a string that specifies the sasl realm. The value of this constant is "java.naming.security.sasl.realm".

See Also:
Constant Field Values

DELETE_RDN

public static final String DELETE_RDN
The value of this property is a string that specifies whether the RDN attribute should be deleted for a modify dn operation. The value of this constant is "java.naming.ldap.deleteRDN".

See Also:
Constant Field Values

BINARY_ATTRIBUTES

public static final String BINARY_ATTRIBUTES
The value of this property is a string that specifies additional binary attributes. The value of this constant is "java.naming.ldap.attributes.binary".

See Also:
Constant Field Values

DEREF_ALIASES

public static final String DEREF_ALIASES
The value of this property is a string that specifies how aliases shall be handled by the provider. The value of this constant is "java.naming.ldap.derefAliases".

See Also:
Constant Field Values

REFERRAL

public static final String REFERRAL
The value of this property is a string that specifies how referrals shall be handled by the provider. The value of this constant is "java.naming.referral".

See Also:
Constant Field Values

TYPES_ONLY

public static final String TYPES_ONLY
The value of this property is a string that specifies to only return attribute type names, no values. The value of this constant is "java.naming.ldap.typesOnly".

See Also:
Constant Field Values

logger

protected final org.slf4j.Logger logger
Logger for this class.

Constructor Detail

JndiConnection

public JndiConnection(LdapContext lc,
                      JndiProviderConfig pc)
Creates a new jndi connection.

Parameters:
lc - ldap context
pc - provider configuration
Method Detail

getLdapContext

public LdapContext getLdapContext()
Returns the underlying ldap context.

Returns:
ldap context

close

public void close(RequestControl[] controls)
           throws LdapException
Tear down this connection to an LDAP.

Specified by:
close in interface ProviderConnection
Parameters:
controls - request controls
Throws:
LdapException - if an LDAP error occurs

bind

public Response<Void> bind(BindRequest request)
                    throws LdapException
Bind to the ldap.

Specified by:
bind in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
Returns:
response associated with the bind operation
Throws:
LdapException - if an error occurs

anonymousBind

protected Response<Void> anonymousBind(BindRequest request)
                                throws LdapException
Performs an anonymous bind.

Parameters:
request - to bind with
Returns:
bind response
Throws:
LdapException - if an error occurs

simpleBind

protected Response<Void> simpleBind(BindRequest request)
                             throws LdapException
Performs a simple bind.

Parameters:
request - to bind with
Returns:
bind response
Throws:
LdapException - if an error occurs

saslBind

protected Response<Void> saslBind(BindRequest request)
                           throws LdapException
Performs a sasl bind.

Parameters:
request - to bind with
Returns:
bind response
Throws:
LdapException - if an error occurs

add

public Response<Void> add(AddRequest request)
                   throws LdapException
Add an entry to an ldap.

Specified by:
add in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
Returns:
response associated with the add operation
Throws:
LdapException - if an error occurs

compare

public Response<Boolean> compare(CompareRequest request)
                          throws LdapException
Compare an entry in the ldap.

Specified by:
compare in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
Returns:
response associated with the compare operation
Throws:
LdapException - if an error occurs

delete

public Response<Void> delete(DeleteRequest request)
                      throws LdapException
Delete an entry in the ldap.

Specified by:
delete in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
Returns:
response associated with the delete operation
Throws:
LdapException - if an error occurs

modify

public Response<Void> modify(ModifyRequest request)
                      throws LdapException
Modify an entry in the ldap.

Specified by:
modify in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
Returns:
response associated with the modify operation
Throws:
LdapException - if an error occurs

modifyDn

public Response<Void> modifyDn(ModifyDnRequest request)
                        throws LdapException
Modify the DN of an entry in the ldap.

Specified by:
modifyDn in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
Returns:
response associated with the modify dn operation
Throws:
LdapException - if an error occurs

search

public SearchIterator search(SearchRequest request)
                      throws LdapException
Search the ldap.

Specified by:
search in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
Returns:
search iterator
Throws:
LdapException - if an error occurs

searchAsync

public void searchAsync(SearchRequest request,
                        SearchListener listener)
                 throws LdapException
Search the ldap asynchronously.

Specified by:
searchAsync in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
listener - to be notified as results arrive
Throws:
LdapException - if an error occurs

abandon

public void abandon(int messageId,
                    RequestControl[] controls)
             throws LdapException
Abandon an operation.

Specified by:
abandon in interface ProviderConnection
Parameters:
messageId - of the operation to abandon
controls - request controls
Throws:
LdapException - if an error occurs

extendedOperation

public Response<?> extendedOperation(ExtendedRequest request)
                              throws LdapException
Perform an extended operation in the ldap.

Specified by:
extendedOperation in interface ProviderConnection
Parameters:
request - containing the data necessary to perform the operation
Returns:
response associated with the extended operation
Throws:
LdapException - if an error occurs

addUnsolicitedNotificationListener

public void addUnsolicitedNotificationListener(UnsolicitedNotificationListener listener)
Adds a listener to receive unsolicited notifications.

Specified by:
addUnsolicitedNotificationListener in interface ProviderConnection
Parameters:
listener - to receive unsolicited notifications

removeUnsolicitedNotificationListener

public void removeUnsolicitedNotificationListener(UnsolicitedNotificationListener listener)
Removes a listener from receiving unsolicited notifications.

Specified by:
removeUnsolicitedNotificationListener in interface ProviderConnection
Parameters:
listener - that was registered to receive unsolicited notifications

getCompareSearchControls

public static SearchControls getCompareSearchControls()
Returns a search controls object configured to perform an LDAP compare operation.

Returns:
search controls

initializeContext

protected LdapContext initializeContext(Request request)
                                 throws NamingException
Creates a new ldap context using LdapContext.newInstance(Control[]). Adds any additional environment properties found in the supplied request to the context.

Parameters:
request - to read properties from
Returns:
ldap context
Throws:
NamingException - if a property cannot be added to the context

createResponse

protected <T> Response<T> createResponse(Request request,
                                         T result,
                                         ResultCode code,
                                         String[] urls,
                                         LdapContext ctx)
Creates an operation response with the supplied response data.

Type Parameters:
T - type of response
Parameters:
request - containing controls
result - of the operation
code - operation result code
urls - referral urls
ctx - ldap context
Returns:
operation response

createResponse

protected <T> Response<T> createResponse(Request request,
                                         T result,
                                         NamingException e,
                                         String[] urls,
                                         LdapContext ctx)
Creates an operation response with the supplied referral response data.

Type Parameters:
T - type of response
Parameters:
request - containing controls
result - of the operation
e - naming exception produced by the operation
urls - referral urls
ctx - ldap context
Returns:
operation response

processNamingException

protected void processNamingException(Request request,
                                      NamingException e,
                                      String[] urls,
                                      LdapContext ctx)
                               throws LdapException
Determines if the supplied naming exception should result in an operation retry.

Parameters:
request - that produced the exception
e - that was produced
urls - referral urls
ctx - that the exception occurred on
Throws:
LdapException - wrapping the naming exception

processResponseControls

protected ResponseControl[] processResponseControls(ControlProcessor<Control> processor,
                                                    RequestControl[] requestControls,
                                                    LdapContext ctx)
Retrieves the response controls from the supplied context and processes them with the supplied control processor. Logs a warning if controls cannot be retrieved.

Parameters:
processor - control processor
requestControls - that produced this response
ctx - to get controls from
Returns:
response controls

getSaslProperties

protected static Map<String,Object> getSaslProperties(SaslConfig config)
Returns the JNDI properties for the supplied sasl configuration.

Parameters:
config - sasl configuration
Returns:
JNDI properties for use in a context environment


Copyright © 2003-2017 Virginia Tech. All Rights Reserved.