diff --git a/README.md b/README.md index 4b8b872..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") } ``` @@ -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/build.gradle b/build.gradle index f888613..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.1' +version = '0.2.2' ext { githubRepoName = 'RADAR-base/radar-jersey' 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/config/EcdsaResourceEnhancer.kt b/src/main/kotlin/org/radarbase/jersey/config/EcdsaResourceEnhancer.kt index 2419762..26128b5 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 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/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..7973e35 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 fun AbstractBinder.enhance() { + 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..5d6ac18 100644 --- a/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt +++ b/src/main/kotlin/org/radarbase/jersey/config/JerseyResourceEnhancer.kt @@ -23,14 +23,18 @@ interface JerseyResourceEnhancer { val packages: Array get() = emptyArray() + fun AbstractBinder.enhance() = Unit + + 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) = Unit + fun enhanceResources(resourceConfig: ResourceConfig) = resourceConfig.enhance() /** * Enhance an AbstractBinder. Use this for app-specific bindings. */ - fun enhanceBinder(binder: AbstractBinder) = Unit + 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 b82c11c..a840b11 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 fun AbstractBinder.enhance() { + 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..379d1ae 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 fun AbstractBinder.enhance() { + 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) } } 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..375f826 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 fun AbstractBinder.enhance() { + 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(