From 389bf3f9208a8c2f25a2d9c407fa8a77a203a7e0 Mon Sep 17 00:00:00 2001 From: Anurag Dalia Date: Mon, 16 May 2022 23:12:56 +0530 Subject: [PATCH 1/2] minor --- .gitignore | 3 +- oauth2-server-http4k/pom.xml | 4 +- oauth2-server-integration-base/pom.xml | 8 ++-- .../oauth2/integration/BaseIntegrationTest.kt | 22 ++++++---- oauth2-server-javalin/pom.xml | 2 +- oauth2-server-json/pom.xml | 2 +- oauth2-server-jwt/pom.xml | 2 +- oauth2-server-ktor/pom.xml | 42 +++++++++++++++---- .../ktor/feature/Oauth2ServerFeature.kt | 17 ++++---- .../ktor/feature/config/KtorConfiguration.kt | 2 +- .../ktor/feature/request/KtorCallContext.kt | 41 ++++++++---------- .../ktor/integration/KtorIntegrationTest.kt | 4 +- oauth2-server-sparkjava/pom.xml | 2 +- pom.xml | 10 ++--- 14 files changed, 95 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index 1d9336b..4f1f1c8 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ hs_err_pid* .idea -**.iml \ No newline at end of file +**.iml +target \ No newline at end of file diff --git a/oauth2-server-http4k/pom.xml b/oauth2-server-http4k/pom.xml index ec9e7f0..7f45e32 100644 --- a/oauth2-server-http4k/pom.xml +++ b/oauth2-server-http4k/pom.xml @@ -15,13 +15,13 @@ org.http4k http4k-core - 3.37.1 + 4.25.13.0 provided org.http4k http4k-server-jetty - 3.37.1 + 4.25.13.0 test diff --git a/oauth2-server-integration-base/pom.xml b/oauth2-server-integration-base/pom.xml index 9b2037f..20d7218 100644 --- a/oauth2-server-integration-base/pom.xml +++ b/oauth2-server-integration-base/pom.xml @@ -12,21 +12,21 @@ oauth2-server-integration-base - 2.11.4 - 2.11.4 + 2.13.3 + 2.13.3 com.squareup.okhttp3 okhttp - 3.12.1 + 4.9.3 org.junit.jupiter junit-jupiter-engine - 5.2.0 + 5.8.2 provided diff --git a/oauth2-server-integration-base/src/main/java/nl/myndocs/oauth2/integration/BaseIntegrationTest.kt b/oauth2-server-integration-base/src/main/java/nl/myndocs/oauth2/integration/BaseIntegrationTest.kt index c021ab4..cb4ad36 100644 --- a/oauth2-server-integration-base/src/main/java/nl/myndocs/oauth2/integration/BaseIntegrationTest.kt +++ b/oauth2-server-integration-base/src/main/java/nl/myndocs/oauth2/integration/BaseIntegrationTest.kt @@ -61,7 +61,7 @@ abstract class BaseIntegrationTest { val response = client.newCall(request) .execute() - val values = objectMapper.readMap(response.body()!!.string()) + val values = objectMapper.readMap(response.body!!.string()) assertThat(values["access_token"], `is`(notNullValue())) assertThat(UUID.fromString(values["access_token"] as String), `is`(instanceOf(UUID::class.java))) @@ -98,25 +98,31 @@ abstract class BaseIntegrationTest { response.close() - val body = FormBody.Builder() + val body = response.header("location")!!.asQueryParameters()["code"]?.let { + FormBody.Builder() .add("grant_type", "authorization_code") - .add("code", response.header("location")!!.asQueryParameters()["code"]) + .add("code", it) .add("redirect_uri", "http://localhost:8080/callback") .add("client_id", "testapp") .add("client_secret", "testpass") .build() + } val tokenUrl = buildOauthTokenUri() - val tokenRequest = Request.Builder() + val tokenRequest = body?.let { + Request.Builder() .url(tokenUrl) - .post(body) + .post(it) .build() + } - val tokenResponse = client.newCall(tokenRequest) + val tokenResponse = tokenRequest?.let { + client.newCall(it) .execute() + } - val values = objectMapper.readMap(tokenResponse.body()!!.string()) + val values = objectMapper.readMap(tokenResponse?.body!!.string()) assertThat(values["access_token"], `is`(notNullValue())) assertThat(UUID.fromString(values["access_token"] as String), `is`(instanceOf(UUID::class.java))) @@ -140,7 +146,7 @@ abstract class BaseIntegrationTest { val tokenResponse = client.newCall(tokenRequest) .execute() - val values = objectMapper.readMap(tokenResponse.body()!!.string()) + val values = objectMapper.readMap(tokenResponse.body!!.string()) assertThat(values["access_token"], `is`(notNullValue())) assertThat(UUID.fromString(values["access_token"] as String), `is`(instanceOf(UUID::class.java))) diff --git a/oauth2-server-javalin/pom.xml b/oauth2-server-javalin/pom.xml index b481fb4..99c9b7e 100644 --- a/oauth2-server-javalin/pom.xml +++ b/oauth2-server-javalin/pom.xml @@ -21,7 +21,7 @@ io.javalin javalin - 3.12.0 + 4.5.0 provided diff --git a/oauth2-server-json/pom.xml b/oauth2-server-json/pom.xml index f00a911..5678427 100644 --- a/oauth2-server-json/pom.xml +++ b/oauth2-server-json/pom.xml @@ -15,7 +15,7 @@ com.google.code.gson gson - 2.8.5 + 2.9.0 diff --git a/oauth2-server-jwt/pom.xml b/oauth2-server-jwt/pom.xml index 99b4417..b5ed083 100644 --- a/oauth2-server-jwt/pom.xml +++ b/oauth2-server-jwt/pom.xml @@ -21,7 +21,7 @@ com.auth0 java-jwt - 3.5.0 + 3.19.2 \ No newline at end of file diff --git a/oauth2-server-ktor/pom.xml b/oauth2-server-ktor/pom.xml index 20e3d1e..1c4b5b4 100644 --- a/oauth2-server-ktor/pom.xml +++ b/oauth2-server-ktor/pom.xml @@ -12,13 +12,13 @@ oauth2-server-ktor - 1.1.2 + 2.0.1 io.ktor - ktor-server-core + ktor-server-core-jvm ${ktor.version} provided @@ -37,7 +37,7 @@ io.ktor - ktor-server-netty + ktor-server-netty-jvm ${ktor.version} test @@ -47,20 +47,48 @@ ${project.version} test + + io.ktor + ktor-utils-jvm + ${ktor.version} + provided + + + io.ktor + ktor-server-host-common + ${ktor.version} + provided + ktor - http://dl.bintray.com/kotlin/ktor + https://kotlin.bintray.com/ktor kotlinx - http://dl.bintray.com/kotlin/kotlinx + https://kotlin.bintray.com/kotlinx + + + central + https://repo1.maven.org/maven2/ + + + jitpack + https://jitpack.io + + + ktor-eap + https://maven.pkg.jetbrains.space/public/p/ktor/eap + + + ktor-dev + https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev - jcenter - http://jcenter.bintray.com + central1 + https://repo.maven.apache.org/maven2 \ No newline at end of file diff --git a/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt b/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt index 6cd8960..0a3007c 100644 --- a/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt +++ b/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt @@ -1,24 +1,23 @@ package nl.myndocs.oauth2.ktor.feature -import io.ktor.application.ApplicationCallPipeline -import io.ktor.application.ApplicationFeature -import io.ktor.application.call import io.ktor.util.AttributeKey import nl.myndocs.oauth2.config.Configuration import nl.myndocs.oauth2.config.ConfigurationBuilder import nl.myndocs.oauth2.ktor.feature.config.KtorConfiguration import nl.myndocs.oauth2.ktor.feature.request.KtorCallContext +import io.ktor.server.application.* class Oauth2ServerFeature(configuration: Configuration) { val callRouter = configuration.callRouter - companion object Feature : ApplicationFeature { + companion object Feature : BaseApplicationPlugin { override val key = AttributeKey("Oauth2ServerFeature") override fun install(pipeline: ApplicationCallPipeline, configure: KtorConfiguration.() -> Unit): Oauth2ServerFeature { val ktorConfiguration = KtorConfiguration() configure(ktorConfiguration) - val configuration = ConfigurationBuilder.build(configure as ConfigurationBuilder.Configuration.() -> Unit, ktorConfiguration) + val configuration = + ConfigurationBuilder.build(configure as ConfigurationBuilder.Configuration.() -> Unit, ktorConfiguration) val feature = Oauth2ServerFeature(configuration) @@ -31,10 +30,10 @@ class Oauth2ServerFeature(configuration: Configuration) { } if ( - arrayOf( - configuration.callRouter.tokenEndpoint, - configuration.callRouter.tokenInfoEndpoint - ).contains(ktorCallContext.path) + arrayOf( + configuration.callRouter.tokenEndpoint, + configuration.callRouter.tokenInfoEndpoint + ).contains(ktorCallContext.path) ) { feature.callRouter.route(ktorCallContext) } diff --git a/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/config/KtorConfiguration.kt b/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/config/KtorConfiguration.kt index 7914b15..33955d4 100644 --- a/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/config/KtorConfiguration.kt +++ b/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/config/KtorConfiguration.kt @@ -1,6 +1,6 @@ package nl.myndocs.oauth2.ktor.feature.config -import io.ktor.application.* +import io.ktor.server.application.* import nl.myndocs.oauth2.config.ConfigurationBuilder import nl.myndocs.oauth2.ktor.feature.request.KtorCallContext import nl.myndocs.oauth2.request.auth.CallContextBasicAuthenticator diff --git a/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/request/KtorCallContext.kt b/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/request/KtorCallContext.kt index 6bfcf5e..c89ec1b 100644 --- a/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/request/KtorCallContext.kt +++ b/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/request/KtorCallContext.kt @@ -1,14 +1,9 @@ package nl.myndocs.oauth2.ktor.feature.request -import io.ktor.application.ApplicationCall -import io.ktor.http.HttpStatusCode -import io.ktor.request.header -import io.ktor.request.httpMethod -import io.ktor.request.path -import io.ktor.request.receiveParameters -import io.ktor.response.header -import io.ktor.response.respondRedirect -import io.ktor.response.respondText +import io.ktor.http.* +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.response.* import io.ktor.util.toMap import kotlinx.coroutines.runBlocking import nl.myndocs.oauth2.authenticator.Credentials @@ -19,17 +14,17 @@ class KtorCallContext(val applicationCall: ApplicationCall) : CallContext { override val path: String = applicationCall.request.path() override val method: String = applicationCall.request.httpMethod.value override val headers: Map = applicationCall.request - .headers - .toMap() - .mapValues { applicationCall.request.header(it.key) } - .filterValues { it != null } - .mapValues { it.value!! } + .headers + .toMap() + .mapValues { applicationCall.request.header(it.key) } + .filterValues { it != null } + .mapValues { it.value!! } override val queryParameters: Map = applicationCall.request - .queryParameters - .toMap() - .filterValues { it.isNotEmpty() } - .mapValues { it.value.first() } + .queryParameters + .toMap() + .filterValues { it.isNotEmpty() } + .mapValues { it.value.first() } private var _formParameters: Map? = null override val formParameters: Map @@ -39,9 +34,9 @@ class KtorCallContext(val applicationCall: ApplicationCall) : CallContext { if (_formParameters == null) { _formParameters = runBlocking { applicationCall.receiveParameters() - .toMap() - .filterValues { it.isNotEmpty() } - .mapValues { it.value.first() } + .toMap() + .filterValues { it.isNotEmpty() } + .mapValues { it.value.first() } } } @@ -59,8 +54,8 @@ class KtorCallContext(val applicationCall: ApplicationCall) : CallContext { override fun respondJson(content: Any) { runBlocking { applicationCall.respondText( - JsonMapper.toJson(content), - io.ktor.http.ContentType.Application.Json + JsonMapper.toJson(content), + io.ktor.http.ContentType.Application.Json ) } } diff --git a/oauth2-server-ktor/src/test/java/nl/myndocs/oauth2/ktor/integration/KtorIntegrationTest.kt b/oauth2-server-ktor/src/test/java/nl/myndocs/oauth2/ktor/integration/KtorIntegrationTest.kt index 834d9b2..d3ced8d 100644 --- a/oauth2-server-ktor/src/test/java/nl/myndocs/oauth2/ktor/integration/KtorIntegrationTest.kt +++ b/oauth2-server-ktor/src/test/java/nl/myndocs/oauth2/ktor/integration/KtorIntegrationTest.kt @@ -1,6 +1,6 @@ package nl.myndocs.oauth2.ktor.integration -import io.ktor.application.install +import io.ktor.server.application.install import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import io.ktor.server.netty.NettyApplicationEngine @@ -37,7 +37,7 @@ class KtorIntegrationTest : BaseIntegrationTest() { @AfterEach fun after() { - server!!.stop(0, 10, TimeUnit.SECONDS) + server!!.stop(0, 10000) } } \ No newline at end of file diff --git a/oauth2-server-sparkjava/pom.xml b/oauth2-server-sparkjava/pom.xml index 1398f55..f0481a6 100644 --- a/oauth2-server-sparkjava/pom.xml +++ b/oauth2-server-sparkjava/pom.xml @@ -15,7 +15,7 @@ com.sparkjava spark-core - 2.8.0 + 2.9.3 provided diff --git a/pom.xml b/pom.xml index 0167d32..3ef9cb9 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ 0.7.1-SNAPSHOT - 1.3.31 + 1.6.21 1.8 1.8 @@ -47,25 +47,25 @@ org.junit.jupiter junit-jupiter-engine - 5.2.0 + 5.8.2 test io.mockk mockk - 1.9.3 + 1.12.3 test org.hamcrest hamcrest-library - 1.3 + 2.2 test org.slf4j slf4j-simple - 1.7.25 + 1.7.36 test From dd5098212e9e202cbebe191f8b27535031a58a9c Mon Sep 17 00:00:00 2001 From: Anurag Dalia Date: Wed, 18 May 2022 16:49:01 +0530 Subject: [PATCH 2/2] minor --- oauth2-server-client-inmemory/pom.xml | 2 +- oauth2-server-core/pom.xml | 2 +- oauth2-server-hexagon/pom.xml | 2 +- oauth2-server-http4k/pom.xml | 2 +- oauth2-server-identity-inmemory/pom.xml | 2 +- oauth2-server-integration-base/pom.xml | 2 +- oauth2-server-javalin/pom.xml | 2 +- oauth2-server-json/pom.xml | 2 +- oauth2-server-jwt/pom.xml | 2 +- oauth2-server-ktor/pom.xml | 4 ++-- .../myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt | 9 ++++----- oauth2-server-sparkjava/pom.xml | 2 +- oauth2-server-token-store-inmemory/pom.xml | 2 +- pom.xml | 2 +- 14 files changed, 18 insertions(+), 19 deletions(-) diff --git a/oauth2-server-client-inmemory/pom.xml b/oauth2-server-client-inmemory/pom.xml index 33802b9..5e81308 100644 --- a/oauth2-server-client-inmemory/pom.xml +++ b/oauth2-server-client-inmemory/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-core/pom.xml b/oauth2-server-core/pom.xml index 707d51c..a95e628 100644 --- a/oauth2-server-core/pom.xml +++ b/oauth2-server-core/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-hexagon/pom.xml b/oauth2-server-hexagon/pom.xml index afb4654..57f5ba2 100644 --- a/oauth2-server-hexagon/pom.xml +++ b/oauth2-server-hexagon/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-http4k/pom.xml b/oauth2-server-http4k/pom.xml index 7f45e32..58127a7 100644 --- a/oauth2-server-http4k/pom.xml +++ b/oauth2-server-http4k/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-identity-inmemory/pom.xml b/oauth2-server-identity-inmemory/pom.xml index 95bc252..8e9be0c 100644 --- a/oauth2-server-identity-inmemory/pom.xml +++ b/oauth2-server-identity-inmemory/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-integration-base/pom.xml b/oauth2-server-integration-base/pom.xml index 20d7218..8a6e5b8 100644 --- a/oauth2-server-integration-base/pom.xml +++ b/oauth2-server-integration-base/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-javalin/pom.xml b/oauth2-server-javalin/pom.xml index 99c9b7e..5e6ebf2 100644 --- a/oauth2-server-javalin/pom.xml +++ b/oauth2-server-javalin/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-json/pom.xml b/oauth2-server-json/pom.xml index 5678427..4a69956 100644 --- a/oauth2-server-json/pom.xml +++ b/oauth2-server-json/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-jwt/pom.xml b/oauth2-server-jwt/pom.xml index b5ed083..37a99e2 100644 --- a/oauth2-server-jwt/pom.xml +++ b/oauth2-server-jwt/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-ktor/pom.xml b/oauth2-server-ktor/pom.xml index 1c4b5b4..f652ddf 100644 --- a/oauth2-server-ktor/pom.xml +++ b/oauth2-server-ktor/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 @@ -55,7 +55,7 @@ io.ktor - ktor-server-host-common + ktor-server-host-common-jvm ${ktor.version} provided diff --git a/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt b/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt index 0a3007c..24e44d6 100644 --- a/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt +++ b/oauth2-server-ktor/src/main/java/nl/myndocs/oauth2/ktor/feature/Oauth2ServerFeature.kt @@ -7,22 +7,21 @@ import nl.myndocs.oauth2.ktor.feature.config.KtorConfiguration import nl.myndocs.oauth2.ktor.feature.request.KtorCallContext import io.ktor.server.application.* -class Oauth2ServerFeature(configuration: Configuration) { +public class Oauth2ServerFeature(configuration: Configuration) { val callRouter = configuration.callRouter - companion object Feature : BaseApplicationPlugin { + public companion object : BaseApplicationPlugin { override val key = AttributeKey("Oauth2ServerFeature") - override fun install(pipeline: ApplicationCallPipeline, configure: KtorConfiguration.() -> Unit): Oauth2ServerFeature { + override fun install(pipeline: Application, configure: KtorConfiguration.() -> Unit): Oauth2ServerFeature { val ktorConfiguration = KtorConfiguration() configure(ktorConfiguration) val configuration = ConfigurationBuilder.build(configure as ConfigurationBuilder.Configuration.() -> Unit, ktorConfiguration) - val feature = Oauth2ServerFeature(configuration) - pipeline.intercept(ApplicationCallPipeline.Features) { + pipeline.intercept(ApplicationCallPipeline.Plugins) { val ktorCallContext = KtorCallContext(call) if (configuration.callRouter.authorizeEndpoint == ktorCallContext.path) { diff --git a/oauth2-server-sparkjava/pom.xml b/oauth2-server-sparkjava/pom.xml index f0481a6..02aa86c 100644 --- a/oauth2-server-sparkjava/pom.xml +++ b/oauth2-server-sparkjava/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/oauth2-server-token-store-inmemory/pom.xml b/oauth2-server-token-store-inmemory/pom.xml index 80ada66..1e87b84 100644 --- a/oauth2-server-token-store-inmemory/pom.xml +++ b/oauth2-server-token-store-inmemory/pom.xml @@ -5,7 +5,7 @@ kotlin-oauth2-server nl.myndocs - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 3ef9cb9..2792a2b 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ nl.myndocs kotlin-oauth2-server pom - 0.7.1-SNAPSHOT + 0.7.2-SNAPSHOT 1.6.21