From f35c7113a2d36fc6238b68c2c59beef82a2a2510 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Mon, 14 Oct 2019 10:33:12 +0200 Subject: [PATCH 1/5] Bump dev version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f888613..494446a 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { description = 'Library for Jersey authorization, exception handling and configuration with the RADAR platform' group = 'org.radarbase' -version = '0.2.1' +version = '0.2.2-SNAPSHOT' ext { githubRepoName = 'RADAR-base/radar-jersey' From d93bac0b7317a2f3699f1ed2cc14211a33325d87 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Mon, 14 Oct 2019 10:59:25 +0200 Subject: [PATCH 2/5] Have enhancers work on this object. --- .../jersey/config/EcdsaResourceEnhancer.kt | 4 ++-- .../jersey/config/EnhancerFactory.kt | 4 ---- .../config/HttpExceptionResourceEnhancer.kt | 19 +++++------------ .../jersey/config/JerseyResourceEnhancer.kt | 10 +++++++-- .../ManagementPortalResourceEnhancer.kt | 16 +++++++------- .../config/RadarJerseyResourceEnhancer.kt | 21 ++++++++----------- 6 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt index 2419762..987201d 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt @@ -22,8 +22,8 @@ import javax.inject.Singleton * and jwtKeystoreAlias. If jwtIssuer is set, the issuer of the JWT will also be validated. */ class EcdsaResourceEnhancer : JerseyResourceEnhancer { - override fun enhanceBinder(binder: AbstractBinder) { - binder.bind(EcdsaJwtTokenValidator::class.java) + override val enhanceBinder: AbstractBinder.() -> Unit = { + bind(EcdsaJwtTokenValidator::class.java) .to(AuthValidator::class.java) .`in`(Singleton::class.java) } diff --git a/src/main/kotlin/org/radarbase/jersey/config/EnhancerFactory.kt b/src/main/kotlin/org/radarbase/jersey/config/EnhancerFactory.kt index b59bb80..65b4a67 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/EnhancerFactory.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/EnhancerFactory.kt @@ -1,9 +1,5 @@ package org.radarbase.jersey.config -import org.radarbase.jersey.auth.AuthConfig -import org.radarbase.jersey.filter.CorsFilter -import org.radarbase.jersey.filter.ResponseLoggerFilter - /** * Factory to create resource enhancers with. */ diff --git a/src/main/kotlin/org/radarbase/jersey/config/HttpExceptionResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/HttpExceptionResourceEnhancer.kt index 96d9465..9d88458 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/HttpExceptionResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/HttpExceptionResourceEnhancer.kt @@ -2,12 +2,7 @@ package org.radarbase.jersey.config import org.glassfish.jersey.internal.inject.AbstractBinder import org.glassfish.jersey.internal.inject.PerThread -import org.glassfish.jersey.server.ResourceConfig -import org.radarbase.jersey.exception.mapper.DefaultJsonExceptionRenderer -import org.radarbase.jersey.exception.mapper.DefaultTextExceptionRenderer -import org.radarbase.jersey.exception.mapper.HtmlTemplateExceptionRenderer -import org.radarbase.jersey.exception.mapper.ExceptionRenderer -import org.radarbase.jersey.exception.mapper.HttpApplicationExceptionMapper +import org.radarbase.jersey.exception.mapper.* import javax.inject.Singleton /** Add HttpApplicationException handling. This includes a HTML templating solution. */ @@ -15,24 +10,20 @@ class HttpExceptionResourceEnhancer: JerseyResourceEnhancer { override val classes: Array> = arrayOf( HttpApplicationExceptionMapper::class.java) - override fun enhanceBinder(binder: AbstractBinder) { - binder.bind(HtmlTemplateExceptionRenderer::class.java) + override val enhanceBinder: AbstractBinder.() -> Unit = { + bind(HtmlTemplateExceptionRenderer::class.java) .to(ExceptionRenderer::class.java) .named("text/html") .`in`(PerThread::class.java) - binder.bind(DefaultJsonExceptionRenderer::class.java) + bind(DefaultJsonExceptionRenderer::class.java) .to(ExceptionRenderer::class.java) .named("application/json") .`in`(Singleton::class.java) - binder.bind(DefaultTextExceptionRenderer::class.java) + bind(DefaultTextExceptionRenderer::class.java) .to(ExceptionRenderer::class.java) .named("text/plain") .`in`(Singleton::class.java) } - - override fun enhanceResources(resourceConfig: ResourceConfig) { - resourceConfig.registerClasses(HttpApplicationExceptionMapper::class.java) - } } \ No newline at end of file diff --git a/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt index 3c0be7b..3d1dd93 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt @@ -23,14 +23,20 @@ interface JerseyResourceEnhancer { val packages: Array get() = emptyArray() + val enhanceBinder: AbstractBinder.() -> Unit + get() = {} + + val enhanceResources: ResourceConfig.() -> Unit + get() = {} + /** * Enhance the ResourceConfig directly. Use this for classes with Jersey-recognized classes like * {@code @Resource}, {@code @Provider} or {@code ContextResolver}. */ - fun enhanceResources(resourceConfig: ResourceConfig) = Unit + fun enhanceResources(resourceConfig: ResourceConfig) = resourceConfig.enhanceResources() /** * Enhance an AbstractBinder. Use this for app-specific bindings. */ - fun enhanceBinder(binder: AbstractBinder) = Unit + fun enhanceBinder(binder: AbstractBinder) = binder.enhanceBinder() } diff --git a/src/main/kotlin/org/radarbase/jersey/config/ManagementPortalResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/ManagementPortalResourceEnhancer.kt index b82c11c..b368b63 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/ManagementPortalResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/ManagementPortalResourceEnhancer.kt @@ -21,15 +21,13 @@ import javax.inject.Singleton * jwtResourceName to be set in the AuthConfig. */ class ManagementPortalResourceEnhancer : JerseyResourceEnhancer { - override fun enhanceBinder(binder: AbstractBinder) { - binder.apply { - bindFactory(TokenValidatorFactory::class.java) - .to(TokenValidator::class.java) - .`in`(Singleton::class.java) + override val enhanceBinder: AbstractBinder.() -> Unit = { + bindFactory(TokenValidatorFactory::class.java) + .to(TokenValidator::class.java) + .`in`(Singleton::class.java) - bind(ManagementPortalTokenValidator::class.java) - .to(AuthValidator::class.java) - .`in`(Singleton::class.java) - } + bind(ManagementPortalTokenValidator::class.java) + .to(AuthValidator::class.java) + .`in`(Singleton::class.java) } } diff --git a/src/main/kotlin/org/radarbase/jersey/config/RadarJerseyResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/RadarJerseyResourceEnhancer.kt index ceb80c1..a875457 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/RadarJerseyResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/RadarJerseyResourceEnhancer.kt @@ -11,7 +11,6 @@ package org.radarbase.jersey.config import org.glassfish.jersey.internal.inject.AbstractBinder import org.glassfish.jersey.process.internal.RequestScoped -import org.glassfish.jersey.server.ResourceConfig import org.radarbase.jersey.auth.Auth import org.radarbase.jersey.auth.AuthConfig import org.radarbase.jersey.auth.filter.AuthenticationFilter @@ -29,17 +28,15 @@ class RadarJerseyResourceEnhancer( AuthenticationFilter::class.java, AuthorizationFeature::class.java) - override fun enhanceBinder(binder: AbstractBinder) { - binder.apply { - bind(config) - .to(AuthConfig::class.java) + override val enhanceBinder: AbstractBinder.() -> Unit = { + bind(config) + .to(AuthConfig::class.java) - // Bind factories. - bindFactory(AuthFactory::class.java) - .proxy(true) - .proxyForSameScope(false) - .to(Auth::class.java) - .`in`(RequestScoped::class.java) - } + // Bind factories. + bindFactory(AuthFactory::class.java) + .proxy(true) + .proxyForSameScope(false) + .to(Auth::class.java) + .`in`(RequestScoped::class.java) } } From a707ca430a268ed9129ff86367473c0a37e376a8 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Mon, 14 Oct 2019 11:00:19 +0200 Subject: [PATCH 3/5] Clean up imports and update enhancer style --- src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt | 1 - .../org/radarbase/jersey/filter/ResponseLoggerFilter.kt | 8 -------- .../jersey/auth/RadarJerseyResourceEnhancerTest.kt | 3 +-- .../org/radarbase/jersey/mock/MockResourceEnhancer.kt | 6 +++--- .../radarbase/jersey/mock/MockResourceEnhancerFactory.kt | 4 +++- 5 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt b/src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt index 7176190..76c94c0 100644 --- a/src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt +++ b/src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt @@ -12,7 +12,6 @@ package org.radarbase.jersey import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory import org.glassfish.jersey.server.ResourceConfig import org.slf4j.LoggerFactory -import java.lang.IllegalStateException import java.net.URI /** diff --git a/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt b/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt index af1f982..6bbd79b 100644 --- a/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt +++ b/src/main/kotlin/org/radarbase/jersey/filter/ResponseLoggerFilter.kt @@ -10,21 +10,13 @@ package org.radarbase.jersey.filter import org.slf4j.LoggerFactory -import java.time.Instant import java.time.LocalDateTime import java.time.ZoneOffset -import java.time.chrono.IsoChronology import java.time.format.DateTimeFormatter -import java.time.format.DateTimeFormatter.ISO_LOCAL_DATE -import java.time.format.DateTimeFormatterBuilder -import java.time.format.ResolverStyle -import java.time.temporal.ChronoField import javax.inject.Singleton import javax.ws.rs.container.ContainerRequestContext import javax.ws.rs.container.ContainerResponseContext import javax.ws.rs.container.ContainerResponseFilter -import javax.ws.rs.core.Context -import javax.ws.rs.core.UriInfo import javax.ws.rs.ext.Provider @Provider diff --git a/src/test/kotlin/org/radarbase/jersey/auth/RadarJerseyResourceEnhancerTest.kt b/src/test/kotlin/org/radarbase/jersey/auth/RadarJerseyResourceEnhancerTest.kt index 0a1f761..56655e0 100644 --- a/src/test/kotlin/org/radarbase/jersey/auth/RadarJerseyResourceEnhancerTest.kt +++ b/src/test/kotlin/org/radarbase/jersey/auth/RadarJerseyResourceEnhancerTest.kt @@ -20,8 +20,7 @@ import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.radarbase.jersey.auth.OAuthHelper.Companion.bearerHeader -import org.radarbase.jersey.config.* -import org.radarbase.jersey.mock.MockResourceEnhancer +import org.radarbase.jersey.config.ConfigLoader import org.radarbase.jersey.mock.MockResourceEnhancerFactory import java.net.URI diff --git a/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancer.kt b/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancer.kt index 5917992..562183a 100644 --- a/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancer.kt +++ b/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancer.kt @@ -15,12 +15,12 @@ class MockResourceEnhancer : JerseyResourceEnhancer { override val packages: Array = arrayOf( "org.radarbase.jersey.mock.resource") - override fun enhanceBinder(binder: AbstractBinder) { - binder.bind(MockProjectService(listOf("a", "b"))) + override val enhanceBinder: AbstractBinder.() -> Unit = { + bind(MockProjectService(listOf("a", "b"))) .to(ProjectService::class.java) .`in`(Singleton::class.java) - binder.bindFactory { RadarJerseyResourceEnhancerTest.oauthHelper.tokenValidator } + bindFactory { RadarJerseyResourceEnhancerTest.oauthHelper.tokenValidator } .to(TokenValidator::class.java) } } \ No newline at end of file diff --git a/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancerFactory.kt b/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancerFactory.kt index e7fbe30..ff6f201 100644 --- a/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancerFactory.kt +++ b/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancerFactory.kt @@ -1,7 +1,9 @@ package org.radarbase.jersey.mock import org.radarbase.jersey.auth.AuthConfig -import org.radarbase.jersey.config.* +import org.radarbase.jersey.config.ConfigLoader +import org.radarbase.jersey.config.EnhancerFactory +import org.radarbase.jersey.config.JerseyResourceEnhancer class MockResourceEnhancerFactory(private val config: AuthConfig) : EnhancerFactory { override fun createEnhancers(): List = listOf( From abab7763f5ddf8a2e481eb0a6b39918987181967 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Wed, 16 Oct 2019 14:07:12 +0100 Subject: [PATCH 4/5] Use shorter enhance syntax --- README.md | 8 ++++---- .../radarbase/jersey/config/EcdsaResourceEnhancer.kt | 2 +- .../jersey/config/HttpExceptionResourceEnhancer.kt | 2 +- .../radarbase/jersey/config/JerseyResourceEnhancer.kt | 10 ++++------ .../jersey/config/ManagementPortalResourceEnhancer.kt | 2 +- .../jersey/config/RadarJerseyResourceEnhancer.kt | 2 +- .../org/radarbase/jersey/mock/MockResourceEnhancer.kt | 2 +- 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4b8b872..c614962 100644 --- a/README.md +++ b/README.md @@ -68,15 +68,15 @@ class MyEnhancerFactory(private val config: MyConfigClass): EnhancerFactory { ConfigLoader.Filters.logResponse, ConfigLoader.Filters.cors) - override fun enhanceBinder(binder: AbstractBinder) { - binder.bind(config) + override fun AbstractBinder.enhance() { + bind(config) .to(MyConfigClass::class.java) - binder.bind(MyProjectService::class.java) + bind(MyProjectService::class.java) .to(ProjectService::class.java) .`in`(Singleton::class.java) - binder.bind(MyProjectService::class.java) + bind(MyProjectService::class.java) .to(MyProjectService::class.java) .`in`(Singleton::class.java) } diff --git a/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt index 987201d..26128b5 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt @@ -22,7 +22,7 @@ import javax.inject.Singleton * and jwtKeystoreAlias. If jwtIssuer is set, the issuer of the JWT will also be validated. */ class EcdsaResourceEnhancer : JerseyResourceEnhancer { - override val enhanceBinder: AbstractBinder.() -> Unit = { + override fun AbstractBinder.enhance() { bind(EcdsaJwtTokenValidator::class.java) .to(AuthValidator::class.java) .`in`(Singleton::class.java) diff --git a/src/main/kotlin/org/radarbase/jersey/config/HttpExceptionResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/HttpExceptionResourceEnhancer.kt index 9d88458..7973e35 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/HttpExceptionResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/HttpExceptionResourceEnhancer.kt @@ -10,7 +10,7 @@ class HttpExceptionResourceEnhancer: JerseyResourceEnhancer { override val classes: Array> = arrayOf( HttpApplicationExceptionMapper::class.java) - override val enhanceBinder: AbstractBinder.() -> Unit = { + override fun AbstractBinder.enhance() { bind(HtmlTemplateExceptionRenderer::class.java) .to(ExceptionRenderer::class.java) .named("text/html") diff --git a/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt index 3d1dd93..5d6ac18 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt @@ -23,20 +23,18 @@ interface JerseyResourceEnhancer { val packages: Array get() = emptyArray() - val enhanceBinder: AbstractBinder.() -> Unit - get() = {} + fun AbstractBinder.enhance() = Unit - val enhanceResources: ResourceConfig.() -> Unit - get() = {} + fun ResourceConfig.enhance() = Unit /** * Enhance the ResourceConfig directly. Use this for classes with Jersey-recognized classes like * {@code @Resource}, {@code @Provider} or {@code ContextResolver}. */ - fun enhanceResources(resourceConfig: ResourceConfig) = resourceConfig.enhanceResources() + fun enhanceResources(resourceConfig: ResourceConfig) = resourceConfig.enhance() /** * Enhance an AbstractBinder. Use this for app-specific bindings. */ - fun enhanceBinder(binder: AbstractBinder) = binder.enhanceBinder() + fun enhanceBinder(binder: AbstractBinder) = binder.enhance() } diff --git a/src/main/kotlin/org/radarbase/jersey/config/ManagementPortalResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/ManagementPortalResourceEnhancer.kt index b368b63..a840b11 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/ManagementPortalResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/ManagementPortalResourceEnhancer.kt @@ -21,7 +21,7 @@ import javax.inject.Singleton * jwtResourceName to be set in the AuthConfig. */ class ManagementPortalResourceEnhancer : JerseyResourceEnhancer { - override val enhanceBinder: AbstractBinder.() -> Unit = { + override fun AbstractBinder.enhance() { bindFactory(TokenValidatorFactory::class.java) .to(TokenValidator::class.java) .`in`(Singleton::class.java) diff --git a/src/main/kotlin/org/radarbase/jersey/config/RadarJerseyResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/RadarJerseyResourceEnhancer.kt index a875457..379d1ae 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/RadarJerseyResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/RadarJerseyResourceEnhancer.kt @@ -28,7 +28,7 @@ class RadarJerseyResourceEnhancer( AuthenticationFilter::class.java, AuthorizationFeature::class.java) - override val enhanceBinder: AbstractBinder.() -> Unit = { + override fun AbstractBinder.enhance() { bind(config) .to(AuthConfig::class.java) diff --git a/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancer.kt b/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancer.kt index 562183a..375f826 100644 --- a/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancer.kt +++ b/src/test/kotlin/org/radarbase/jersey/mock/MockResourceEnhancer.kt @@ -15,7 +15,7 @@ class MockResourceEnhancer : JerseyResourceEnhancer { override val packages: Array = arrayOf( "org.radarbase.jersey.mock.resource") - override val enhanceBinder: AbstractBinder.() -> Unit = { + override fun AbstractBinder.enhance() { bind(MockProjectService(listOf("a", "b"))) .to(ProjectService::class.java) .`in`(Singleton::class.java) From 533f3547105528673b39cee3001e0346a9978b0b Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Wed, 16 Oct 2019 13:54:13 +0100 Subject: [PATCH 5/5] Bump version --- README.md | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c614962..963261e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ repositories { } dependencies { - api("org.radarbase:radar-jersey:0.2.1") + api("org.radarbase:radar-jersey:0.2.2") } ``` diff --git a/build.gradle b/build.gradle index 494446a..d9f149b 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { description = 'Library for Jersey authorization, exception handling and configuration with the RADAR platform' group = 'org.radarbase' -version = '0.2.2-SNAPSHOT' +version = '0.2.2' ext { githubRepoName = 'RADAR-base/radar-jersey'