Skip to content

Commit 30baff4

Browse files
authored
Add ability to disable WebRoot entirely (#1602)
* Add ability to disable WebRoot entirely * Add ability to disable WebRoot entirely * Add ability to disable WebRoot entirely * Add ability to disable WebRoot entirely
1 parent 8a5618a commit 30baff4

File tree

10 files changed

+56
-65
lines changed

10 files changed

+56
-65
lines changed

example/apache-ignite/src/main/scala/org/finos/vuu/example/ignite/IgniteVuuMain.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import org.finos.vuu.core.module.vui.VuiStateModule
1717
import org.finos.vuu.example.ignite.loader.IgniteOrderGenerator
1818
import org.finos.vuu.example.ignite.module.IgniteOrderDataModule
1919
import org.finos.vuu.net.auth.AlwaysHappyAuthenticator
20-
import org.finos.vuu.net.http.VuuHttp2ServerOptions
20+
import org.finos.vuu.net.http.{AbsolutePathWebRoot, VuuHttp2ServerOptions}
2121
import org.finos.vuu.net.{AlwaysHappyLoginValidator, Authenticator, LoggedInTokenValidator}
2222
import org.finos.vuu.order.oms.OmsApi
2323
import org.finos.vuu.plugin.virtualized.VirtualizedTablePlugin
@@ -63,12 +63,8 @@ object IgniteVuuMain extends App with StrictLogging {
6363

6464
val config = VuuServerConfig(
6565
VuuHttp2ServerOptions()
66-
//only specify webroot if we want to load the source locally, we'll load it from the jar
67-
//otherwise
68-
.withWebRoot(webRoot)
66+
.withWebRoot(AbsolutePathWebRoot(webRoot, directoryListings = true))
6967
.withSsl(certPath, keyPath)
70-
//don't leave me on in prod pls....
71-
.withDirectoryListings(true)
7268
.withBindAddress("0.0.0.0")
7369
.withPort(8443),
7470
VuuWebSocketOptions()

example/main-java/src/main/java/org/finos/vuu/VuuExampleMain.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.finos.vuu.net.Authenticator;
2020
import org.finos.vuu.net.LoggedInTokenValidator;
2121
import org.finos.vuu.net.auth.AlwaysHappyAuthenticator;
22+
import org.finos.vuu.net.http.AbsolutePathWebRoot;
2223
import org.finos.vuu.net.http.VuuHttp2ServerOptions;
2324
import org.finos.vuu.plugin.Plugin;
2425
import org.finos.vuu.state.MemoryBackedVuiStateStore;
@@ -54,13 +55,9 @@ public static void main( String[] args )
5455
final String keyPath = "example/main/src/main/resources/certs/key.pem";
5556

5657
final VuuServerConfig config = new VuuServerConfig(
57-
VuuHttp2ServerOptions.apply()
58-
.withWebRoot(webRoot)
59-
//if we specify a web root, it means we will serve the files from a directory on the file system
60-
//if we don't the files will be served from the vuu-ui jar directly.
61-
//.withWebRoot(".")
58+
VuuHttp2ServerOptions.apply()
59+
.withWebRoot(new AbsolutePathWebRoot(webRoot, true))
6260
.withSsl(certPath, keyPath)
63-
.withDirectoryListings(true)
6461
.withPort(8443),
6562
VuuWebSocketOptions.apply()
6663
.withUri("websocket")

example/main/src/main/scala/org/finos/vuu/SimulMain.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import org.finos.vuu.example.rest.client.{HttpClient, StubbedBackend}
2020
import org.finos.vuu.example.rest.module.RestModule
2121
import org.finos.vuu.example.virtualtable.module.VirtualTableModule
2222
import org.finos.vuu.net.auth.AlwaysHappyAuthenticator
23-
import org.finos.vuu.net.http.VuuHttp2ServerOptions
23+
import org.finos.vuu.net.http.{AbsolutePathWebRoot, VuuHttp2ServerOptions}
2424
import org.finos.vuu.net.{AlwaysHappyLoginValidator, Authenticator, LoggedInTokenValidator}
2525
import org.finos.vuu.order.oms.OmsApi
2626
import org.finos.vuu.plugin.virtualized.VirtualizedTablePlugin
@@ -101,9 +101,8 @@ object httpServerOptions {
101101
val options = VuuHttp2ServerOptions()
102102
//only specify webroot if we want to load the source locally, we'll load it from the jar
103103
//otherwise
104-
.withWebRoot(c.getString(ConfigKeys.webroot))
104+
.withWebRoot(AbsolutePathWebRoot(c.getString(ConfigKeys.webroot), directoryListings = true))
105105
//don't leave me on in prod pls....
106-
.withDirectoryListings(true)
107106
.withBindAddress("0.0.0.0")
108107
.withPort(8443)
109108

example/permission/src/test/scala/org/finos/vuu/core/module/authn/AuthNServerTest.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.finos.vuu.core.module.TableDefContainer
1212
import org.finos.vuu.core.module.vui.VuiStateModule
1313
import org.finos.vuu.core.{VuuSecurityOptions, VuuServer, VuuServerConfig, VuuWebSocketOptions}
1414
import org.finos.vuu.net.auth.AlwaysHappyAuthenticator
15-
import org.finos.vuu.net.http.VuuHttp2ServerOptions
15+
import org.finos.vuu.net.http.{AbsolutePathWebRoot, VuuHttp2ServerOptions}
1616
import org.finos.vuu.net.{Authenticator, LoggedInTokenValidator}
1717
import org.finos.vuu.state.MemoryBackedVuiStateStore
1818
import org.scalatest.featurespec.AnyFeatureSpec
@@ -47,9 +47,8 @@ class AuthNServerTest extends AnyFeatureSpec with Matchers with StrictLogging {
4747

4848
val config = VuuServerConfig(
4949
VuuHttp2ServerOptions()
50-
.withWebRoot("vuu/src/main/resources/www")
50+
.withWebRoot(AbsolutePathWebRoot("vuu/src/main/resources/www", directoryListings = true))
5151
.withSsl("vuu/src/main/resources/certs/cert.pem", "vuu/src/main/resources/certs/key.pem")
52-
.withDirectoryListings(true)
5352
.withPort(https),
5453
VuuWebSocketOptions()
5554
.withUri("websocket")

vuu/src/main/scala/org/finos/vuu/net/http/VuuHttp2Server.scala

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,36 @@ class VertxHttp2Verticle(val options: VuuHttp2ServerOptions, val services: List[
8686
services.foreach(service => addRestService(router, service))
8787

8888
var webRoot: String = null
89-
if(options.webRoot.isEmpty){
90-
webRoot = "classpath://webroot"
91-
router.route("/public/*")
92-
.handler(StaticHandler.create())
93-
router.route("/*")
94-
.handler(StaticHandler.create())
95-
}else{
96-
webRoot = new File(options.webRoot).getAbsoluteFile.toString
97-
PathChecker.throwOnDirectoryNotExists(options.webRoot, "webroot path does not exist:")
98-
99-
router.route("/public/*")
100-
.handler(StaticHandler.create()
101-
.setWebRoot(options.webRoot)
102-
.setDirectoryListing(options.allowDirectoryListings)
103-
)
104-
105-
// Serve the static pages
106-
router.route("/*")
107-
.handler(StaticHandler.create()
108-
.setWebRoot(options.webRoot)
109-
.setDirectoryListing(options.allowDirectoryListings)
110-
)
89+
options.webRoot match {
90+
case WebRootDisabled() =>
91+
webRoot = "disabled"
92+
case ClassPathWebRoot() => {
93+
webRoot = "classpath://webroot"
94+
router.route("/public/*")
95+
.handler(StaticHandler.create())
96+
router.route("/*")
97+
.handler(StaticHandler.create())
98+
}
99+
case AbsolutePathWebRoot(path: String, directoryListings: Boolean) => {
100+
webRoot = new File(path).getAbsoluteFile.toString
101+
PathChecker.throwOnDirectoryNotExists(path, "webroot path does not exist:")
102+
103+
router.route("/public/*")
104+
.handler(StaticHandler.create()
105+
.setWebRoot(path)
106+
.setDirectoryListing(directoryListings)
107+
)
108+
109+
// Serve the static pages
110+
router.route("/*")
111+
.handler(StaticHandler.create()
112+
.setWebRoot(path)
113+
.setDirectoryListing(directoryListings)
114+
)
115+
}
111116
}
112117

113-
vertx.createHttpServer(httpOpts).requestHandler(router).listen(options.port);
114-
115-
118+
vertx.createHttpServer(httpOpts).requestHandler(router).listen(options.port)
116119
logger.info(s"[HTTP2] Server Started @ ${options.port} on / with webroot $webRoot ")
117120

118121
} catch {

vuu/src/main/scala/org/finos/vuu/net/http/VuuHttp2ServerOptions.scala

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,34 @@ trait VuuSecurityOptions {
99
def withLoginValidator(tokenValidator: LoginTokenValidator): VuuSecurityOptions
1010
}
1111

12+
sealed trait VuuHttp2ServerWebRootType
13+
case class WebRootDisabled() extends VuuHttp2ServerWebRootType
14+
case class ClassPathWebRoot() extends VuuHttp2ServerWebRootType
15+
case class AbsolutePathWebRoot(path: String, directoryListings: Boolean = false) extends VuuHttp2ServerWebRootType
16+
1217
trait VuuHttp2ServerOptions {
13-
def allowDirectoryListings: Boolean
1418
def sslEnabled: Boolean
1519
def certPath: String
1620
def keyPath: String
17-
def webRoot: String
21+
def webRoot: VuuHttp2ServerWebRootType
1822
def port: Int
1923
def bindAddress: String
2024
def withSsl(certPath: String, keyPath: String): VuuHttp2ServerOptions
2125
def withSslDisabled(): VuuHttp2ServerOptions
22-
def withWebRoot(webRoot: String): VuuHttp2ServerOptions
23-
def withDirectoryListings(allow: Boolean): VuuHttp2ServerOptions
26+
def withWebRoot(webRoot: VuuHttp2ServerWebRootType): VuuHttp2ServerOptions
2427
def withPort(port: Int): VuuHttp2ServerOptions
2528
def withBindAddress(bindAddress: String): VuuHttp2ServerOptions
2629
}
2730

2831
object VuuHttp2ServerOptions {
2932
def apply(): VuuHttp2ServerOptions = {
30-
VuuHttp2ServerOptionsImpl(port = 8080, allowDirectoryListings = false)
33+
VuuHttp2ServerOptionsImpl(port = 8080)
3134
}
3235
}
3336

3437
private case class VuuHttp2ServerOptionsImpl(sslEnabled: Boolean = true,
3538
certPath: String = "", keyPath: String = "",
36-
webRoot: String = "", port: Int,
37-
allowDirectoryListings: Boolean,
39+
webRoot: VuuHttp2ServerWebRootType = WebRootDisabled(), port: Int,
3840
bindAddress: String = "") extends VuuHttp2ServerOptions {
3941

4042
def withPort(port: Int): VuuHttp2ServerOptions = {
@@ -47,12 +49,9 @@ private case class VuuHttp2ServerOptionsImpl(sslEnabled: Boolean = true,
4749
this.copy(certPath = certPath, keyPath = keyPath, sslEnabled = true)
4850
}
4951

50-
def withWebRoot(webRoot: String): VuuHttp2ServerOptions = {
52+
def withWebRoot(webRoot: VuuHttp2ServerWebRootType): VuuHttp2ServerOptions = {
5153
this.copy(webRoot = webRoot)
5254
}
5355

54-
override def withDirectoryListings(allow: Boolean): VuuHttp2ServerOptions = {
55-
this.copy(allowDirectoryListings = allow)
56-
}
5756
override def withBindAddress(bindAddress: String): VuuHttp2ServerOptions = this.copy(bindAddress = bindAddress)
5857
}

vuu/src/test/scala/org/finos/vuu/core/module/modulefrommodule/ModuleConstructorTest.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.finos.toolbox.time.{Clock, DefaultClock}
66
import org.finos.vuu.core.module.TableDefContainer
77
import org.finos.vuu.core.{VuuSecurityOptions, VuuServerConfig, VuuThreadingOptions, VuuWebSocketOptions}
88
import org.finos.vuu.net.{AlwaysHappyLoginValidator, Authenticator, ViewServerMessage}
9-
import org.finos.vuu.net.http.VuuHttp2ServerOptions
9+
import org.finos.vuu.net.http.{AbsolutePathWebRoot, VuuHttp2ServerOptions}
1010
import org.scalatest.GivenWhenThen
1111
import org.scalatest.featurespec.AnyFeatureSpec
1212
import org.scalatest.matchers.should.Matchers
@@ -32,10 +32,9 @@ class ModuleConstructorTest extends AnyFeatureSpec with Matchers with GivenWhenT
3232
VuuHttp2ServerOptions()
3333
//only specify webroot if we want to load the source locally, we'll load it from the jar
3434
//otherwise
35-
.withWebRoot("webRoot")
35+
.withWebRoot(AbsolutePathWebRoot("webRoot", directoryListings = true))
3636
.withSsl("certPath", "keyPath")
3737
//don't leave me on in prod pls....
38-
.withDirectoryListings(true)
3938
.withBindAddress("0.0.0.0")
4039
.withPort(8443),
4140
VuuWebSocketOptions()

vuu/src/test/scala/org/finos/vuu/net/rest/RestServiceTest.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.finos.vuu.net.rest
33
import com.typesafe.scalalogging.StrictLogging
44
import org.finos.vuu.core.module.vui.VuiStateModule
55
import org.finos.vuu.core.{VuuSecurityOptions, VuuServer, VuuServerConfig, VuuWebSocketOptions}
6-
import org.finos.vuu.net.http.VuuHttp2ServerOptions
6+
import org.finos.vuu.net.http.{AbsolutePathWebRoot, VuuHttp2ServerOptions}
77
import org.finos.vuu.state.MemoryBackedVuiStateStore
88
import io.vertx.core.json.JsonObject
99
import io.vertx.core.{Vertx, VertxOptions}
@@ -42,9 +42,8 @@ class RestServiceTest extends AnyFeatureSpec with Matchers with StrictLogging {
4242

4343
val config = VuuServerConfig(
4444
VuuHttp2ServerOptions()
45-
.withWebRoot("vuu/src/main/resources/www")
45+
.withWebRoot(AbsolutePathWebRoot("vuu/src/main/resources/www", directoryListings = true))
4646
.withSsl("vuu/src/main/resources/certs/cert.pem", "vuu/src/main/resources/certs/key.pem")
47-
.withDirectoryListings(true)
4847
.withPort(https),
4948
VuuWebSocketOptions()
5049
.withUri("websocket")

vuu/src/test/scala/org/finos/vuu/net/rpc/RpcModuleTest.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.finos.vuu.client.ClientHelperFns._
44
import org.finos.vuu.core.module.{MyObjectParam, TableDefContainer, TestModule}
55
import org.finos.vuu.core.{VuuSecurityOptions, VuuServer, VuuServerConfig, VuuWebSocketOptions}
66
import org.finos.vuu.net.WebSocketViewServerClient
7-
import org.finos.vuu.net.http.VuuHttp2ServerOptions
7+
import org.finos.vuu.net.http.{AbsolutePathWebRoot, VuuHttp2ServerOptions}
88
import org.finos.vuu.net.json.JsonVsSerializer
99
import org.finos.vuu.net.ws.WebSocketClient
1010
import org.finos.toolbox.jmx.{MetricsProvider, MetricsProviderImpl}
@@ -42,9 +42,8 @@ class RpcModuleTest extends AnyFeatureSpec with Matchers {
4242

4343
val config = VuuServerConfig(
4444
VuuHttp2ServerOptions()
45-
.withWebRoot("vuu/src/main/resources/www")
45+
.withWebRoot(AbsolutePathWebRoot("vuu/src/main/resources/www", directoryListings = true))
4646
.withSsl("vuu/src/main/resources/certs/cert.pem", "vuu/src/main/resources/certs/key.pem")
47-
.withDirectoryListings(true)
4847
.withPort(https),
4948
VuuWebSocketOptions()
5049
.withUri("websocket")

vuu/src/test/scala/org/finos/vuu/wsapi/helpers/TestStartUp.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import org.finos.toolbox.time.Clock
66
import org.finos.vuu.core.module.{TableDefContainer, ViewServerModule}
77
import org.finos.vuu.core._
88
import org.finos.vuu.net.auth.AlwaysHappyAuthenticator
9-
import org.finos.vuu.net.http.VuuHttp2ServerOptions
9+
import org.finos.vuu.net.http.{VuuHttp2ServerOptions, WebRootDisabled}
1010
import org.finos.vuu.net.json.JsonVsSerializer
1111
import org.finos.vuu.net.ws.WebSocketClient
1212
import org.finos.vuu.net.{AlwaysHappyLoginValidator, ViewServerClient, WebSocketViewServerClient}
13+
1314
import java.security.SecureRandom
1415

1516
class TestStartUp(moduleFactoryFunc: () => ViewServerModule)(
@@ -33,8 +34,8 @@ class TestStartUp(moduleFactoryFunc: () => ViewServerModule)(
3334

3435
val config = VuuServerConfig(
3536
VuuHttp2ServerOptions()
37+
.withWebRoot(WebRootDisabled())
3638
.withSslDisabled()
37-
.withDirectoryListings(true)
3839
.withPort(http),
3940
VuuWebSocketOptions()
4041
.withBindAddress("0.0.0.0")

0 commit comments

Comments
 (0)