Skip to content

Commit

Permalink
Merge pull request #3 from RADAR-base/release-0.2.2
Browse files Browse the repository at this point in the history
Release 0.2.2
  • Loading branch information
blootsvoets authored Oct 16, 2019
2 parents ea0495e + 533f354 commit 8450041
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 64 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}
dependencies {
api("org.radarbase:radar-jersey:0.2.1")
api("org.radarbase:radar-jersey:0.2.2")
}
```

Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/org/radarbase/jersey/GrizzlyServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,28 @@ 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. */
class HttpExceptionResourceEnhancer: JerseyResourceEnhancer {
override val classes: Array<Class<*>> = 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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ interface JerseyResourceEnhancer {
val packages: Array<String>
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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class MockResourceEnhancer : JerseyResourceEnhancer {
override val packages: Array<String> = 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)
}
}
Original file line number Diff line number Diff line change
@@ -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<JerseyResourceEnhancer> = listOf(
Expand Down

0 comments on commit 8450041

Please sign in to comment.