(defn wrap-base [handler]
(-> ((:middleware defaults) handler)
wrap-webjars
wrap-flash
wrap-byu-api-call ;; API piggy-backs off CAS; returns with "code=" and "state=" in the url
(wrap-cas (-> env :site-url)) ;; regular CAS; gives me a "ticket=" param
(wrap-session {:cookie-attrs {:http-only true}})
(wrap-defaults
(-> site-defaults
(assoc-in [:security :anti-forgery] false)
(dissoc :session)))
wrap-context
wrap-internal-error))(defn wrap-byu-api-call [handler]
(let [api-address (oauth/authkey-GET-url
(-> env :client-id)
(-> env :site-url))] ;; Just generates the target URL, including its redirect_url after auth happens
(println "API ADDRESS" api-address) ;; looks good
(fn [req]
(println "--- In wrap-byu-api-call ---")
(println req)
(if (get-in req [:session :byu-api-auth-code])
(do
(println "--------- Request has the right session info")
(handler req))
(if-let [code (get-in req [:params :code])]
(do
(println "--------- Request has the code in the url")
(handler (assoc-in req [:session :byu-api-auth-code] code)))
(do
(println "--------- Request has neither url or session code")
(redirect api-address)))))))2016/08/03 17:43:30 [error] 46923#0: *11 connect() failed (111: Connection refused) while connecting to upstream, client: 10.25.2.15, server: humplus-funding.byu.edu, request: "GET /?state=myteststate&code=c45fdbea689f5669665299f52df21 HTTP/1.1", upstream: "http://[::1]:8080/humplusfunding/?state=myteststate&code=c45fdbea689f5669665299f52df21", host: "humplus-funding.byu.edu", referrer: "https://shib.byu.edu/idp/profile/SAML2/POST/SSO;jsessionid=449AF9F05854EE118062BE44D06A43B0.2?execution=e1s1&_eventId_proceed=1" [0m [0m17:43:05,408 INFO [stdout] (default task-11) --- In wrap-byu-api-call ---
[0m [0m17:43:05,412 INFO [stdout] (default task-11) {:ssl-client-cert nil, :cookies {}, :cas-info #object[java.util.Collections$EmptyMap 0x7b1411d5 {}], :remote-addr 127.0.0.1, :username torysa, :params {:ticket ST-553561-akFrwrLF0F61bh71eX2G-smaug1}, :servlet-context #object[io.undertow.servlet.spec.ServletContextImpl 0x5321b1d1 io.undertow.servlet.spec.ServletContextImpl@5321b1d1], :servlet-response #object[io.undertow.servlet.spec.HttpServletResponseImpl 0x15e9b613 io.undertow.servlet.spec.HttpServletResponseImpl@15e9b613], :handler-type :servlet, :servlet #object[immutant.web.internal.servlet.proxy$javax.servlet.http.HttpServlet$ff19274a 0x42b3cfa1 immutant.web.internal.servlet.proxy$javax.servlet.http.HttpServlet$ff19274a@42b3cfa1], :headers {accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, connection close, x-forwarded-proto https, user-agent Mozilla/5.0 (X11; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0, x-forwarded-for 10.25.2.15, host humplus-funding.byu.edu, accept-language en-US,en;q=0.5, accept-encoding gzip, deflate, br}, :server-port 80, :servlet-request #object[io.undertow.servlet.spec.HttpServletRequestImpl 0xb5665c6 HttpServletRequestImpl [ GET /humplusfunding/ ]], :content-length -1, :form-params {}, :query-params {ticket ST-553561-akFrwrLF0F61bh71eX2G-smaug1, _const_cas_assertion_ #object[org.jasig.cas.client.validation.AssertionImpl 0x633a30ed org.jasig.cas.client.validation.AssertionImpl@633a30ed]}, :content-type nil, :path-info /, :character-encoding nil, :context /humplusfunding, :uri /humplusfunding/, :server-name humplus-funding.byu.edu, :query-string ticket=ST-553561-akFrwrLF0F61bh71eX2G-smaug1, :body #object[io.undertow.servlet.spec.ServletInputStreamImpl 0x7f53fade io.undertow.servlet.spec.ServletInputStreamImpl@7f53fade], :multipart-params {}, :scheme :http, :request-method :get, :session nil}
[0m [0m17:43:05,412 INFO [stdout] (default task-11) --------- Request has neither url or session code
... <REPEATED MANY TIMES>