moved security.

This commit is contained in:
Bryce Covert
2018-04-06 09:20:51 -07:00
parent b93808f1df
commit c74e4fceaa
7 changed files with 100 additions and 90 deletions

View File

@@ -13,7 +13,7 @@
[ring.middleware.edn :refer [wrap-edn-params]]
[clojure.java.jdbc :as j]
[config.core :refer [env]]
[buddy.auth :refer [authenticated?]]
[buddy.auth.backends.token :refer [jws-backend]]
[buddy.auth.middleware :refer [wrap-authorization wrap-authentication]]
[auto-ap.routes.companies :as companies]
@@ -24,26 +24,17 @@
(defcredential "AKIAIRKDGLBX7J7VJZ6Q" "OtRw2t/xktJBDjP8Jnx1Yf6G+uzBfIkrQEc6nmgo" "us-east-1")
(defn wrap-secure [handler]
(fn [request]
(if (authenticated? request)
(handler request)
{:status 401
:body "not authenticated"})))
(defroutes static-routes
(GET "/" [] (response/resource-response "index.html" {:root "public"}))
(route/resources "/")
(routes (ANY "*" [] (response/resource-response "index.html" {:root "public"}))))
(defroutes api-routes
(context "/api" []
(wrap-routes invoices/routes wrap-secure)
(wrap-routes companies/routes wrap-secure)
(wrap-routes vendors/routes wrap-secure)
(wrap-routes reminders/routes wrap-secure)
invoices/routes
companies/routes
vendors/routes
reminders/routes
auth/routes))

View File

@@ -1,8 +1,10 @@
(ns auto-ap.routes.companies
(:require [compojure.core :refer [context GET PUT defroutes]]
[auto-ap.db.companies :as companies]))
(:require [compojure.core :refer [context GET PUT defroutes wrap-routes]]
[auto-ap.db.companies :as companies]
[auto-ap.routes.utils :refer [wrap-secure]]))
(defroutes routes
(wrap-routes
(context "/companies" []
(GET "/" []
{:status 200
@@ -11,4 +13,5 @@
(PUT "/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
{:status 200
:body (pr-str (companies/upsert id edn-params))
:headers {"Content-Type" "application/edn"}})))
:headers {"Content-Type" "application/edn"}}))
wrap-secure))

View File

@@ -1,10 +1,12 @@
(ns auto-ap.routes.invoices
(:require [compojure.core :refer [context GET PUT POST defroutes]]
(:require [compojure.core :refer [context GET PUT POST defroutes wrap-routes]]
[auto-ap.db.invoices :as invoices]
[auto-ap.db.companies :as companies]
[auto-ap.parse :as parse]))
[auto-ap.parse :as parse]
[auto-ap.routes.utils :refer [wrap-secure]]))
(defroutes routes
(wrap-routes
(context "/invoices" []
(GET "/" []
{:status 200
@@ -59,4 +61,5 @@
#_(wrap-json-response (GET "/export" {:keys [query-params]}
(println query-params)
(doto (invoices/get-unpaid (query-params "company"))
println)))))
println))))
wrap-secure))

View File

@@ -1,7 +1,8 @@
(ns auto-ap.routes.reminders
(:require [compojure.core :refer [context GET POST defroutes]]
[auto-ap.db.vendors :as vendors]
[amazonica.aws.simpleemail :as ses]))
[amazonica.aws.simpleemail :as ses]
))
(defroutes routes

View File

@@ -0,0 +1,9 @@
(ns auto-ap.routes.utils
(:require [buddy.auth :refer [authenticated?]]))
(defn wrap-secure [handler]
(fn [request]
(if (authenticated? request)
(handler request)
{:status 401
:body "not authenticated"})))

View File

@@ -1,8 +1,10 @@
(ns auto-ap.routes.vendors
(:require [compojure.core :refer [context GET PUT POST defroutes]]
[auto-ap.db.vendors :as vendors]))
(:require [compojure.core :refer [context GET PUT POST defroutes wrap-routes]]
[auto-ap.db.vendors :as vendors]
[auto-ap.routes.utils :refer [wrap-secure]]))
(defroutes routes
(wrap-routes
(context "/vendors" []
(GET "/" []
{:status 200
@@ -15,4 +17,5 @@
(POST "/" {:keys [edn-params] :as r}
{:status 200
:body (pr-str (vendors/insert edn-params))
:headers {"Content-Type" "application/edn"}})))
:headers {"Content-Type" "application/edn"}}))
wrap-secure))