Skip to content

Commit

Permalink
Merge pull request #3 from operatr-io/fix-context-warn
Browse files Browse the repository at this point in the history
fix-context-path-warn
  • Loading branch information
d-t-w authored Jun 7, 2022
2 parents 6c85eff + 8a4c3a2 commit c254d69
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 78 deletions.
7 changes: 7 additions & 0 deletions slipway-core/dependency-check-suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
<suppress>
<notes><![CDATA[
file name: kpow-*-standalone.jar (shaded: org.clojure:core.async:1.5.648)
]]></notes>
<packageUrl regex="true">^pkg:maven/org\.clojure/core\.async@.*$</packageUrl>
<cve>CVE-2021-43138</cve>
</suppress>
</suppressions>
6 changes: 3 additions & 3 deletions slipway-core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
:url "https://github.com/operatr-io/slipway"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:profiles {:dev {:dependencies [[clj-kondo "2022.03.09"]]
:profiles {:dev {:dependencies [[clj-kondo "2022.05.31"]]
:plugins [[lein-cljfmt "0.8.0"]]}
:kaocha {:dependencies [[lambdaisland/kaocha "1.64.1010" :exclusions [org.clojure/tools.reader]]]}
:kaocha {:dependencies [[lambdaisland/kaocha "1.66.1034" :exclusions [org.clojure/tools.reader]]]}
:smoke {:pedantic? :abort}}
:aliases {"check" ["with-profile" "+smoke" "check"]
"kaocha" ["with-profile" "+kaocha,+smoke" "run" "-m" "kaocha.runner"]
"kondo" ["with-profile" "+smoke" "run" "-m" "clj-kondo.main" "--lint" "src:test" "--parallel"]
"fmt" ["with-profile" "+smoke" "cljfmt" "check"]
"fmtfix" ["with-profile" "+smoke" "cljfmt" "fix"]}

:dependencies [[org.clojure/clojure "1.11.0"]
:dependencies [[org.clojure/clojure "1.11.1"]
[org.clojure/tools.logging "1.2.4"]
[com.taoensso/sente "1.16.2" :scope "provided"]
[org.eclipse.jetty.websocket/websocket-jetty-server "10.0.9" :scope "provided"]
Expand Down
18 changes: 9 additions & 9 deletions slipway-core/src/slipway/auth.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(ns slipway.auth
(:require [clojure.tools.logging :as log]
[clojure.core.protocols :as p])
(:require [clojure.core.protocols :as p]
[clojure.tools.logging :as log])
(:import (org.eclipse.jetty.server Authentication$User)
(org.eclipse.jetty.server Authentication$User Request Handler Server)
(java.util List)
(javax.security.auth.login Configuration)
(javax.servlet SessionTrackingMode)
(org.eclipse.jetty.http HttpCookie$SameSite)
(org.eclipse.jetty.jaas JAASLoginService)
(org.eclipse.jetty.security HashLoginService ConstraintSecurityHandler)
(java.util List)
(org.eclipse.jetty.security ConstraintSecurityHandler HashLoginService)
(org.eclipse.jetty.security.authentication BasicAuthenticator FormAuthenticator)
(javax.servlet SessionTrackingMode)
(org.eclipse.jetty.server.session SessionHandler)
(org.eclipse.jetty.server Authentication$User Handler Request Server)
(org.eclipse.jetty.server.handler HandlerCollection)
(org.eclipse.jetty.http HttpCookie$SameSite)))
(org.eclipse.jetty.server.session SessionHandler)))

(defn user
"Derive user credentials (name + roles) from a base jetty request"
Expand Down Expand Up @@ -89,7 +89,7 @@
:lax HttpCookie$SameSite/LAX
:strict HttpCookie$SameSite/STRICT))

(defn ^SessionHandler session-handler
(defn session-handler ^SessionHandler
;; Apply sensible defaults in-line with ring-defaults:
;; https://github.com/ring-clojure/ring-defaults/blob/master/src/ring/middleware/defaults.clj#L44
[{:keys [secure-request-only? http-only? same-site max-inactive-interval tracking-modes cookie-name]
Expand Down
12 changes: 6 additions & 6 deletions slipway-core/src/slipway/auth/constraints.clj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
(ns slipway.auth.constraints
(:import (org.eclipse.jetty.util.security Constraint)
(org.eclipse.jetty.security ConstraintMapping)))
(:import (org.eclipse.jetty.security ConstraintMapping)
(org.eclipse.jetty.util.security Constraint)))

(defn ^Constraint basic-auth-any-constraint []
(defn basic-auth-any-constraint ^Constraint []
(doto (Constraint. Constraint/__BASIC_AUTH Constraint/ANY_AUTH) ;; == allow any authenticated user
(.setName "auth")
(.setAuthenticate true)))

(defn ^Constraint form-auth-any-constraint []
(defn form-auth-any-constraint ^Constraint []
(doto (Constraint. Constraint/__FORM_AUTH Constraint/ANY_AUTH) ;; == allow any authenticated user
(.setName "auth")
(.setAuthenticate true)))

(defn ^Constraint no-auth []
(defn no-auth ^Constraint []
(doto (Constraint.)
(.setName "no-auth")))

(defn ^ConstraintMapping constraint-mapping
(defn constraint-mapping ^ConstraintMapping
[^String path ^Constraint constraint]
(doto (ConstraintMapping.)
(.setConstraint constraint)
Expand Down
14 changes: 7 additions & 7 deletions slipway-core/src/slipway/impl/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* https://github.com/sunng87/ring-jetty9-adapter/blob/master/src/ring/adapter/jetty9.clj
* https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/src/ring/adapter/jetty.clj"
(:require [clojure.tools.logging :as log])
(:import (org.eclipse.jetty.server Server ServerConnector HttpConfiguration HttpConnectionFactory
ConnectionFactory SecureRequestCustomizer ProxyConnectionFactory Connector ForwardedRequestCustomizer)
(org.eclipse.jetty.util.thread QueuedThreadPool ScheduledExecutorScheduler ThreadPool)
(:import (java.security KeyStore)
(org.eclipse.jetty.server ConnectionFactory Connector ForwardedRequestCustomizer HttpConfiguration
HttpConnectionFactory ProxyConnectionFactory SecureRequestCustomizer Server ServerConnector)
(org.eclipse.jetty.server.handler.gzip GzipHandler)
(org.eclipse.jetty.util.ssl SslContextFactory SslContextFactory$Server)
(java.security KeyStore)
(org.eclipse.jetty.server.handler.gzip GzipHandler)))
(org.eclipse.jetty.util.thread QueuedThreadPool ScheduledExecutorScheduler ThreadPool)))

(defn http-config
[{:keys [ssl-port secure-scheme output-buffer-size request-header-size
Expand Down Expand Up @@ -40,7 +40,7 @@
(.setHeaderCacheSize header-cache-size)
(.addCustomizer secure-customizer))))

(defn ^SslContextFactory$Server ssl-context-factory
(defn ssl-context-factory ^SslContextFactory$Server
[{:keys [keystore keystore-type key-password client-auth key-manager-password
truststore trust-password truststore-type ssl-protocols ssl-provider
exclude-ciphers replace-exclude-ciphers? exclude-protocols replace-exclude-protocols?
Expand Down Expand Up @@ -127,7 +127,7 @@
(log/infof "Enabling gzip compression on the following content types: %s" content-types)
(.setHandler server gzip-handler)))

(defn ^Server create-server
(defn create-server ^Server
[{:as options
:keys [port max-threads min-threads threadpool-idle-timeout job-queue
daemon? max-idle-time host ssl? ssl-port http? proxy?
Expand Down
4 changes: 2 additions & 2 deletions slipway-core/src/slipway/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Derived from:
* https://github.com/sunng87/ring-jetty9-adapter/blob/master/src/ring/adapter/jetty9.clj"
(:require [clojure.string :as string])
(:import (javax.servlet.http HttpServletRequest HttpServletResponse)
(java.util Locale)))
(:import (java.util Locale)
(javax.servlet.http HttpServletRequest HttpServletResponse)))

(defprotocol RequestMapDecoder
(build-request-map [r]))
Expand Down
8 changes: 4 additions & 4 deletions slipway-jetty10/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
:url "https://github.com/operatr-io/slipway"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:profiles {:dev {:dependencies [[clj-kondo "2022.03.09"]
:profiles {:dev {:dependencies [[clj-kondo "2022.05.31"]
[clj-http "3.12.3"]
[commons-io "2.10.0"]]
[commons-io "2.11.0"]]
:resource-paths ["dev-resources"]
:plugins [[lein-cljfmt "0.8.0"]]}
:kaocha {:dependencies [[lambdaisland/kaocha "1.64.1010"]]}
:kaocha {:dependencies [[lambdaisland/kaocha "1.66.1034"]]}
:smoke {:pedantic? :abort}}
:aliases {"check" ["with-profile" "+smoke" "check"]
"kaocha" ["with-profile" "+kaocha,+smoke" "run" "-m" "kaocha.runner"]
"kondo" ["with-profile" "+smoke" "run" "-m" "clj-kondo.main" "--lint" "src:test" "--parallel"]
"fmt" ["with-profile" "+smoke" "cljfmt" "check"]
"fmtfix" ["with-profile" "+smoke" "cljfmt" "fix"]}

:dependencies [[org.clojure/clojure "1.11.0"]
:dependencies [[org.clojure/clojure "1.11.1"]
[org.clojure/tools.logging "1.2.4"]
[ring/ring-servlet "1.9.5"]
[io.operatr/slipway-core "1.0.5"]
Expand Down
20 changes: 10 additions & 10 deletions slipway-jetty10/src/slipway/jetty10/websockets.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
Dervied from:
* https://github.com/sunng87/ring-jetty9-adapter/blob/master/src/ring/adapter/jetty9/websocket.clj"
(:require [slipway.websockets :as ws]
[slipway.util :as util])
(:import (org.eclipse.jetty.websocket.api WebSocketAdapter Session RemoteEndpoint WriteCallback
WebSocketPingPongListener)
(org.eclipse.jetty.websocket.server JettyWebSocketServerContainer JettyWebSocketCreator
JettyServerUpgradeRequest)
(javax.servlet AsyncContext)
(javax.servlet.http HttpServletRequest HttpServletResponse)
(clojure.lang IFn)
(:require [slipway.util :as util]
[slipway.websockets :as ws])
(:import (clojure.lang IFn)
(java.nio ByteBuffer)
(java.time Duration)
(java.util Locale)
(java.time Duration)))
(javax.servlet AsyncContext)
(javax.servlet.http HttpServletRequest HttpServletResponse)
(org.eclipse.jetty.websocket.api RemoteEndpoint Session WebSocketAdapter WebSocketPingPongListener
WriteCallback)
(org.eclipse.jetty.websocket.server JettyServerUpgradeRequest JettyWebSocketCreator
JettyWebSocketServerContainer)))

(def ^:private no-op (constantly nil))

Expand Down
24 changes: 12 additions & 12 deletions slipway-jetty10/src/slipway/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
(:require [clojure.tools.logging :as log]
[ring.util.servlet :as servlet]
[slipway.auth :as auth]
[slipway.jetty10.websockets :as jetty10.ws]
[slipway.impl.server :as server]
[slipway.jetty10.auth]
[slipway.jetty10.websockets :as jetty10.ws]
[slipway.util :as util]
[slipway.websockets :as ws]
[slipway.impl.server :as server])
(:import (org.eclipse.jetty.server Server Request)
(org.eclipse.jetty.servlet ServletHandler ServletContextHandler)
(javax.servlet.http HttpServletRequest HttpServletResponse)
[slipway.websockets :as ws])
(:import (javax.servlet.http HttpServletRequest HttpServletResponse)
(org.eclipse.jetty.server Request Server)
(org.eclipse.jetty.servlet ServletContextHandler ServletHandler)
(org.eclipse.jetty.websocket.server.config JettyWebSocketServletContainerInitializer)))

(extend-protocol util/RequestMapDecoder
Expand All @@ -25,7 +25,7 @@
(defn wrap-proxy-handler
[jetty-handler]
(doto (ServletContextHandler.)
(.setContextPath "/*")
(.setContextPath "/")
(.setAllowNullPathInfo true)
(JettyWebSocketServletContainerInitializer/configure nil)
(.setServletHandler jetty-handler)))
Expand Down Expand Up @@ -62,13 +62,13 @@
"application/javascript"
"image/svg+xml"])

(defn ^Server run-jetty
(defn run-jetty
"Starts a Jetty server.
See https://github.com/operatr-io/slipway#usage for list of options"
[handler {:as options
:keys [configurator join? auth gzip? gzip-content-types gzip-min-size http-forwarded? error-handler]
:or {gzip-content-types default-gzip-content-types
gzip-min-size 1024}}]
^Server [handler {:as options
:keys [configurator join? auth gzip? gzip-content-types gzip-min-size http-forwarded? error-handler]
:or {gzip-content-types default-gzip-content-types
gzip-min-size 1024}}]
(let [server (server/create-server options)
ring-app-handler (proxy-handler handler options)]
(.setHandler server ring-app-handler)
Expand Down
8 changes: 4 additions & 4 deletions slipway-jetty9/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
:url "https://github.com/operatr-io/slipway"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:profiles {:dev {:dependencies [[clj-kondo "2022.03.09"]
:profiles {:dev {:dependencies [[clj-kondo "2022.05.31"]
[clj-http "3.12.3"]
[commons-io "2.10.0"]]
[commons-io "2.11.0"]]
:resource-paths ["dev-resources"]
:plugins [[lein-cljfmt "0.8.0"]]}
:kaocha {:dependencies [[lambdaisland/kaocha "1.64.1010"]]}
:kaocha {:dependencies [[lambdaisland/kaocha "1.66.1034"]]}
:smoke {:pedantic? :abort}}
:aliases {"check" ["with-profile" "+smoke" "check"]
"kaocha" ["with-profile" "+kaocha,+smoke" "run" "-m" "kaocha.runner"]
"kondo" ["with-profile" "+smoke" "run" "-m" "clj-kondo.main" "--lint" "src:test" "--parallel"]
"fmt" ["with-profile" "+smoke" "cljfmt" "check"]
"fmtfix" ["with-profile" "+smoke" "cljfmt" "fix"]}

:dependencies [[org.clojure/clojure "1.11.0"]
:dependencies [[org.clojure/clojure "1.11.1"]
[ring/ring-servlet "1.9.5"]
[io.operatr/slipway-core "1.0.5"]
[org.eclipse.jetty/jetty-server "9.4.46.v20220331"]
Expand Down
12 changes: 6 additions & 6 deletions slipway-jetty9/src/slipway/jetty9/websockets.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* https://github.com/sunng87/ring-jetty9-adapter/blob/master/src/ring/adapter/jetty9/websocket.clj"
(:require [slipway.util :as util]
[slipway.websockets :as ws])
(:import (org.eclipse.jetty.server Request Response)
(org.eclipse.jetty.websocket.api WebSocketAdapter Session RemoteEndpoint WriteCallback)
(:import (clojure.lang IFn)
(java.nio ByteBuffer)
(java.util Locale)
(org.eclipse.jetty.server Request Response)
(org.eclipse.jetty.websocket.api RemoteEndpoint Session WebSocketAdapter WriteCallback)
(org.eclipse.jetty.websocket.api.extensions ExtensionConfig)
(org.eclipse.jetty.websocket.server WebSocketHandler)
(org.eclipse.jetty.websocket.servlet WebSocketServletFactory WebSocketCreator ServletUpgradeRequest)
(clojure.lang IFn)
(java.nio ByteBuffer)
(java.util Locale)))
(org.eclipse.jetty.websocket.servlet ServletUpgradeRequest WebSocketCreator WebSocketServletFactory)))

(def ^:private no-op (constantly nil))

Expand Down
30 changes: 15 additions & 15 deletions slipway-jetty9/src/slipway/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
Derived from:
* https://github.com/sunng87/ring-jetty9-adapter/blob/master/src/ring/adapter/jetty9.clj
* https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/src/ring/adapter/jetty.clj"
(:require [ring.util.servlet :as servlet]
[slipway.util :as util]
[slipway.jetty9.websockets :as jetty9.websockets]
(:require [clojure.tools.logging :as log]
[ring.util.servlet :as servlet]
[slipway.auth :as auth]
[slipway.jetty9.auth]
[slipway.websockets :as ws]
[slipway.impl.server :as server]
[clojure.tools.logging :as log])
(:import (org.eclipse.jetty.server Handler Server Request)
(org.eclipse.jetty.server.handler AbstractHandler HandlerList ContextHandler)
(javax.servlet.http HttpServletRequest HttpServletResponse)))
[slipway.jetty9.auth]
[slipway.jetty9.websockets :as jetty9.websockets]
[slipway.util :as util]
[slipway.websockets :as ws])
(:import (javax.servlet.http HttpServletRequest HttpServletResponse)
(org.eclipse.jetty.server Handler Request Server)
(org.eclipse.jetty.server.handler AbstractHandler ContextHandler HandlerList)))

(extend-protocol util/RequestMapDecoder
HttpServletRequest
Expand Down Expand Up @@ -66,17 +66,17 @@
"application/javascript"
"image/svg+xml"])

(defn ^Server run-jetty
(defn run-jetty
"Starts a Jetty server.
See https://github.com/operatr-io/slipway#usage for list of options"
[handler {:as options
:keys [configurator join? auth gzip? gzip-content-types gzip-min-size http-forwarded? error-handler]
:or {gzip-content-types default-gzip-content-types
gzip-min-size 1024}}]
^Server [handler {:as options
:keys [configurator join? auth gzip? gzip-content-types gzip-min-size http-forwarded? error-handler]
:or {gzip-content-types default-gzip-content-types
gzip-min-size 1024}}]
(let [server (server/create-server options)
ring-app-handler (proxy-handler handler options)
ws-handler (doto (ContextHandler.)
(.setContextPath "/*")
(.setContextPath "/")
(.setAllowNullPathInfo true)
(.setHandler (jetty9.websockets/proxy-ws-handler handler options)))
contexts (doto (HandlerList.)
Expand Down

0 comments on commit c254d69

Please sign in to comment.