Skip to content

Commit

Permalink
Merge pull request #49 from RADAR-base/release-0.8.0
Browse files Browse the repository at this point in the history
Release 0.8.0
  • Loading branch information
blootsvoets authored Dec 2, 2021
2 parents 92d982c + f475161 commit 115ce98
Show file tree
Hide file tree
Showing 35 changed files with 456 additions and 259 deletions.
44 changes: 21 additions & 23 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.7.0")
api("org.radarbase:radar-jersey:0.8.0")
}
```

Expand All @@ -21,14 +21,14 @@ Any path or resource that should be authenticated against the ManagementPortal,
@Path("/projects")
@Authenticated
class Users(
@Context projectService: MyProjectService
@Context projectService: MyProjectService
) {
@GET
@NeedsPermission(PROJECT, READ)
fun getProjects(@Context auth: Auth): List<Project> {
return projectService.read()
.filter { auth.token.hasPermissionOnProject(PROJECT_READ, it.name) }
}
}

@POST
@Path("/{projectId}")
Expand All @@ -53,40 +53,38 @@ class MyEnhancerFactory(private val config: MyConfigClass): EnhancerFactory {
val authConfig = AuthConfig(
managementPortal = MPConfig(
url = "http://...",
),
),
jwtResourceName = "res_MyResource",
)
)
return listOf(
// My own resource configuration
MyResourceEnhancer(),
// RADAR OAuth2 enhancement
ConfigLoader.Enhancers.radar(),
Enhancers.radar(authConfig),
// Use ManagementPortal OAuth implementation
ConfigLoader.Enhancers.managementPortal,
// HttpApplicationException handling
ConfigLoader.Enhancers.httpException,
// General error handling (WebApplicationException and any other Exception)
ConfigLoader.Enhancers.generalException,
Enhancers.managementPortal(authConfig),
// Error handling
Enhancers.exception,
)
}

class MyResourceEnhancer: JerseyResourceEnhancer {
override val classes: Array<Class<*>> = arrayOf(
ConfigLoader.Filters.logResponse,
ConfigLoader.Filters.cors,
ConfigLoader.Filters.cache,
)
Filters.logResponse,
Filters.cors,
Filters.cache,
)

overide val packages = arrayOf(
"com.example.app.resources",
)
override val packages = arrayOf(
"com.example.app.resources",
)

override fun AbstractBinder.enhance() {
bind(config)
.to(MyConfigClass::class.java)
bind(MyService::class.java)
.to(MyService::class.java)
.`in`(Singleton::class.java)
bind(MyService::class.java)
.to(MyService::class.java)
.`in`(Singleton::class.java)
}
}
}
Expand Down Expand Up @@ -168,8 +166,8 @@ The implementation may optionally return health status `UP` or `DOWN` and may in

### Caching

Client side caching is enabled by the `ConfigLoader.Filters.cache` filter. When this is enabled, resource methods and classes can be annotated with a `org.radarbase.jersey.cache.Cache` or `NoCache` annotation. The fields of this annotation correspond to the [`Cache-Control` headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control).
Client side caching is enabled by the `Filters.cache` filter. When this is enabled, resource methods and classes can be annotated with a `org.radarbase.jersey.cache.Cache` or `NoCache` annotation. The fields of this annotation correspond to the [`Cache-Control` headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control).

### OpenAPI / Swagger

To automatically create a OpenAPI / Swagger endpoint for your API, add the `ConfigLoader.Enhancers.openapi` resource enhancer. Provide it with a general description of your API as specified by an `OpenAPI` object.
To automatically create a OpenAPI / Swagger endpoint for your API, add the `Enhancers.openapi` resource enhancer. Provide it with a general description of your API as specified by an `OpenAPI` object.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {

allprojects {
group = "org.radarbase"
version = "0.7.0"
version = "0.8.0"
}

subprojects {
Expand Down Expand Up @@ -203,5 +203,5 @@ nexusPublishing {
}

tasks.wrapper {
gradleVersion = "7.2"
gradleVersion = "7.3.1"
}
13 changes: 7 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ org.gradle.jvmargs=-Xmx2000m
org.gradle.vfs.watch=true
kotlin.code.style=official

kotlinVersion=1.5.31
dokkaVersion=1.5.31
kotlinVersion=1.6.0
dokkaVersion=1.6.0

jerseyVersion=3.0.3
grizzlyVersion=3.0.1
okhttpVersion=4.9.2
junitVersion=5.8.1
okhttpVersion=4.9.3
junitVersion=5.8.2
hamcrestVersion=2.2
mockitoKotlinVersion=4.0.0

hk2Version=3.0.2
managementPortalVersion=0.8.0
Expand All @@ -29,6 +30,6 @@ swaggerVersion=2.1.11
mustacheVersion=0.9.10

hibernateVersion=5.6.1.Final
liquibaseVersion=4.5.0
liquibaseVersion=4.6.1
postgresVersion=42.3.1
h2Version=1.4.200
h2Version=2.0.202
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.radarbase.jersey.hibernate.config

import org.glassfish.jersey.internal.inject.AbstractBinder
import org.glassfish.jersey.process.internal.RequestScoped
import org.radarbase.jersey.config.JerseyResourceEnhancer
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer
import org.radarbase.jersey.hibernate.DatabaseHealthMetrics
import org.radarbase.jersey.hibernate.DatabaseInitialization
import org.radarbase.jersey.hibernate.RadarEntityManagerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,42 +77,42 @@ internal class HibernateTest {
override fun contentType() = "application/json".toMediaTypeOrNull()

override fun writeTo(sink: BufferedSink) {
sink.writeUtf8("{\"name\": \"a\"}")
sink.writeUtf8("""{"name": "a"}""")
}
})
.url("http://localhost:9091/projects")
.build()).execute().use { response ->
assertThat(response.isSuccessful, `is`(true))
assertThat(response.body?.string(), equalTo("{\"id\":1000,\"name\":\"a\",\"description\":null}"))
assertThat(response.body?.string(), equalTo("""{"id":1000,"name":"a"}"""))
}

client.newCall(Request.Builder()
.url("http://localhost:9091/projects/1000")
.build()).execute().use { response ->
assertThat(response.isSuccessful, `is`(true))
assertThat(response.body?.string(), equalTo("{\"id\":1000,\"name\":\"a\",\"description\":null}"))
assertThat(response.body?.string(), equalTo("""{"id":1000,"name":"a"}"""))
}


client.newCall(Request.Builder()
.url("http://localhost:9091/projects")
.build()).execute().use { response ->
assertThat(response.isSuccessful, `is`(true))
assertThat(response.body?.string(), equalTo("[{\"id\":1000,\"name\":\"a\",\"description\":null}]"))
assertThat(response.body?.string(), equalTo("""[{"id":1000,"name":"a"}]"""))
}

client.newCall(Request.Builder()
.post(object : RequestBody() {
override fun contentType() = "application/json".toMediaTypeOrNull()

override fun writeTo(sink: BufferedSink) {
sink.writeUtf8("{\"name\": \"a\",\"description\":\"d\"}")
sink.writeUtf8("""{"name": "a","description":"d"}""")
}
})
.url("http://localhost:9091/projects/1000")
.build()).execute().use { response ->
assertThat(response.isSuccessful, `is`(true))
assertThat(response.body?.string(), equalTo("{\"id\":1000,\"name\":\"a\",\"description\":\"d\"}"))
assertThat(response.body?.string(), equalTo("""{"id":1000,"name":"a","description":"d"}"""))
}
client.newCall(Request.Builder()
.delete()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.radarbase.jersey.hibernate.mock

import org.glassfish.jersey.internal.inject.AbstractBinder
import org.radarbase.jersey.config.ConfigLoader
import org.radarbase.jersey.config.JerseyResourceEnhancer
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer
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<Class<*>> = arrayOf(
ConfigLoader.Filters.logResponse)
Filters.logResponse)

override val packages: Array<String> = arrayOf(
"org.radarbase.jersey.hibernate.mock.resource")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package org.radarbase.jersey.hibernate.mock

import org.radarbase.jersey.auth.AuthConfig
import org.radarbase.jersey.config.ConfigLoader
import org.radarbase.jersey.config.EnhancerFactory
import org.radarbase.jersey.config.JerseyResourceEnhancer
import org.radarbase.jersey.enhancer.EnhancerFactory
import org.radarbase.jersey.enhancer.Enhancers
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer
import org.radarbase.jersey.hibernate.config.DatabaseConfig
import org.radarbase.jersey.hibernate.config.HibernateResourceEnhancer

class MockResourceEnhancerFactory(private val config: AuthConfig, private val databaseConfig: DatabaseConfig) : EnhancerFactory {
class MockResourceEnhancerFactory(private val config: AuthConfig, private val databaseConfig: DatabaseConfig) :
EnhancerFactory {
override fun createEnhancers(): List<JerseyResourceEnhancer> = listOf(
MockResourceEnhancer(),
ConfigLoader.Enhancers.radar(config),
HibernateResourceEnhancer(databaseConfig),
ConfigLoader.Enhancers.disabledAuthorization,
ConfigLoader.Enhancers.health,
ConfigLoader.Enhancers.httpException,
ConfigLoader.Enhancers.generalException)
MockResourceEnhancer(),
Enhancers.radar(config),
HibernateResourceEnhancer(databaseConfig),
Enhancers.disabledAuthorization,
Enhancers.health,
Enhancers.exception,
)
}
11 changes: 6 additions & 5 deletions radar-jersey/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ dependencies {
val jerseyVersion: String by project
api("org.glassfish.jersey.inject:jersey-hk2:$jerseyVersion")
api("org.glassfish.jersey.core:jersey-server:$jerseyVersion")
implementation("org.glassfish.jersey.media:jersey-media-json-jackson:$jerseyVersion")

val jacksonVersion: String by project
api("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:$jacksonVersion")

val okhttpVersion: String by project
implementation("com.squareup.okhttp3:okhttp:$okhttpVersion")
Expand All @@ -47,11 +50,6 @@ dependencies {
val swaggerVersion: String by project
implementation("io.swagger.core.v3:swagger-jaxrs2-jakarta:$swaggerVersion")

runtimeOnly("org.glassfish.jersey.media:jersey-media-json-jackson:$jerseyVersion")

implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
runtimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion")
runtimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:$jacksonVersion")

val jakartaXmlBindVersion: String by project
val jakartaJaxbCoreVersion: String by project
Expand All @@ -70,6 +68,9 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
val hamcrestVersion: String by project
testImplementation("org.hamcrest:hamcrest:$hamcrestVersion")

val mockitoKotlinVersion: String by project
testImplementation("org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion")
}

tasks.processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* See the file LICENSE in the root of this repository.
*/

package org.radarbase.jersey.config
package org.radarbase.jersey.auth.disabled

import org.glassfish.jersey.internal.inject.AbstractBinder
import org.radarbase.jersey.auth.AuthValidator
import org.radarbase.jersey.auth.disabled.DisabledAuthValidator
import jakarta.inject.Singleton
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer

/**
* Registration for authorization against a ManagementPortal. It requires managementPortalUrl and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* See the file LICENSE in the root of this repository.
*/

package org.radarbase.jersey.config
package org.radarbase.jersey.auth.jwt

import org.glassfish.jersey.internal.inject.AbstractBinder
import org.radarbase.jersey.auth.AuthValidator
import org.radarbase.jersey.auth.jwt.EcdsaJwtTokenValidator
import jakarta.inject.Singleton
import org.radarbase.jersey.enhancer.JerseyResourceEnhancer

/**
* Registration for authorization against a generic OAuth 2.0 provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
* See the file LICENSE in the root of this repository.
*/

package org.radarbase.jersey.config
package org.radarbase.jersey.auth.managementportal

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.auth.managementportal.ManagementPortalTokenValidator
import org.radarbase.jersey.auth.managementportal.TokenValidatorFactory
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
Expand Down
Loading

0 comments on commit 115ce98

Please sign in to comment.