diff --git a/backend/deps.edn b/backend/deps.edn index 3af2bc1fc..c396e0d4a 100644 --- a/backend/deps.edn +++ b/backend/deps.edn @@ -53,7 +53,7 @@ com.draines/postal {:mvn/version "2.0.3" :exclusions [commons-codec/commons-codec]} - org.clojars.pntblnk/clj-ldap {:mvn/version"0.0.16"} + puppetlabs/clj-ldap {:mvn/version"0.3.0"} ;; exception printing io.aviso/pretty {:mvn/version "0.1.37"} diff --git a/backend/src/uxbox/http/auth/ldap.clj b/backend/src/uxbox/http/auth/ldap.clj index 351b851e9..d869cb3f3 100644 --- a/backend/src/uxbox/http/auth/ldap.clj +++ b/backend/src/uxbox/http/auth/ldap.clj @@ -31,10 +31,10 @@ (log/errorf e "Cannot connect to LDAP %s:%s" (:ldap-auth-host cfg/config) (:ldap-auth-port cfg/config))))) :stop (when (realized? *ldap-pool) - (some-> *ldap-pool deref (client/close)))) + (some-> *ldap-pool deref (.close)))) (defn- auth-with-ldap [username password] - (when-let [conn (some-> *ldap-pool deref (client/get-connection))] + (when-some [conn (some-> *ldap-pool deref)] (let [user-search-query (replace-several (:ldap-auth-user-query cfg/config) "$username" username) user-attributes (-> cfg/config @@ -43,21 +43,18 @@ :ldap-auth-fullname-attribute :ldap-auth-avatar-attribute]) vals)] - (try - (when-some [user-entry (-> conn - (client/search - (:ldap-auth-base-dn cfg/config) - {:filter user-search-query - :sizelimit 1 - :attributes user-attributes}) - first)] - (when-not (client/bind? conn (:dn user-entry) password) - (ex/raise :type :authentication - :code ::wrong-credentials)) - (set/rename-keys user-entry {(keyword (:ldap-auth-avatar-attribute cfg/config)) :photo - (keyword (:ldap-auth-fullname-attribute cfg/config)) :fullname - (keyword (:ldap-auth-email-attribute cfg/config)) :email})) - (finally (client/release-connection @*ldap-pool conn)))))) + (when-some [user-entry (-> conn + (client/search (:ldap-auth-base-dn cfg/config) + {:filter user-search-query + :sizelimit 1 + :attributes user-attributes}) + (first))] + (when-not (client/bind? conn (:dn user-entry) password) + (ex/raise :type :authentication + :code ::wrong-credentials)) + (set/rename-keys user-entry {(keyword (:ldap-auth-avatar-attribute cfg/config)) :photo + (keyword (:ldap-auth-fullname-attribute cfg/config)) :fullname + (keyword (:ldap-auth-email-attribute cfg/config)) :email}))))) (defn auth [req] (let [data (:body-params req)