Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
support aot compilation
  • Loading branch information
clayton committed Jun 12, 2017
1 parent 804ee03 commit 43d8a01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion 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"
Expand Down
25 changes: 15 additions & 10 deletions src/main/clojure/de/mpg/shh/util_ldap/ldap.clj
Expand Up @@ -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"})

Expand All @@ -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)
Expand All @@ -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]
Expand Down Expand Up @@ -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))]
Expand Down

0 comments on commit 43d8a01

Please sign in to comment.