mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
🐛 System start and stop without LDAP connection
This commit is contained in:
parent
272c27061d
commit
f2c4ff7518
1 changed files with 45 additions and 39 deletions
|
@ -6,15 +6,17 @@
|
|||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.config :as cfg]
|
||||
[uxbox.services.mutations :as sm]
|
||||
[uxbox.http.session :as session]))
|
||||
[uxbox.http.session :as session]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
|
||||
(defn replace-several [s & {:as replacements}]
|
||||
(reduce-kv clojure.string/replace s replacements))
|
||||
|
||||
(defstate ldap-pool
|
||||
:start (client/connect (merge
|
||||
{:host {:address (:ldap-auth-host cfg/config)
|
||||
(defstate *ldap-pool
|
||||
:start (delay
|
||||
(try
|
||||
(client/connect (merge {:host {:address (:ldap-auth-host cfg/config)
|
||||
:port (:ldap-auth-port cfg/config)}}
|
||||
(-> cfg/config
|
||||
(select-keys [:ldap-auth-ssl
|
||||
|
@ -25,11 +27,15 @@
|
|||
:ldap-auth-starttls :startTLS?
|
||||
:ldap-bind-dn :bind-dn
|
||||
:ldap-bind-password :password}))))
|
||||
:stop (client/close ldap-pool))
|
||||
(catch Exception e
|
||||
(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))))
|
||||
|
||||
(defn- auth-with-ldap [username password]
|
||||
(let [conn (client/get-connection ldap-pool)
|
||||
user-search-query (replace-several (:ldap-auth-user-query cfg/config)
|
||||
(when-let [conn (some-> *ldap-pool deref (client/get-connection))]
|
||||
(let [user-search-query (replace-several (:ldap-auth-user-query cfg/config)
|
||||
"$username" username)
|
||||
user-attributes (-> cfg/config
|
||||
(select-keys [:ldap-auth-username-attribute
|
||||
|
@ -51,7 +57,7 @@
|
|||
(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)))))
|
||||
(finally (client/release-connection @*ldap-pool conn))))))
|
||||
|
||||
(defn auth [req]
|
||||
(let [data (:body-params req)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue