From 93062317a7574676bae8c80c501825088036238e Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Mon, 28 Mar 2022 11:09:21 +0200 Subject: [PATCH 1/8] Bump dev version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 115d0a9..ef90c67 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ plugins { allprojects { group = "org.radarbase" - version = "0.8.3" + version = "0.8.4-SNAPSHOT" } subprojects { From 2a16d0adea44c2af74b29220c7008f449252dca0 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Mon, 16 May 2022 10:51:44 +0200 Subject: [PATCH 2/8] Updated snyk workflow --- .github/workflows/scheduled_snyk.yaml | 12 ++++++++---- .github/workflows/snyk.yaml | 9 +++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/scheduled_snyk.yaml b/.github/workflows/scheduled_snyk.yaml index 6a150ce..f581302 100644 --- a/.github/workflows/scheduled_snyk.yaml +++ b/.github/workflows/scheduled_snyk.yaml @@ -8,21 +8,25 @@ jobs: env: REPORT_FILE: test.json steps: - - uses: actions/checkout@master + - uses: actions/checkout@v3 - uses: snyk/actions/setup@master + with: + snyk-version: v1.931.0 - - uses: actions/setup-java@v2 + - uses: actions/setup-java@v3 with: - distribution: zulu + distribution: temurin java-version: 11 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + - name: Run Snyk env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} run: > snyk test --configuration-matching='^runtimeClasspath$' - --configuration-matching='^compileClasspath$' --json-file-output=${{ env.REPORT_FILE }} --org=radar-base --sub-project=radar-jersey diff --git a/.github/workflows/snyk.yaml b/.github/workflows/snyk.yaml index 6f8d206..e959e9c 100644 --- a/.github/workflows/snyk.yaml +++ b/.github/workflows/snyk.yaml @@ -7,12 +7,14 @@ jobs: security: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v3 - uses: snyk/actions/setup@master + with: + snyk-version: v1.931.0 - - uses: actions/setup-java@v2 + - uses: actions/setup-java@v3 with: - distribution: zulu + distribution: temurin java-version: 11 - name: Setup Gradle @@ -24,7 +26,6 @@ jobs: run: > snyk test --configuration-matching='^runtimeClasspath$' - --configuration-matching='^compileClasspath$' --fail-on=upgradable --org=radar-base --sub-project=radar-jersey From 6180aea0e844085f7509ac3a58b99a245f8e9e27 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Wed, 1 Jun 2022 16:39:07 +0200 Subject: [PATCH 3/8] Added help flag support and ConfigLoader code style --- .../radarbase/jersey/config/ConfigLoader.kt | 87 ++++++++++++------- 1 file changed, 56 insertions(+), 31 deletions(-) diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt index 2b201a1..7e274fb 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt @@ -12,6 +12,8 @@ import java.io.BufferedInputStream import java.io.IOException import java.nio.file.Files import java.nio.file.Paths +import kotlin.io.path.Path +import kotlin.io.path.exists import kotlin.system.exitProcess object ConfigLoader { @@ -25,28 +27,46 @@ object ConfigLoader { * @throws NoSuchMethodException if the constructor cannot be found * @throws ReflectiveOperationException if the class cannot be instantiated */ - fun loadResources(factoryClass: Class, vararg parameters: Any): ResourceConfig { - val parameterClasses = parameters.map { it.javaClass }.toTypedArray() - val enhancerFactory = factoryClass.getConstructor(*parameterClasses) - .newInstance(*parameters) + fun loadResources( + factoryClass: Class, + vararg parameters: Any, + ): ResourceConfig { + val enhancerFactory = factoryClass + .getConstructor(*parameters.map { it.javaClass }.toTypedArray()) + .newInstance(*parameters) return createResourceConfig(enhancerFactory.createEnhancers()) } @JvmOverloads - fun loadConfig(fileName: String, args: Array, clazz: Class, mapper: ObjectMapper? = null): T = - loadConfig(listOf(fileName), args, clazz, mapper) + fun loadConfig( + fileName: String, + args: Array, + clazz: Class, + mapper: ObjectMapper? = null, + ): T = loadConfig(listOf(fileName), args, clazz, mapper) @JvmOverloads - fun loadConfig(fileNames: List, args: Array, clazz: Class, mapper: ObjectMapper? = null): T { - val configFile = if (args.size == 1) Paths.get(args[0]) - else fileNames.map { Paths.get(it) }.find { Files.exists(it) } + fun loadConfig( + fileNames: List, + args: Array, + clazz: Class, + mapper: ObjectMapper? = null, + ): T { + if ("-h" in args || "--help" in args) { + logger.info("Usage: []") + exitProcess(0) + } + + val configFile = args.firstOrNull()?.let { Path(it) } + ?: fileNames.map { Path(it) }.firstOrNull { it.exists() } requireNotNull(configFile) { "Configuration not provided." } logger.info("Reading configuration from {}", configFile.toAbsolutePath()) - try { + return try { val localMapper = mapper ?: ObjectMapper(YAMLFactory()) - .registerModule(kotlinModule()) - return Files.newInputStream(configFile).use { input -> + .registerModule(kotlinModule()) + + Files.newInputStream(configFile).use { input -> BufferedInputStream(input).use { bufInput -> localMapper.readValue(bufInput, clazz) } @@ -64,8 +84,11 @@ object ConfigLoader { * * @throws IllegalArgumentException if a file matching configFileName cannot be found */ - inline fun loadConfig(fileName: String, args: Array, mapper: ObjectMapper? = null): T = - loadConfig(listOf(fileName), args, T::class.java, mapper) + inline fun loadConfig( + fileName: String, + args: Array, + mapper: ObjectMapper? = null, + ): T = loadConfig(listOf(fileName), args, T::class.java, mapper) /** * Load a configuration from YAML file. The filename is searched in the current working @@ -73,29 +96,31 @@ object ConfigLoader { * * @throws IllegalArgumentException if a file matching configFileName cannot be found */ - inline fun loadConfig(fileNames: List, args: Array, mapper: ObjectMapper? = null): T = - loadConfig(fileNames, args, T::class.java, mapper) + inline fun loadConfig( + fileNames: List, + args: Array, + mapper: ObjectMapper? = null, + ): T = loadConfig(fileNames, args, T::class.java, mapper) /** * Create a resourceConfig based on the provided resource enhancers. This method also disables * the WADL since it may be identified as a security risk. */ - fun createResourceConfig(enhancers: List): ResourceConfig { - val resources = ResourceConfig() - resources.property("jersey.config.server.wadl.disableWadl", true) - enhancers.forEach { enhancer -> - resources.packages(*enhancer.packages) - resources.registerClasses(*enhancer.classes) - enhancer.enhanceResources(resources) - } - - resources.register(object : AbstractBinder() { - override fun configure() { - enhancers.forEach { it.enhanceBinder(this) } + fun createResourceConfig(enhancers: List): ResourceConfig = + ResourceConfig().apply { + property("jersey.config.server.wadl.disableWadl", true) + enhancers.forEach { enhancer -> + packages(*enhancer.packages) + registerClasses(*enhancer.classes) + enhancer.enhanceResources(this@apply) } - }) - return resources - } + + register(object : AbstractBinder() { + override fun configure() { + enhancers.forEach { it.enhanceBinder(this) } + } + }) + } val logger: Logger = LoggerFactory.getLogger(ConfigLoader::class.java) From 48ae5a508d02ee04502893ce809cb4a575e533eb Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Thu, 2 Jun 2022 11:06:58 +0200 Subject: [PATCH 4/8] Improve logging without health messages --- .../kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt index 2c4f2df..a8daeb3 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt @@ -28,7 +28,7 @@ class ResponseLoggerFilter : ContainerResponseFilter { when { path == null -> return status == null -> return - path.endsWith("/health") && status == 200 -> return + (path == "health" || path.endsWith("/health")) && status == 200 -> return requestContext.mediaType == null -> logger.info( "[{}] {} {} -- <{}> ", status, From 45f6ca0fad01b14c43368f45c52af601c5214ad6 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Thu, 2 Jun 2022 11:10:00 +0200 Subject: [PATCH 5/8] Improve readability --- .../org/radarbase/jersey/filter/ResponseLoggerFilter.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt index a8daeb3..db6f8a5 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt @@ -28,7 +28,7 @@ class ResponseLoggerFilter : ContainerResponseFilter { when { path == null -> return status == null -> return - (path == "health" || path.endsWith("/health")) && status == 200 -> return + path.isHealthEndpoint && status == 200 -> return requestContext.mediaType == null -> logger.info( "[{}] {} {} -- <{}> ", status, @@ -58,5 +58,8 @@ class ResponseLoggerFilter : ContainerResponseFilter { companion object { private val logger = LoggerFactory.getLogger(ResponseLoggerFilter::class.java) + /** Whether given path matches a health endpoint. */ + private inline val String.isHealthEndpoint: Boolean + get() = this == "health" || endsWith("/health") } } From f66419a088c7b7f27c743e2f675444ad52af41fe Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Wed, 13 Jul 2022 10:15:53 +0200 Subject: [PATCH 6/8] Updated dependencies Includes update from javax.persistence to jakarta.persistence --- build.gradle.kts | 2 +- gradle.properties | 44 ++++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- radar-jersey-hibernate/build.gradle.kts | 8 +++- .../jersey/hibernate/DatabaseHealthMetrics.kt | 17 +++---- .../hibernate/DatabaseInitialization.kt | 21 ++++++--- .../jersey/hibernate/HibernateRepository.kt | 6 +-- .../hibernate/RadarEntityManagerFactory.kt | 8 +--- .../RadarEntityManagerFactoryFactory.kt | 6 +-- .../hibernate/config/CloseableTransaction.kt | 2 +- .../config/HibernateResourceEnhancer.kt | 6 +-- .../hibernate/config/RadarPersistenceInfo.kt | 20 ++++----- .../hibernate/DatabaseHealthMetricsTest.kt | 7 +-- .../jersey/hibernate/db/ProjectDao.kt | 2 +- .../hibernate/db/ProjectRepositoryImpl.kt | 4 +- .../hibernate/mock/MockProjectService.kt | 2 +- .../hibernate/mock/MockResourceEnhancer.kt | 4 +- .../mock/resource/ProjectResource.kt | 4 +- .../org/radarbase/jersey/GrizzlyServer.kt | 32 ++++++++------ .../radarbase/jersey/auth/AuthValidator.kt | 3 +- .../auth/disabled/DisabledAuthValidator.kt | 4 +- .../DisabledAuthorizationResourceEnhancer.kt | 2 +- .../auth/filter/AuthenticationFilter.kt | 8 ++-- .../auth/filter/AuthorizationFeature.kt | 2 +- .../jersey/auth/filter/PermissionFilter.kt | 10 ++--- .../auth/filter/RadarSecurityContext.kt | 2 +- .../radarbase/jersey/auth/jwt/AuthFactory.kt | 4 +- .../jersey/auth/jwt/EcdsaJwtTokenValidator.kt | 4 +- .../jersey/auth/jwt/EcdsaResourceEnhancer.kt | 2 +- .../ManagementPortalResourceEnhancer.kt | 4 +- .../ManagementPortalTokenValidator.kt | 4 +- .../managementportal/TokenValidatorFactory.kt | 2 +- .../jersey/cache/CacheControlFeature.kt | 2 +- .../jersey/cache/CacheControlFilter.kt | 2 +- .../radarbase/jersey/config/ConfigLoader.kt | 4 +- .../jersey/enhancer/HealthResourceEnhancer.kt | 2 +- .../mapper/JsonProcessingExceptionMapper.kt | 2 +- .../mapper/UnhandledExceptionMapper.kt | 2 +- .../org/radarbase/jersey/filter/CorsFilter.kt | 3 +- .../jersey/filter/ResponseLoggerFilter.kt | 2 +- .../jersey/resource/HealthResource.kt | 2 +- .../jersey/service/ImmediateHealthService.kt | 2 +- .../managementportal/MPClientFactory.kt | 2 +- .../managementportal/ProjectServiceWrapper.kt | 4 +- .../radarbase/jersey/auth/AuthConfigTest.kt | 1 - .../jersey/config/ConfigLoaderTest.kt | 3 +- .../enhancer/MapperResourceEnhancerTest.kt | 5 ++- .../jersey/mock/resource/MockResource.kt | 8 ++-- 48 files changed, 153 insertions(+), 141 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ef90c67..574169b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -208,5 +208,5 @@ nexusPublishing { } tasks.wrapper { - gradleVersion = "7.4.1" + gradleVersion = "7.4.2" } diff --git a/gradle.properties b/gradle.properties index 18efaf9..85d8557 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,34 +3,36 @@ org.gradle.jvmargs=-Xmx2000m org.gradle.vfs.watch=true kotlin.code.style=official -kotlinVersion=1.6.10 -dokkaVersion=1.6.10 -jsoupVersion=1.14.3 +kotlinVersion=1.7.10 +dokkaVersion=1.7.0 +jsoupVersion=1.15.2 -jerseyVersion=3.0.4 -grizzlyVersion=3.0.1 -okhttpVersion=4.9.3 +jerseyVersion=3.0.5 +grizzlyVersion=4.0.0 +okhttpVersion=4.10.0 junitVersion=5.8.2 hamcrestVersion=2.2 mockitoKotlinVersion=4.0.0 -hk2Version=3.0.2 +hk2Version=3.0.3 managementPortalVersion=0.8.1 -javaJwtVersion=3.19.0 -jakartaWsRsVersion=3.0.0 -jakartaAnnotationVersion=2.0.0 -jacksonVersion=2.13.2.20220324 +javaJwtVersion=4.0.0 +jakartaWsRsVersion=3.1.0 +jakartaAnnotationVersion=2.1.1 +jacksonVersion=2.13.3 slf4jVersion=1.7.36 -log4j2Version=2.17.2 -jakartaXmlBindVersion=3.0.1 -jakartaJaxbCoreVersion=3.0.2 -jakartaJaxbRuntimeVersion=3.0.2 -javaxValidationVersion=2.0.1.Final +log4j2Version=2.18.0 +jakartaXmlBindVersion=4.0.0 +jakartaJaxbCoreVersion=4.0.0 +jakartaJaxbRuntimeVersion=4.0.0 +jakartaValidationVersion=3.0.2 +hibernateValidatorVersion=7.0.4.Final +glassfishJakartaElVersion=4.0.2 jakartaActivation=2.1.0 -swaggerVersion=2.1.13 +swaggerVersion=2.2.1 mustacheVersion=0.9.10 -hibernateVersion=5.6.7.Final -liquibaseVersion=4.9.0 -postgresVersion=42.3.3 -h2Version=2.1.210 +hibernateVersion=6.1.1.Final +liquibaseVersion=4.13.0 +postgresVersion=42.4.0 +h2Version=2.1.214 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 00e33ed..aa991fc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/radar-jersey-hibernate/build.gradle.kts b/radar-jersey-hibernate/build.gradle.kts index d20a1a8..3154683 100644 --- a/radar-jersey-hibernate/build.gradle.kts +++ b/radar-jersey-hibernate/build.gradle.kts @@ -14,8 +14,12 @@ dependencies { api("org.hibernate:hibernate-core:$hibernateVersion") runtimeOnly("org.hibernate:hibernate-c3p0:$hibernateVersion") - val javaxValidationVersion: String by project - implementation("javax.validation:validation-api:$javaxValidationVersion") + val jakartaValidationVersion: String by project + runtimeOnly("jakarta.validation:jakarta.validation-api:$jakartaValidationVersion") + val hibernateValidatorVersion: String by project + runtimeOnly("org.hibernate.validator:hibernate-validator:$hibernateValidatorVersion") + val glassfishJakartaElVersion: String by project + runtimeOnly("org.glassfish:jakarta.el:$glassfishJakartaElVersion") val slf4jVersion: String by project implementation("org.slf4j:slf4j-api:$slf4jVersion") diff --git a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/DatabaseHealthMetrics.kt b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/DatabaseHealthMetrics.kt index 2462dc7..4df1339 100644 --- a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/DatabaseHealthMetrics.kt +++ b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/DatabaseHealthMetrics.kt @@ -1,26 +1,27 @@ package org.radarbase.jersey.hibernate import jakarta.inject.Provider +import jakarta.persistence.EntityManager import jakarta.ws.rs.core.Context -import org.radarbase.jersey.hibernate.RadarEntityManagerFactory.Companion.connection +import org.radarbase.jersey.hibernate.DatabaseInitialization.Companion.useConnection import org.radarbase.jersey.hibernate.config.DatabaseConfig import org.radarbase.jersey.service.HealthService import org.radarbase.jersey.service.HealthService.Metric import org.radarbase.jersey.util.CacheConfig import org.radarbase.jersey.util.CachedValue import java.time.Duration -import javax.persistence.EntityManager class DatabaseHealthMetrics( @Context private val entityManager: Provider, @Context dbConfig: DatabaseConfig ): Metric(name = "db") { private val cachedStatus = CachedValue( - CacheConfig( - refreshDuration = Duration.ofSeconds(dbConfig.healthCheckValiditySeconds), - retryDuration = Duration.ofSeconds(dbConfig.healthCheckValiditySeconds), - ), - ::testConnection) + CacheConfig( + refreshDuration = Duration.ofSeconds(dbConfig.healthCheckValiditySeconds), + retryDuration = Duration.ofSeconds(dbConfig.healthCheckValiditySeconds), + ), + ::testConnection, + ) override val status: HealthService.Status get() = cachedStatus.get { it == HealthService.Status.UP } @@ -29,7 +30,7 @@ class DatabaseHealthMetrics( get() = mapOf("status" to status) private fun testConnection(): HealthService.Status = try { - entityManager.get().connection().close() + entityManager.get().useConnection { connection -> connection.close() } HealthService.Status.UP } catch (ex: Throwable) { HealthService.Status.DOWN diff --git a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/DatabaseInitialization.kt b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/DatabaseInitialization.kt index a2ed2f8..8f09901 100644 --- a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/DatabaseInitialization.kt +++ b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/DatabaseInitialization.kt @@ -1,5 +1,9 @@ package org.radarbase.jersey.hibernate +import jakarta.persistence.EntityManager +import jakarta.persistence.EntityManagerFactory +import jakarta.ws.rs.core.Context +import jakarta.ws.rs.ext.Provider import liquibase.Contexts import liquibase.Liquibase import liquibase.database.DatabaseFactory @@ -9,14 +13,12 @@ import org.glassfish.jersey.server.monitoring.ApplicationEvent import org.glassfish.jersey.server.monitoring.ApplicationEventListener import org.glassfish.jersey.server.monitoring.RequestEvent import org.glassfish.jersey.server.monitoring.RequestEventListener -import org.radarbase.jersey.hibernate.RadarEntityManagerFactory.Companion.connection +import org.hibernate.HibernateException +import org.hibernate.Session import org.radarbase.jersey.hibernate.RadarEntityManagerFactoryFactory.Companion.useEntityManager import org.radarbase.jersey.hibernate.config.DatabaseConfig import org.slf4j.LoggerFactory import java.sql.Connection -import javax.persistence.EntityManagerFactory -import jakarta.ws.rs.core.Context -import jakarta.ws.rs.ext.Provider @Provider class DatabaseInitialization( @@ -27,9 +29,8 @@ class DatabaseInitialization( override fun onEvent(event: ApplicationEvent) { if (event.type != ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) return try { - entityManagerFactory.get().useEntityManager { - // make first connection - it.connection().use { connection -> + entityManagerFactory.get().useEntityManager { em -> + em.useConnection { connection -> if (dbConfig.liquibase.enable) { initializeLiquibase(connection) } @@ -56,5 +57,11 @@ class DatabaseInitialization( companion object { private val logger = LoggerFactory.getLogger(DatabaseInitialization::class.java) + + @Throws(HibernateException::class) + fun EntityManager.useConnection(work: (Connection) -> Unit) { + check(this is Session) { "Cannot use connection of EntityManager that is not a Hibernate Session" } + doWork(work) + } } } diff --git a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/HibernateRepository.kt b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/HibernateRepository.kt index 742a624..250c480 100644 --- a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/HibernateRepository.kt +++ b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/HibernateRepository.kt @@ -1,11 +1,11 @@ package org.radarbase.jersey.hibernate +import jakarta.inject.Provider +import jakarta.persistence.EntityManager +import jakarta.persistence.EntityTransaction import org.radarbase.jersey.exception.HttpInternalServerException import org.radarbase.jersey.hibernate.config.CloseableTransaction import org.slf4j.LoggerFactory -import jakarta.inject.Provider -import javax.persistence.EntityManager -import javax.persistence.EntityTransaction open class HibernateRepository( private val entityManagerProvider: Provider diff --git a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/RadarEntityManagerFactory.kt b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/RadarEntityManagerFactory.kt index 5482b5e..717d0df 100644 --- a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/RadarEntityManagerFactory.kt +++ b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/RadarEntityManagerFactory.kt @@ -1,12 +1,10 @@ package org.radarbase.jersey.hibernate +import jakarta.persistence.EntityManager +import jakarta.persistence.EntityManagerFactory import jakarta.ws.rs.core.Context import org.glassfish.jersey.internal.inject.DisposableSupplier -import org.hibernate.internal.SessionImpl import org.slf4j.LoggerFactory -import java.sql.Connection -import javax.persistence.EntityManager -import javax.persistence.EntityManagerFactory class RadarEntityManagerFactory( @Context private val emf: EntityManagerFactory @@ -26,7 +24,5 @@ class RadarEntityManagerFactory( companion object { private val logger = LoggerFactory.getLogger(RadarEntityManagerFactory::class.java) - - fun EntityManager.connection(): Connection = unwrap(SessionImpl::class.java).connection() } } diff --git a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/RadarEntityManagerFactoryFactory.kt b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/RadarEntityManagerFactoryFactory.kt index c363e7d..a4fb71e 100644 --- a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/RadarEntityManagerFactoryFactory.kt +++ b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/RadarEntityManagerFactoryFactory.kt @@ -1,14 +1,14 @@ package org.radarbase.jersey.hibernate +import jakarta.persistence.EntityManager +import jakarta.persistence.EntityManagerFactory +import jakarta.ws.rs.core.Context import org.glassfish.jersey.internal.inject.DisposableSupplier import org.hibernate.jpa.HibernatePersistenceProvider import org.radarbase.jersey.hibernate.config.DatabaseConfig import org.radarbase.jersey.hibernate.config.RadarPersistenceInfo import org.slf4j.LoggerFactory import java.util.* -import javax.persistence.EntityManager -import javax.persistence.EntityManagerFactory -import jakarta.ws.rs.core.Context /** * Creates EntityManagerFactory using Hibernate. When an [EntityManagerFactory] is created, diff --git a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/CloseableTransaction.kt b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/CloseableTransaction.kt index aad87e7..d4f37e2 100644 --- a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/CloseableTransaction.kt +++ b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/CloseableTransaction.kt @@ -1,7 +1,7 @@ package org.radarbase.jersey.hibernate.config +import jakarta.persistence.EntityTransaction import java.io.Closeable -import javax.persistence.EntityTransaction interface CloseableTransaction : Closeable { val transaction: EntityTransaction diff --git a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/HibernateResourceEnhancer.kt b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/HibernateResourceEnhancer.kt index c8f68e2..6cf1968 100644 --- a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/HibernateResourceEnhancer.kt +++ b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/HibernateResourceEnhancer.kt @@ -1,5 +1,8 @@ package org.radarbase.jersey.hibernate.config +import jakarta.inject.Singleton +import jakarta.persistence.EntityManager +import jakarta.persistence.EntityManagerFactory import org.glassfish.jersey.internal.inject.AbstractBinder import org.glassfish.jersey.process.internal.RequestScoped import org.radarbase.jersey.enhancer.JerseyResourceEnhancer @@ -8,9 +11,6 @@ import org.radarbase.jersey.hibernate.DatabaseInitialization import org.radarbase.jersey.hibernate.RadarEntityManagerFactory import org.radarbase.jersey.hibernate.RadarEntityManagerFactoryFactory import org.radarbase.jersey.service.HealthService -import jakarta.inject.Singleton -import javax.persistence.EntityManager -import javax.persistence.EntityManagerFactory class HibernateResourceEnhancer( private val databaseConfig: DatabaseConfig diff --git a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/RadarPersistenceInfo.kt b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/RadarPersistenceInfo.kt index 275713f..1ea8ee3 100644 --- a/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/RadarPersistenceInfo.kt +++ b/radar-jersey-hibernate/src/main/kotlin/org/radarbase/jersey/hibernate/config/RadarPersistenceInfo.kt @@ -1,13 +1,13 @@ package org.radarbase.jersey.hibernate.config +import jakarta.persistence.SharedCacheMode +import jakarta.persistence.ValidationMode +import jakarta.persistence.spi.ClassTransformer +import jakarta.persistence.spi.PersistenceUnitInfo +import jakarta.persistence.spi.PersistenceUnitTransactionType import org.hibernate.jpa.HibernatePersistenceProvider import java.net.URL import java.util.* -import javax.persistence.SharedCacheMode -import javax.persistence.ValidationMode -import javax.persistence.spi.ClassTransformer -import javax.persistence.spi.PersistenceUnitInfo -import javax.persistence.spi.PersistenceUnitTransactionType import javax.sql.DataSource class RadarPersistenceInfo( @@ -15,7 +15,7 @@ class RadarPersistenceInfo( ): PersistenceUnitInfo { @Suppress("UNCHECKED_CAST") private val properties: Properties = Properties().apply { - put("javax.persistence.schema-generation.database.action", "none") + put("jakarta.persistence.schema-generation.database.action", "none") put("org.hibernate.flushMode", "COMMIT") put("hibernate.connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider") put("hibernate.c3p0.max_size", "50") @@ -29,10 +29,10 @@ class RadarPersistenceInfo( put("hibernate.c3p0.breakAfterAcquireFailure", "false") putAll((mapOf( - "javax.persistence.jdbc.driver" to config.driver, - "javax.persistence.jdbc.url" to config.url, - "javax.persistence.jdbc.user" to config.user, - "javax.persistence.jdbc.password" to config.password, + "jakarta.persistence.jdbc.driver" to config.driver, + "jakarta.persistence.jdbc.url" to config.url, + "jakarta.persistence.jdbc.user" to config.user, + "jakarta.persistence.jdbc.password" to config.password, "hibernate.dialect" to config.dialect) + config.properties) .filterValues { it != null } as Map) diff --git a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/DatabaseHealthMetricsTest.kt b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/DatabaseHealthMetricsTest.kt index 1d16152..9cb53e1 100644 --- a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/DatabaseHealthMetricsTest.kt +++ b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/DatabaseHealthMetricsTest.kt @@ -2,9 +2,7 @@ package org.radarbase.jersey.hibernate import okhttp3.OkHttpClient import okhttp3.Request -import org.hamcrest.MatcherAssert import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers import org.hamcrest.Matchers.`is` import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test @@ -42,7 +40,10 @@ internal class DatabaseHealthMetricsTest { .url("http://localhost:9091/health") .build()).execute().use { response -> assertThat(response.isSuccessful, `is`(true)) - assertThat(response.body?.string(), equalTo("{\"status\":\"UP\",\"db\":{\"status\":\"UP\"}}")) + assertThat( + response.body?.string(), + equalTo("{\"status\":\"UP\",\"db\":{\"status\":\"UP\"}}"), + ) } } finally { server.shutdown() diff --git a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/db/ProjectDao.kt b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/db/ProjectDao.kt index 4b2c4b2..a150ac4 100644 --- a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/db/ProjectDao.kt +++ b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/db/ProjectDao.kt @@ -1,6 +1,6 @@ package org.radarbase.jersey.hibernate.db -import javax.persistence.* +import jakarta.persistence.* @Entity(name = "Project") @Table(name = "project") diff --git a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/db/ProjectRepositoryImpl.kt b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/db/ProjectRepositoryImpl.kt index e11e59c..0477d16 100644 --- a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/db/ProjectRepositoryImpl.kt +++ b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/db/ProjectRepositoryImpl.kt @@ -1,9 +1,9 @@ package org.radarbase.jersey.hibernate.db -import org.radarbase.jersey.hibernate.HibernateRepository import jakarta.inject.Provider -import javax.persistence.EntityManager +import jakarta.persistence.EntityManager import jakarta.ws.rs.core.Context +import org.radarbase.jersey.hibernate.HibernateRepository class ProjectRepositoryImpl( @Context em: Provider diff --git a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/MockProjectService.kt b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/MockProjectService.kt index 68642be..b92cd18 100644 --- a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/MockProjectService.kt +++ b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/MockProjectService.kt @@ -9,10 +9,10 @@ package org.radarbase.jersey.hibernate.mock +import jakarta.ws.rs.core.Context import org.radarbase.jersey.exception.HttpNotFoundException import org.radarbase.jersey.hibernate.db.ProjectRepository import org.radarbase.jersey.service.ProjectService -import jakarta.ws.rs.core.Context class MockProjectService( @Context private val projects: ProjectRepository diff --git a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/MockResourceEnhancer.kt b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/MockResourceEnhancer.kt index 157bc43..1b965fc 100644 --- a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/MockResourceEnhancer.kt +++ b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/MockResourceEnhancer.kt @@ -1,12 +1,12 @@ package org.radarbase.jersey.hibernate.mock +import jakarta.inject.Singleton import org.glassfish.jersey.internal.inject.AbstractBinder import org.radarbase.jersey.enhancer.JerseyResourceEnhancer +import org.radarbase.jersey.filter.Filters import org.radarbase.jersey.hibernate.db.ProjectRepository import org.radarbase.jersey.hibernate.db.ProjectRepositoryImpl import org.radarbase.jersey.service.ProjectService -import jakarta.inject.Singleton -import org.radarbase.jersey.filter.Filters class MockResourceEnhancer : JerseyResourceEnhancer { override val classes: Array> = arrayOf( diff --git a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/resource/ProjectResource.kt b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/resource/ProjectResource.kt index e63a08d..37ef15e 100644 --- a/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/resource/ProjectResource.kt +++ b/radar-jersey-hibernate/src/test/kotlin/org/radarbase/jersey/hibernate/mock/resource/ProjectResource.kt @@ -1,10 +1,10 @@ package org.radarbase.jersey.hibernate.mock.resource +import jakarta.ws.rs.* +import jakarta.ws.rs.core.Context import org.radarbase.jersey.exception.HttpNotFoundException import org.radarbase.jersey.hibernate.db.ProjectDao import org.radarbase.jersey.hibernate.db.ProjectRepository -import jakarta.ws.rs.* -import jakarta.ws.rs.core.Context @Path("projects") @Consumes("application/json") diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt index 5176b5f..eea71d7 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt @@ -19,22 +19,26 @@ import java.util.concurrent.TimeUnit * Grizzly server wrapper. */ class GrizzlyServer( - /** Base URI for the server to listen at. */ - private val baseUri: URI, - /** ResourceConfig including all needed Jersey resources. */ - resources: ResourceConfig, - /** - * Whether to enable JMX. If true, ensure that additional JMX dependencies from Grizzly - * are imported. - */ - enableJmx: Boolean = false) { + /** Base URI for the server to listen at. */ + private val baseUri: URI, + /** ResourceConfig including all needed Jersey resources. */ + resources: ResourceConfig, + /** + * Whether to enable JMX. If true, ensure that additional JMX dependencies from Grizzly + * are imported. + */ + enableJmx: Boolean = false, +) { private val server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resources) - .also { it.serverConfiguration.isJmxEnabled = enableJmx } + .also { it.serverConfiguration.isJmxEnabled = enableJmx } - private val shutdownHook = Thread({ - logger.info("Stopping HTTP server...") - server.shutdown() - }, "shutdownHook") + private val shutdownHook = Thread( + { + logger.info("Stopping HTTP server...") + server.shutdown() + }, + "shutdownHook", + ) /** Start the server. This is a non-blocking call. */ fun start() { diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/AuthValidator.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/AuthValidator.kt index 0399000..b76c22e 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/AuthValidator.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/AuthValidator.kt @@ -9,10 +9,9 @@ package org.radarbase.jersey.auth +import jakarta.ws.rs.container.ContainerRequestContext import org.radarbase.auth.exception.TokenValidationException import org.radarbase.jersey.auth.filter.AuthenticationFilter -import jakarta.ws.rs.container.ContainerRequestContext -import kotlin.jvm.Throws interface AuthValidator { @Throws(TokenValidationException::class) diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/disabled/DisabledAuthValidator.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/disabled/DisabledAuthValidator.kt index 02ad68d..3bcd98f 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/disabled/DisabledAuthValidator.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/disabled/DisabledAuthValidator.kt @@ -1,10 +1,10 @@ package org.radarbase.jersey.auth.disabled +import jakarta.ws.rs.container.ContainerRequestContext +import jakarta.ws.rs.core.Context import org.radarbase.jersey.auth.Auth import org.radarbase.jersey.auth.AuthConfig import org.radarbase.jersey.auth.AuthValidator -import jakarta.ws.rs.container.ContainerRequestContext -import jakarta.ws.rs.core.Context /** Authorization validator that grants permission to all resources. */ class DisabledAuthValidator( diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/disabled/DisabledAuthorizationResourceEnhancer.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/disabled/DisabledAuthorizationResourceEnhancer.kt index 523cde0..52aa330 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/disabled/DisabledAuthorizationResourceEnhancer.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/disabled/DisabledAuthorizationResourceEnhancer.kt @@ -9,9 +9,9 @@ package org.radarbase.jersey.auth.disabled +import jakarta.inject.Singleton import org.glassfish.jersey.internal.inject.AbstractBinder import org.radarbase.jersey.auth.AuthValidator -import jakarta.inject.Singleton import org.radarbase.jersey.enhancer.JerseyResourceEnhancer /** diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/AuthenticationFilter.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/AuthenticationFilter.kt index 6372eb9..a06b18b 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/AuthenticationFilter.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/AuthenticationFilter.kt @@ -9,10 +9,6 @@ package org.radarbase.jersey.auth.filter -import org.radarbase.auth.exception.TokenValidationException -import org.radarbase.jersey.auth.AuthValidator -import org.radarbase.jersey.auth.Authenticated -import org.radarbase.jersey.exception.HttpUnauthorizedException import jakarta.annotation.Priority import jakarta.inject.Singleton import jakarta.ws.rs.Priorities @@ -20,6 +16,10 @@ import jakarta.ws.rs.container.ContainerRequestContext import jakarta.ws.rs.container.ContainerRequestFilter import jakarta.ws.rs.core.Context import jakarta.ws.rs.ext.Provider +import org.radarbase.auth.exception.TokenValidationException +import org.radarbase.jersey.auth.AuthValidator +import org.radarbase.jersey.auth.Authenticated +import org.radarbase.jersey.exception.HttpUnauthorizedException /** * Authenticates user by a JWT in the bearer signed by the Management Portal. diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/AuthorizationFeature.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/AuthorizationFeature.kt index 9c8f321..edd180f 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/AuthorizationFeature.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/AuthorizationFeature.kt @@ -9,13 +9,13 @@ package org.radarbase.jersey.auth.filter -import org.radarbase.jersey.auth.NeedsPermission import jakarta.inject.Singleton import jakarta.ws.rs.Priorities import jakarta.ws.rs.container.DynamicFeature import jakarta.ws.rs.container.ResourceInfo import jakarta.ws.rs.core.FeatureContext import jakarta.ws.rs.ext.Provider +import org.radarbase.jersey.auth.NeedsPermission /** Authorization for different auth tags. */ @Provider diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/PermissionFilter.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/PermissionFilter.kt index cab3337..ed84530 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/PermissionFilter.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/PermissionFilter.kt @@ -9,16 +9,16 @@ package org.radarbase.jersey.auth.filter -import org.radarbase.auth.authorization.Permission -import org.radarbase.jersey.auth.Auth -import org.radarbase.jersey.auth.NeedsPermission -import org.radarbase.jersey.exception.HttpForbiddenException -import org.radarbase.jersey.service.ProjectService import jakarta.ws.rs.container.ContainerRequestContext import jakarta.ws.rs.container.ContainerRequestFilter import jakarta.ws.rs.container.ResourceInfo import jakarta.ws.rs.core.Context import jakarta.ws.rs.core.UriInfo +import org.radarbase.auth.authorization.Permission +import org.radarbase.jersey.auth.Auth +import org.radarbase.jersey.auth.NeedsPermission +import org.radarbase.jersey.exception.HttpForbiddenException +import org.radarbase.jersey.service.ProjectService /** * Check that the token has given permissions. diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/RadarSecurityContext.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/RadarSecurityContext.kt index c38060a..1c8ea6c 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/RadarSecurityContext.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/filter/RadarSecurityContext.kt @@ -9,9 +9,9 @@ package org.radarbase.jersey.auth.filter +import jakarta.ws.rs.core.SecurityContext import org.radarbase.jersey.auth.Auth import java.security.Principal -import jakarta.ws.rs.core.SecurityContext /** * Security context from currently parsed authentication. diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/AuthFactory.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/AuthFactory.kt index 0eb99ee..11d2a06 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/AuthFactory.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/AuthFactory.kt @@ -9,11 +9,11 @@ package org.radarbase.jersey.auth.jwt +import jakarta.ws.rs.container.ContainerRequestContext +import jakarta.ws.rs.core.Context import org.radarbase.jersey.auth.Auth import org.radarbase.jersey.auth.filter.RadarSecurityContext import java.util.function.Supplier -import jakarta.ws.rs.container.ContainerRequestContext -import jakarta.ws.rs.core.Context /** Generates radar tokens from the security context. */ class AuthFactory( diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/EcdsaJwtTokenValidator.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/EcdsaJwtTokenValidator.kt index 8ef8b6a..54c4f82 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/EcdsaJwtTokenValidator.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/EcdsaJwtTokenValidator.kt @@ -15,6 +15,8 @@ import com.auth0.jwt.algorithms.Algorithm import com.auth0.jwt.exceptions.AlgorithmMismatchException import com.auth0.jwt.exceptions.JWTVerificationException import com.auth0.jwt.exceptions.SignatureVerificationException +import jakarta.ws.rs.container.ContainerRequestContext +import jakarta.ws.rs.core.Context import org.radarbase.auth.exception.ConfigurationException import org.radarbase.jersey.auth.Auth import org.radarbase.jersey.auth.AuthConfig @@ -30,8 +32,6 @@ import java.security.interfaces.ECPublicKey import java.security.interfaces.RSAPublicKey import java.security.spec.X509EncodedKeySpec import java.util.* -import jakarta.ws.rs.container.ContainerRequestContext -import jakarta.ws.rs.core.Context class EcdsaJwtTokenValidator constructor(@Context private val config: AuthConfig) : AuthValidator { private val verifiers: List diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/EcdsaResourceEnhancer.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/EcdsaResourceEnhancer.kt index 6c71b66..86ba6d7 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/EcdsaResourceEnhancer.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/jwt/EcdsaResourceEnhancer.kt @@ -9,9 +9,9 @@ package org.radarbase.jersey.auth.jwt +import jakarta.inject.Singleton import org.glassfish.jersey.internal.inject.AbstractBinder import org.radarbase.jersey.auth.AuthValidator -import jakarta.inject.Singleton import org.radarbase.jersey.enhancer.JerseyResourceEnhancer /** diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/ManagementPortalResourceEnhancer.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/ManagementPortalResourceEnhancer.kt index 775323b..43f99d0 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/ManagementPortalResourceEnhancer.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/ManagementPortalResourceEnhancer.kt @@ -9,18 +9,18 @@ package org.radarbase.jersey.auth.managementportal +import jakarta.inject.Singleton import org.glassfish.jersey.internal.inject.AbstractBinder import org.radarbase.auth.authentication.TokenValidator import org.radarbase.jersey.auth.AuthConfig import org.radarbase.jersey.auth.AuthValidator +import org.radarbase.jersey.enhancer.JerseyResourceEnhancer import org.radarbase.jersey.service.ProjectService import org.radarbase.jersey.service.managementportal.MPClientFactory import org.radarbase.jersey.service.managementportal.MPProjectService import org.radarbase.jersey.service.managementportal.ProjectServiceWrapper import org.radarbase.jersey.service.managementportal.RadarProjectService import org.radarbase.management.client.MPClient -import jakarta.inject.Singleton -import org.radarbase.jersey.enhancer.JerseyResourceEnhancer /** * Registration for authorization against a ManagementPortal. It requires managementPortalUrl and diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/ManagementPortalTokenValidator.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/ManagementPortalTokenValidator.kt index 3d7dafd..0d8f52f 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/ManagementPortalTokenValidator.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/ManagementPortalTokenValidator.kt @@ -10,13 +10,13 @@ package org.radarbase.jersey.auth.managementportal import com.auth0.jwt.JWT +import jakarta.ws.rs.container.ContainerRequestContext +import jakarta.ws.rs.core.Context import org.radarbase.auth.authentication.TokenValidator import org.radarbase.auth.exception.TokenValidationException import org.radarbase.jersey.auth.Auth import org.radarbase.jersey.auth.AuthValidator import org.slf4j.LoggerFactory -import jakarta.ws.rs.container.ContainerRequestContext -import jakarta.ws.rs.core.Context /** Creates a TokenValidator based on the current management portal configuration. */ class ManagementPortalTokenValidator( diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/TokenValidatorFactory.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/TokenValidatorFactory.kt index a04d444..adb2270 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/TokenValidatorFactory.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/auth/managementportal/TokenValidatorFactory.kt @@ -9,12 +9,12 @@ package org.radarbase.jersey.auth.managementportal +import jakarta.ws.rs.core.Context import org.radarbase.auth.authentication.TokenValidator import org.radarbase.auth.config.TokenVerifierPublicKeyConfig import org.radarbase.jersey.auth.AuthConfig import java.net.URI import java.util.function.Supplier -import jakarta.ws.rs.core.Context class TokenValidatorFactory( @Context private val config: AuthConfig diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/cache/CacheControlFeature.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/cache/CacheControlFeature.kt index a591cdb..b39ba14 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/cache/CacheControlFeature.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/cache/CacheControlFeature.kt @@ -1,11 +1,11 @@ package org.radarbase.jersey.cache -import java.lang.reflect.AnnotatedElement import jakarta.ws.rs.GET import jakarta.ws.rs.container.DynamicFeature import jakarta.ws.rs.container.ResourceInfo import jakarta.ws.rs.core.CacheControl import jakarta.ws.rs.core.FeatureContext +import java.lang.reflect.AnnotatedElement /** * @author [Bill Burke](mailto:bill@burkecentral.com) diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/cache/CacheControlFilter.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/cache/CacheControlFilter.kt index 459de33..2934554 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/cache/CacheControlFilter.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/cache/CacheControlFilter.kt @@ -1,6 +1,5 @@ package org.radarbase.jersey.cache -import java.io.IOException import jakarta.annotation.Priority import jakarta.ws.rs.Priorities import jakarta.ws.rs.container.ContainerRequestContext @@ -8,6 +7,7 @@ import jakarta.ws.rs.container.ContainerResponseContext import jakarta.ws.rs.container.ContainerResponseFilter import jakarta.ws.rs.core.CacheControl import jakarta.ws.rs.core.HttpHeaders +import java.io.IOException /** * @author [Bill Burke](mailto:bill@burkecentral.com) diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt index 7e274fb..c4cad48 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/config/ConfigLoader.kt @@ -5,13 +5,13 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import com.fasterxml.jackson.module.kotlin.kotlinModule import org.glassfish.jersey.internal.inject.AbstractBinder import org.glassfish.jersey.server.ResourceConfig -import org.radarbase.jersey.enhancer.* +import org.radarbase.jersey.enhancer.EnhancerFactory +import org.radarbase.jersey.enhancer.JerseyResourceEnhancer import org.slf4j.Logger import org.slf4j.LoggerFactory import java.io.BufferedInputStream import java.io.IOException import java.nio.file.Files -import java.nio.file.Paths import kotlin.io.path.Path import kotlin.io.path.exists import kotlin.system.exitProcess diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/enhancer/HealthResourceEnhancer.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/enhancer/HealthResourceEnhancer.kt index 10aed2d..4471de8 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/enhancer/HealthResourceEnhancer.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/enhancer/HealthResourceEnhancer.kt @@ -1,10 +1,10 @@ package org.radarbase.jersey.enhancer +import jakarta.inject.Singleton import org.glassfish.jersey.internal.inject.AbstractBinder import org.radarbase.jersey.resource.HealthResource import org.radarbase.jersey.service.HealthService import org.radarbase.jersey.service.ImmediateHealthService -import jakarta.inject.Singleton class HealthResourceEnhancer: JerseyResourceEnhancer { override val classes: Array> = arrayOf(HealthResource::class.java) diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/exception/mapper/JsonProcessingExceptionMapper.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/exception/mapper/JsonProcessingExceptionMapper.kt index 3977223..d966503 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/exception/mapper/JsonProcessingExceptionMapper.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/exception/mapper/JsonProcessingExceptionMapper.kt @@ -10,7 +10,6 @@ package org.radarbase.jersey.exception.mapper import com.fasterxml.jackson.core.JsonProcessingException -import org.slf4j.LoggerFactory import jakarta.inject.Singleton import jakarta.ws.rs.container.ContainerRequestContext import jakarta.ws.rs.core.Context @@ -19,6 +18,7 @@ import jakarta.ws.rs.core.UriInfo import jakarta.ws.rs.ext.ExceptionMapper import jakarta.ws.rs.ext.Provider import org.radarbase.jersey.exception.HttpBadRequestException +import org.slf4j.LoggerFactory /** Handle exceptions without a specific mapper. */ @Provider diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/exception/mapper/UnhandledExceptionMapper.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/exception/mapper/UnhandledExceptionMapper.kt index 6cc43c1..a99a970 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/exception/mapper/UnhandledExceptionMapper.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/exception/mapper/UnhandledExceptionMapper.kt @@ -9,7 +9,6 @@ package org.radarbase.jersey.exception.mapper -import org.slf4j.LoggerFactory import jakarta.inject.Singleton import jakarta.ws.rs.container.ContainerRequestContext import jakarta.ws.rs.core.Context @@ -17,6 +16,7 @@ import jakarta.ws.rs.core.Response import jakarta.ws.rs.core.UriInfo import jakarta.ws.rs.ext.ExceptionMapper import jakarta.ws.rs.ext.Provider +import org.slf4j.LoggerFactory /** Handle exceptions without a specific mapper. */ @Provider diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/CorsFilter.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/CorsFilter.kt index e24ff7e..bfc5394 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/CorsFilter.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/CorsFilter.kt @@ -9,13 +9,12 @@ package org.radarbase.jersey.filter -import java.io.IOException import jakarta.inject.Singleton import jakarta.ws.rs.container.ContainerRequestContext import jakarta.ws.rs.container.ContainerResponseContext import jakarta.ws.rs.container.ContainerResponseFilter import jakarta.ws.rs.ext.Provider -import kotlin.jvm.Throws +import java.io.IOException @Provider @Singleton diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt index db6f8a5..c6ae174 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt @@ -9,12 +9,12 @@ package org.radarbase.jersey.filter -import org.slf4j.LoggerFactory import jakarta.inject.Singleton import jakarta.ws.rs.container.ContainerRequestContext import jakarta.ws.rs.container.ContainerResponseContext import jakarta.ws.rs.container.ContainerResponseFilter import jakarta.ws.rs.ext.Provider +import org.slf4j.LoggerFactory @Provider @Singleton diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/resource/HealthResource.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/resource/HealthResource.kt index f881b7b..8d9af79 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/resource/HealthResource.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/resource/HealthResource.kt @@ -1,6 +1,5 @@ package org.radarbase.jersey.resource -import org.radarbase.jersey.service.HealthService import jakarta.annotation.Resource import jakarta.inject.Singleton import jakarta.ws.rs.GET @@ -8,6 +7,7 @@ import jakarta.ws.rs.Path import jakarta.ws.rs.Produces import jakarta.ws.rs.core.Context import jakarta.ws.rs.core.MediaType.APPLICATION_JSON +import org.radarbase.jersey.service.HealthService @Path("/health") @Resource diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/ImmediateHealthService.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/ImmediateHealthService.kt index 0b29b67..255333c 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/ImmediateHealthService.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/ImmediateHealthService.kt @@ -1,7 +1,7 @@ package org.radarbase.jersey.service -import org.glassfish.hk2.api.IterableProvider import jakarta.ws.rs.core.Context +import org.glassfish.hk2.api.IterableProvider class ImmediateHealthService( @Context healthMetrics: IterableProvider diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/managementportal/MPClientFactory.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/managementportal/MPClientFactory.kt index f2d2ac8..74dd2e2 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/managementportal/MPClientFactory.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/managementportal/MPClientFactory.kt @@ -1,11 +1,11 @@ package org.radarbase.jersey.service.managementportal import com.fasterxml.jackson.databind.ObjectMapper +import jakarta.ws.rs.core.Context import okhttp3.OkHttpClient import org.radarbase.jersey.auth.AuthConfig import org.radarbase.management.client.MPClient import java.util.function.Supplier -import jakarta.ws.rs.core.Context class MPClientFactory( @Context private val authConfig: AuthConfig, diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/managementportal/ProjectServiceWrapper.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/managementportal/ProjectServiceWrapper.kt index 1077587..5f857db 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/managementportal/ProjectServiceWrapper.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/service/managementportal/ProjectServiceWrapper.kt @@ -16,10 +16,10 @@ package org.radarbase.jersey.service.managementportal -import org.radarbase.jersey.exception.HttpNotFoundException -import org.radarbase.jersey.service.ProjectService import jakarta.inject.Provider import jakarta.ws.rs.core.Context +import org.radarbase.jersey.exception.HttpNotFoundException +import org.radarbase.jersey.service.ProjectService class ProjectServiceWrapper( @Context private val radarProjectService: Provider diff --git a/radar-jersey/src/test/kotlin/org/radarbase/jersey/auth/AuthConfigTest.kt b/radar-jersey/src/test/kotlin/org/radarbase/jersey/auth/AuthConfigTest.kt index b0d8d57..0171d2e 100644 --- a/radar-jersey/src/test/kotlin/org/radarbase/jersey/auth/AuthConfigTest.kt +++ b/radar-jersey/src/test/kotlin/org/radarbase/jersey/auth/AuthConfigTest.kt @@ -5,7 +5,6 @@ import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.not import org.junit.jupiter.api.Test import java.util.* -import kotlin.jvm.Throws internal class AuthConfigTest { @Test diff --git a/radar-jersey/src/test/kotlin/org/radarbase/jersey/config/ConfigLoaderTest.kt b/radar-jersey/src/test/kotlin/org/radarbase/jersey/config/ConfigLoaderTest.kt index 9b433fb..fb73784 100644 --- a/radar-jersey/src/test/kotlin/org/radarbase/jersey/config/ConfigLoaderTest.kt +++ b/radar-jersey/src/test/kotlin/org/radarbase/jersey/config/ConfigLoaderTest.kt @@ -1,9 +1,8 @@ package org.radarbase.jersey.config +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import org.junit.jupiter.api.Assertions.* - internal class ConfigLoaderTest { @Test fun loadConfig() { diff --git a/radar-jersey/src/test/kotlin/org/radarbase/jersey/enhancer/MapperResourceEnhancerTest.kt b/radar-jersey/src/test/kotlin/org/radarbase/jersey/enhancer/MapperResourceEnhancerTest.kt index ad30709..02fd35b 100644 --- a/radar-jersey/src/test/kotlin/org/radarbase/jersey/enhancer/MapperResourceEnhancerTest.kt +++ b/radar-jersey/src/test/kotlin/org/radarbase/jersey/enhancer/MapperResourceEnhancerTest.kt @@ -6,8 +6,9 @@ import org.glassfish.jersey.server.ResourceConfig import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.jupiter.api.Test -import org.mockito.kotlin.* - +import org.mockito.kotlin.check +import org.mockito.kotlin.mock +import org.mockito.kotlin.verify import java.time.Instant internal class MapperResourceEnhancerTest { diff --git a/radar-jersey/src/test/kotlin/org/radarbase/jersey/mock/resource/MockResource.kt b/radar-jersey/src/test/kotlin/org/radarbase/jersey/mock/resource/MockResource.kt index 102160f..a22f070 100644 --- a/radar-jersey/src/test/kotlin/org/radarbase/jersey/mock/resource/MockResource.kt +++ b/radar-jersey/src/test/kotlin/org/radarbase/jersey/mock/resource/MockResource.kt @@ -12,14 +12,14 @@ package org.radarbase.jersey.mock.resource import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses -import org.radarbase.auth.authorization.Permission -import org.radarbase.jersey.auth.Auth -import org.radarbase.jersey.auth.Authenticated -import org.radarbase.jersey.auth.NeedsPermission import jakarta.annotation.Resource import jakarta.ws.rs.* import jakarta.ws.rs.core.Context import jakarta.ws.rs.core.MediaType +import org.radarbase.auth.authorization.Permission +import org.radarbase.jersey.auth.Auth +import org.radarbase.jersey.auth.Authenticated +import org.radarbase.jersey.auth.NeedsPermission import org.radarbase.jersey.exception.HttpBadRequestException import java.io.IOException import java.time.Instant From 9369d155ddee3bce51227aa3c063a33c63e1d1e9 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Wed, 13 Jul 2022 10:27:30 +0200 Subject: [PATCH 7/8] Bump version --- README.md | 2 +- build.gradle.kts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ff0ebb1..c135b79 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ repositories { } dependencies { - api("org.radarbase:radar-jersey:0.8.3") + api("org.radarbase:radar-jersey:0.9.0") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 574169b..bb78cec 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ plugins { allprojects { group = "org.radarbase" - version = "0.8.4-SNAPSHOT" + version = "0.9.0" } subprojects { @@ -43,12 +43,16 @@ subprojects { configurations["dokkaHtmlPlugin"]("org.jetbrains.dokka:kotlin-as-java-plugin:$dokkaVersion") val jacksonVersion: String by project - configurations["dokkaPlugin"](platform("com.fasterxml.jackson:jackson-bom:$jacksonVersion")) - configurations["dokkaRuntime"](platform("com.fasterxml.jackson:jackson-bom:$jacksonVersion")) - val jsoupVersion: String by project - configurations["dokkaPlugin"]("org.jsoup:jsoup:$jsoupVersion") - configurations["dokkaRuntime"]("org.jsoup:jsoup:$jsoupVersion") + val kotlinVersion: String by project + + sequenceOf("dokkaPlugin", "dokkaRuntime") + .map { configurations[it] } + .forEach { conf -> + conf(platform("com.fasterxml.jackson:jackson-bom:$jacksonVersion")) + conf("org.jsoup:jsoup:$jsoupVersion") + conf(platform("org.jetbrains.kotlin:kotlin-bom:$kotlinVersion")) + } val log4j2Version: String by project val testRuntimeOnly by configurations From 7cc4370eaaf6fca6c16aa11a6ce24c6e04e4e5a7 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Wed, 13 Jul 2022 10:48:36 +0200 Subject: [PATCH 8/8] Still allow health checks to be seen in debug mode --- .../jersey/filter/ResponseLoggerFilter.kt | 28 +++++++++++++------ .../org/radarbase/jersey/auth/OAuthHelper.kt | 1 + 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt index c6ae174..cdff2ca 100644 --- a/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt +++ b/radar-jersey/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt @@ -14,7 +14,9 @@ import jakarta.ws.rs.container.ContainerRequestContext import jakarta.ws.rs.container.ContainerResponseContext import jakarta.ws.rs.container.ContainerResponseFilter import jakarta.ws.rs.ext.Provider +import org.slf4j.Logger import org.slf4j.LoggerFactory +import org.slf4j.event.Level @Provider @Singleton @@ -23,20 +25,21 @@ class ResponseLoggerFilter : ContainerResponseFilter { requestContext: ContainerRequestContext?, responseContext: ContainerResponseContext?, ) { - val path = requestContext?.uriInfo?.path - val status = responseContext?.status + val path = requestContext?.uriInfo?.path ?: return + val status = responseContext?.status ?: return + val logLevel = if (path.isHealthEndpoint && status == 200) Level.DEBUG else Level.INFO + when { - path == null -> return - status == null -> return - path.isHealthEndpoint && status == 200 -> return - requestContext.mediaType == null -> logger.info( + requestContext.mediaType == null -> logger.log( + logLevel, "[{}] {} {} -- <{}> ", status, requestContext.method, path, responseContext.mediaType, ) - requestContext.length < 0 -> logger.info( + requestContext.length < 0 -> logger.log( + logLevel, "[{}] {} {} <{}> -- <{}> ", status, requestContext.method, @@ -44,7 +47,8 @@ class ResponseLoggerFilter : ContainerResponseFilter { requestContext.mediaType, responseContext.mediaType, ) - else -> logger.info( + else -> logger.log( + logLevel, "[{}] {} {} <{}: {}> -- <{}> ", status, requestContext.method, @@ -61,5 +65,13 @@ class ResponseLoggerFilter : ContainerResponseFilter { /** Whether given path matches a health endpoint. */ private inline val String.isHealthEndpoint: Boolean get() = this == "health" || endsWith("/health") + private fun Logger.log(level: Level, message: String, vararg arguments: Any?) = + when (level) { + Level.ERROR -> error(message, *arguments) + Level.WARN -> warn(message, *arguments) + Level.INFO -> info(message, *arguments) + Level.DEBUG -> debug(message, *arguments) + Level.TRACE -> trace(message, *arguments) + } } } diff --git a/radar-jersey/src/test/kotlin/org/radarbase/jersey/auth/OAuthHelper.kt b/radar-jersey/src/test/kotlin/org/radarbase/jersey/auth/OAuthHelper.kt index c0e778c..813a433 100644 --- a/radar-jersey/src/test/kotlin/org/radarbase/jersey/auth/OAuthHelper.kt +++ b/radar-jersey/src/test/kotlin/org/radarbase/jersey/auth/OAuthHelper.kt @@ -43,6 +43,7 @@ class OAuthHelper { override fun getResourceName(): String = ISS + @Deprecated("Use public key endpoints instead.", replaceWith = ReplaceWith("getPublicKeyEndpoints()")) override fun getPublicKeys(): List = emptyList() } @Suppress("DEPRECATION")