Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added reconnect and timeout options

  • Loading branch information...
commit dd66496136c74ec77a045c3727529edad8ed68ce 1 parent 5beae4f
@alienscience authored
View
6 README.md
@@ -36,6 +36,12 @@ Options is a map with the following entries:
:trust-store Only trust SSL certificates that are in this
JKS format file, optional, defaults to trusting all
certificates
+ :reconnect? Boolean, automatically reopen closed connections,
+ defaults to false
+ :connect-timeout The timeout for making connections (milliseconds),
+ defaults to 1 minute
+ :timeout The timeout when waiting for a response from the server
+ (milliseconds), defaults to 5 minutes
For example:
(ldap/connect conn {:address "ldap.example.com" :num-connections 10})
View
42 src/clj_ldap/client.clj
@@ -5,6 +5,7 @@
(:require [clojure.string :as string])
(:import [com.unboundid.ldap.sdk
LDAPResult
+ LDAPConnectionOptions
LDAPConnection
ResultCode
LDAPConnectionPool
@@ -24,16 +25,23 @@
(defn- create-connection
"Create an LDAPConnection object"
- [address port ssl? trust-store]
- (if ssl?
- (let [trust-manager (if trust-store
- (TrustStoreTrustManager. trust-store)
- (TrustAllTrustManager.))
- ssl-util (SSLUtil. trust-manager)]
- (LDAPConnection. (.createSSLSocketFactory ssl-util)
- address
- (or port 636)))
- (LDAPConnection. address (or port 389))))
+ [{:keys [address port ssl? trust-store
+ reconnect? connect-timeout timeout]}]
+ (let [host (or address "localhost")
+ opt (LDAPConnectionOptions.)]
+ (when reconnect? (.setAutoReconnect opt true))
+ (when connect-timeout (.setConnectTimeoutMillis opt connect-timeout))
+ (when timeout (.setResponseTimeoutMillis opt timeout))
+ (if ssl?
+ (let [trust-manager (if trust-store
+ (TrustStoreTrustManager. trust-store)
+ (TrustAllTrustManager.))
+ ssl-util (SSLUtil. trust-manager)]
+ (LDAPConnection. (.createSSLSocketFactory ssl-util)
+ opt
+ host
+ (or port 636)))
+ (LDAPConnection. opt host (or port 389)))))
(defn- ldap-result
"Converts an LDAPResult object into a clojure datastructure"
@@ -115,12 +123,16 @@
:trust-store Only trust SSL certificates that are in this
JKS format file, optional, defaults to trusting all
certificates
+ :reconnect? Boolean, automatically reopen closed connections,
+ defaults to false
+ :connect-timeout The timeout for making connections (milliseconds),
+ defaults to 1 minute
+ :timeout The timeout when waiting for a response from the server
+ (milliseconds), defaults to 5 minutes
"
- [{:keys [address port bind-dn password num-connections
- ssl? trust-store] :as options}]
-
- (let [connection (create-connection (or address "localhost")
- port ssl? trust-store)
+ [options]
+ (let [{:keys [bind-dn password num-connections]} options
+ connection (create-connection options)
bind-result (.bind connection bind-dn password)]
(if (= ResultCode/SUCCESS (.getResultCode bind-result))
(LDAPConnectionPool. connection (or num-connections 1))
View
6 test/clj_ldap/test/client.clj
@@ -56,7 +56,11 @@
(ldap/connect {:address "localhost"
:port port
:num-connections 4})
- (ldap/connect {:ssl? true :port ssl-port})])
+ (ldap/connect {:ssl? true :port ssl-port})
+ (ldap/connect {:port port
+ :reconnect? true
+ :connect-timeout 1000
+ :timeout 5000})])
(defn- test-server
"Setup server"
Please sign in to comment.
Something went wrong with that request. Please try again.