add auth rules, only basic admin for now
This commit is contained in:
parent
8a471893f5
commit
f220856e39
1 changed files with 26 additions and 12 deletions
|
@ -18,7 +18,6 @@
|
||||||
[buddy.auth.backends.session :refer [session-backend]])
|
[buddy.auth.backends.session :refer [session-backend]])
|
||||||
(:import))
|
(:import))
|
||||||
|
|
||||||
|
|
||||||
(defn wrap-internal-error [handler]
|
(defn wrap-internal-error [handler]
|
||||||
(fn [req]
|
(fn [req]
|
||||||
(try
|
(try
|
||||||
|
@ -37,7 +36,6 @@
|
||||||
{:status 403
|
{:status 403
|
||||||
:title "Invalid anti-forgery token"})}))
|
:title "Invalid anti-forgery token"})}))
|
||||||
|
|
||||||
|
|
||||||
(defn wrap-formats [handler]
|
(defn wrap-formats [handler]
|
||||||
(let [wrapped (-> handler wrap-params (wrap-format formats/instance))]
|
(let [wrapped (-> handler wrap-params (wrap-format formats/instance))]
|
||||||
(fn [request]
|
(fn [request]
|
||||||
|
@ -45,10 +43,24 @@
|
||||||
;; since they're not compatible with this middleware
|
;; since they're not compatible with this middleware
|
||||||
((if (:websocket? request) handler wrapped) request))))
|
((if (:websocket? request) handler wrapped) request))))
|
||||||
|
|
||||||
|
;; Authentication
|
||||||
|
|
||||||
|
(defn admin-access [req]
|
||||||
|
(contains? (get-in req [:session :user :roles]) :admin))
|
||||||
|
|
||||||
|
(def rules [{:pattern #"^/admin/.*"
|
||||||
|
:handler admin-access}
|
||||||
|
; TODO add other auth schemes
|
||||||
|
;{:pattern [#"^/$" #"^/oauth/.*"]
|
||||||
|
; :handler any-access}
|
||||||
|
;{:pattern #"^/.*"
|
||||||
|
; :handler user-access}
|
||||||
|
])
|
||||||
|
|
||||||
(defn on-error [request response]
|
(defn on-error [request response]
|
||||||
(error-page
|
(error-page
|
||||||
{:status 403
|
{:status 403
|
||||||
:title (str "Access to " (:uri request) " is not authorized")}))
|
:title (str "Access to " (:uri request) " is not authorised")}))
|
||||||
|
|
||||||
(defn wrap-restricted [handler]
|
(defn wrap-restricted [handler]
|
||||||
(restrict handler {:handler authenticated?
|
(restrict handler {:handler authenticated?
|
||||||
|
@ -63,6 +75,8 @@
|
||||||
(defn wrap-base [handler]
|
(defn wrap-base [handler]
|
||||||
(-> ((:middleware defaults) handler)
|
(-> ((:middleware defaults) handler)
|
||||||
wrap-auth
|
wrap-auth
|
||||||
|
(wrap-access-rules {:rules rules
|
||||||
|
:on-error on-error})
|
||||||
wrap-webjars
|
wrap-webjars
|
||||||
wrap-flash
|
wrap-flash
|
||||||
(wrap-session {:cookie-attrs {:http-only true}})
|
(wrap-session {:cookie-attrs {:http-only true}})
|
||||||
|
|
Loading…
Reference in a new issue