summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-api
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-04-06 15:35:09 +0200
committerGitHub <noreply@github.com>2022-04-06 15:35:09 +0200
commit0d4f19003324e196fffae3f252786e30197dfa4c (patch)
tree08ba4eb3b0e067ae933c636ca3967c45058fd69f /opendc-web/opendc-web-api
parentaf87540d49d58c465f0847c016814d58cfeb44fc (diff)
parent9f0b7ddd0d62e4dc43a69ea8fafd06be1a663f9f (diff)
merge: Integrate UI into Quarkus web application (#69)
This pull request adds a Quarkus extension that integrates with the existing Quarkus web application to provide access to the OpenDC web UI. The benefit of this approach is that in this way, OpenDC can be distributed as a single JVM application to the user, which can host its own web UI directly. Furthermore, this pull request also adds support for unauthenticated access to the API when accessing in dev mode, so that users do not have to setup Auth0 in order to use OpenDC locally. ## Implementation Notes :hammer_and_pick: * Do not use next/image * Migrate to next-global-css * Update PatternFly to latest version * Add Gradle integration with Next.js project * Build web UI via Gradle * Support building WebJar for OpenDC web UI * Add extension for serving OpenDC web UI * Include web UI in development mode * Add workaround for Quarkus Gradle build issues * Add support for unauthenticated user access ## External Dependencies :four_leaf_clover: * [node-gradle](https://github.com/node-gradle/gradle-node-plugin)
Diffstat (limited to 'opendc-web/opendc-web-api')
-rw-r--r--opendc-web/opendc-web-api/build.gradle.kts21
-rw-r--r--opendc-web/opendc-web-api/src/main/kotlin/org/opendc/web/api/util/DevSecurityOverrideFilter.kt51
-rw-r--r--opendc-web/opendc-web-api/src/main/resources/application-dev.properties12
-rw-r--r--opendc-web/opendc-web-api/src/main/resources/application-prod.properties3
-rw-r--r--opendc-web/opendc-web-api/src/main/resources/application-test.properties3
5 files changed, 87 insertions, 3 deletions
diff --git a/opendc-web/opendc-web-api/build.gradle.kts b/opendc-web/opendc-web-api/build.gradle.kts
index 853632a7..ca01e0c8 100644
--- a/opendc-web/opendc-web-api/build.gradle.kts
+++ b/opendc-web/opendc-web-api/build.gradle.kts
@@ -36,6 +36,7 @@ dependencies {
implementation(enforcedPlatform(libs.quarkus.bom))
implementation(projects.opendcWeb.opendcWebProto)
+ implementation(projects.opendcWeb.opendcWebUiQuarkus.runtime)
implementation(libs.quarkus.kotlin)
implementation(libs.quarkus.resteasy.core)
@@ -78,16 +79,30 @@ tasks.quarkusDev {
tasks.test {
extensions.configure(JacocoTaskExtension::class) {
excludeClassLoaders = listOf("*QuarkusClassLoader")
- // destinationFile = layout.buildDirectory.file("jacoco-quarkus.exec").get().asFile
}
}
/* Fix for Quarkus/ktlint-gradle incompatibilities */
-tasks.named("runKtlintCheckOverMainSourceSet").configure {
+tasks.named("runKtlintCheckOverMainSourceSet") {
mustRunAfter(tasks.quarkusGenerateCode)
mustRunAfter(tasks.quarkusGenerateCodeDev)
}
-tasks.named("runKtlintCheckOverTestSourceSet").configure {
+tasks.named("runKtlintCheckOverTestSourceSet") {
mustRunAfter(tasks.quarkusGenerateCodeTests)
}
+
+/* Fix for Quarkus/Gradle issues */
+tasks.quarkusGenerateCode {
+ mustRunAfter(projects.opendcWeb.opendcWebUiQuarkus.deployment)
+ mustRunAfter(projects.opendcWeb.opendcWebUi)
+
+ doFirst {
+ mkdir("${projects.opendcWeb.opendcWebUi.dependencyProject.buildDir}/classes/java/main")
+ }
+}
+
+tasks.quarkusGenerateCodeTests {
+ mustRunAfter(projects.opendcWeb.opendcWebUiQuarkus.deployment)
+ mustRunAfter(projects.opendcWeb.opendcWebUi)
+}
diff --git a/opendc-web/opendc-web-api/src/main/kotlin/org/opendc/web/api/util/DevSecurityOverrideFilter.kt b/opendc-web/opendc-web-api/src/main/kotlin/org/opendc/web/api/util/DevSecurityOverrideFilter.kt
new file mode 100644
index 00000000..ba2cf2ae
--- /dev/null
+++ b/opendc-web/opendc-web-api/src/main/kotlin/org/opendc/web/api/util/DevSecurityOverrideFilter.kt
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2022 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.web.api.util
+
+import io.quarkus.arc.properties.IfBuildProperty
+import java.security.Principal
+import javax.ws.rs.container.ContainerRequestContext
+import javax.ws.rs.container.ContainerRequestFilter
+import javax.ws.rs.container.PreMatching
+import javax.ws.rs.core.SecurityContext
+import javax.ws.rs.ext.Provider
+
+/**
+ * Helper class to disable security for the OpenDC web API when in development mode.
+ */
+@Provider
+@PreMatching
+@IfBuildProperty(name = "opendc.security.enabled", stringValue = "false")
+class DevSecurityOverrideFilter : ContainerRequestFilter {
+ override fun filter(requestContext: ContainerRequestContext) {
+ requestContext.securityContext = object : SecurityContext {
+ override fun getUserPrincipal(): Principal = Principal { "anon" }
+
+ override fun isSecure(): Boolean = false
+
+ override fun isUserInRole(role: String): Boolean = true
+
+ override fun getAuthenticationScheme(): String = "basic"
+ }
+ }
+}
diff --git a/opendc-web/opendc-web-api/src/main/resources/application-dev.properties b/opendc-web/opendc-web-api/src/main/resources/application-dev.properties
index 84da528f..08d11609 100644
--- a/opendc-web/opendc-web-api/src/main/resources/application-dev.properties
+++ b/opendc-web/opendc-web-api/src/main/resources/application-dev.properties
@@ -26,3 +26,15 @@ quarkus.datasource.jdbc.url=jdbc:h2:mem:default;DB_CLOSE_DELAY=-1;INIT=CREATE TY
quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.sql-load-script=init-dev.sql
+
+# OpenID
+quarkus.oidc.enabled=false
+quarkus.oidc.auth-server-url=
+quarkus.oidc.client-id=
+
+# OpenDC web UI
+quarkus.opendc-ui.path=/
+quarkus.resteasy.path=/api
+
+opendc.security.enabled=false
+
diff --git a/opendc-web/opendc-web-api/src/main/resources/application-prod.properties b/opendc-web/opendc-web-api/src/main/resources/application-prod.properties
index 3af1dfd9..8f523d76 100644
--- a/opendc-web/opendc-web-api/src/main/resources/application-prod.properties
+++ b/opendc-web/opendc-web-api/src/main/resources/application-prod.properties
@@ -27,3 +27,6 @@ quarkus.datasource.jdbc.url=${OPENDC_DB_URL}
# Hibernate
quarkus.hibernate-orm.dialect=org.hibernate.dialect.PostgreSQL95Dialect
quarkus.hibernate-orm.database.generation=validate
+
+# Disable OpenDC web UI
+quarkus.opendc-ui.include=false
diff --git a/opendc-web/opendc-web-api/src/main/resources/application-test.properties b/opendc-web/opendc-web-api/src/main/resources/application-test.properties
index 0710f200..ea07de6e 100644
--- a/opendc-web/opendc-web-api/src/main/resources/application-test.properties
+++ b/opendc-web/opendc-web-api/src/main/resources/application-test.properties
@@ -34,3 +34,6 @@ quarkus.oidc.client-id=
quarkus.smallrye-openapi.enable=false
quarkus.swagger-ui.enable=false
quarkus.smallrye-openapi.oidc-open-id-connect-url=
+
+# Disable OpenDC web UI
+quarkus.opendc-ui.include=false