Writing a Simple LDAP ProxyThe OpenDJ LDAP SDK example Proxy demonstrates a simple LDAP proxy that forwards requests
to one or more remote directory servers. Although the implementation is
intended as an example, it does demonstrate use of the asynchronous API,
load balancing, and connection pooling.The Proxy example sets up connections pools with load balancing to the
directory servers. It passes the connection factories to a
ProxyBackend that handles the requests passed back
to the directory servers. It also sets up an LDAP listener to receive incoming
connections from clients of the Proxy.The ProxyBackend uses separate connection factories,
one for bind operations, the other for other operations. It uses the proxied
authorization control to ensure operations are performed using the bind
identity for the operation.The ProxyBackend's function is to handle each client
request, encapsulating the result handlers that allow it to deal with each
basic operation. It authenticates to the directory server to check incoming
credentials, and adds the proxied authorization control to requests other than
binds. The ProxyBackend handles all operations using
asynchronous connections and methods.Connection PoolingAs shown in the Proxy example, the
Connections.newFixedConnectionPool() returns a connection
pool of the maximum size you specify.final List<ConnectionFactory> factories = new LinkedList<ConnectionFactory>();
factories.add(Connections.newFixedConnectionPool(new LDAPConnectionFactory(
remoteAddress, remotePort), Integer.MAX_VALUE));Connections are returned to the pool when you close()
them. Notice that Connections also provides methods to
return ConnectionFactorys with a heart beat check on
connections provided by the factory, and connection factories that
authenticate connections before returning them.Connections in the pool are intended for reuse. Therefore when you
close() a connection from the pool, the OpenDJ LDAP SDK
does not perform an unbind(). You must therefore be careful
about how you manage authentication on connections from a pool. As a rule,
either bind separately and use proxied authorization as in the Proxy example,
or make sure that the first operation on a connection retrieved from the pool
is a bind that correctly authenticates the user currently served by the
connection.Load Balancing & FailoverThe Connections.newLoadBalancer() method returns a
load balancer based on the algorithm you choose. Algorithms include both
round robin for equitably sharing load across local directory servers, and
also failover usually used for switching automatically from an unresponsive
server group to an alternative server group. The algorithms take collections
of connection factories, such as those that you set up for connection
pooling.final RoundRobinLoadBalancingAlgorithm algorithm =
new RoundRobinLoadBalancingAlgorithm(factories);
final ConnectionFactory factory = Connections.newLoadBalancer(algorithm);The algorithms also include constructors that let you adjust timeouts
and so forth.DN & Attribute RewritingTODO