From 43d8a01fec448bd3f9b047d9ab5df57693306ce3 Mon Sep 17 00:00:00 2001 From: Stephen Clayton Date: Mon, 12 Jun 2017 08:16:30 +0200 Subject: [PATCH] support aot compilation --- project.clj | 2 +- .../clojure/de/mpg/shh/util_ldap/ldap.clj | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/project.clj b/project.clj index e2a2a02..73c09df 100755 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject de.mpg.shh/util-ldap "0.0.6" +(defproject de.mpg.shh/util-ldap "0.0.7" :description "Read from active directory" :url "http://www.shh.mpg.de/" :license {:name "Eclipse Public License" diff --git a/src/main/clojure/de/mpg/shh/util_ldap/ldap.clj b/src/main/clojure/de/mpg/shh/util_ldap/ldap.clj index 98a5bda..5bce4fa 100644 --- a/src/main/clojure/de/mpg/shh/util_ldap/ldap.clj +++ b/src/main/clojure/de/mpg/shh/util_ldap/ldap.clj @@ -11,13 +11,18 @@ (def properties (delay (load-properties "shh-auth.properties"))) -(def ldap-host (if-let [host (get-in @properties [:ldap :host])] host (throw (Exception. "No configuration found for ldap.host check resources/shh-auth.properties")))) -(def ldap-port (if-let [port (get-in @properties [:ldap :port])] - (try - (java.lang.Long/valueOf port) - (catch NumberFormatException nfe - (throw (Exception. "Not a number check ldap.port in resources/shh-auth.properties")))) - (throw (Exception. "No configuration found for ldap.port check resources/shh-auth.properties")))) +(defn get-ldap-host + [] + (if-let [host (get-in @properties [:ldap :host])] host (throw (Exception. "No configuration found for ldap.host check resources/shh-auth.properties")))) + +(defn get-ldap-port + [] + (if-let [port (get-in @properties [:ldap :port])] + (try + (java.lang.Long/valueOf port) + (catch NumberFormatException nfe + (throw (Exception. "Not a number check ldap.port in resources/shh-auth.properties")))) + (throw (Exception. "No configuration found for ldap.port check resources/shh-auth.properties")))) (def user-attributes #{"cn" "sn" "mail" "memberOf"}) @@ -29,7 +34,7 @@ (try (do (doto ldap-conn - (.connect ldap-host ldap-port) + (.connect (get-ldap-host) (get-ldap-port)) (.startTLS) (.bind LDAPConnection/LDAP_V3 username (.getBytes password))) true) @@ -49,7 +54,7 @@ lc-attr (str/lower-case attr)] (if (contains? accumulator lc-attr) (update accumulator lc-attr conj value) - (assoc accumulator lc-attr [value])))) + (assoc accumulator lc-attr [value])))) (defn attributes->map [attributes] @@ -105,7 +110,7 @@ (try (let [ldap-result (-> (doto ldap-conn (.setConstraints search-constraints) - (.connect ldap-host ldap-port) + (.connect (get-ldap-host) (get-ldap-port)) (.startTLS) (.bind LDAPConnection/LDAP_V3 username (.getBytes password))) (.search "ou=dag,dc=shh,dc=mpg,dc=de" LDAPConnection/SCOPE_SUB "(objectclass=user)" (into-array String user-attributes) false))]