diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 330fc72..0526cfa 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/main/kotlin/com/dariopellegrini/kdone/application/Application.kt b/src/main/kotlin/com/dariopellegrini/kdone/application/Application.kt index 3e0b78c..7046886 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/application/Application.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/application/Application.kt @@ -43,6 +43,10 @@ fun Application.installKDone(mongoDatabase: MongoDatabase, header(HttpHeaders.AcceptLanguage) header("facebookToken") header("facebookId") + header("appleToken") + header("appleId") + header("googleToken") + header("googleId") exposeHeader(HttpHeaders.Authorization) allowNonSimpleContentTypes = true anyHost() @@ -59,7 +63,7 @@ fun Application.installKDone(mongoDatabase: MongoDatabase, verifier { jwtConfig.verifier } - realm = "kdone.dariopellegrini.com" + realm = jwtConfig.issuer validate { credentials -> JWTValidator().validate(credentials) } diff --git a/src/main/kotlin/com/dariopellegrini/kdone/auth/JWTConfig.kt b/src/main/kotlin/com/dariopellegrini/kdone/auth/JWTConfig.kt index b1bac0f..8706d76 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/auth/JWTConfig.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/auth/JWTConfig.kt @@ -6,7 +6,7 @@ import com.auth0.jwt.algorithms.Algorithm import java.util.* class JWTConfig(private val secret: String, - private val issuer: String = "kdone.com", + val issuer: String = "kdone.com", private val validityInMs: Long? = null, // 100 hours private val algorithm: Algorithm = Algorithm.HMAC512(secret)) { diff --git a/src/main/kotlin/com/dariopellegrini/kdone/extensions/ApplicationCallExtensions.kt b/src/main/kotlin/com/dariopellegrini/kdone/extensions/ApplicationCallExtensions.kt index 8306780..23b03d0 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/extensions/ApplicationCallExtensions.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/extensions/ApplicationCallExtensions.kt @@ -26,14 +26,14 @@ import kotlin.reflect.full.isSubclassOf import kotlin.reflect.jvm.javaField import kotlin.reflect.jvm.jvmErasure -suspend inline fun ApplicationCall.receiveMap(): Map { - val inputMap = this.receive>() +suspend inline fun ApplicationCall.receiveMap(): Map { + val inputMap = this.receive>() val kClass = T::class val propertiesMap = kClass.declaredMemberProperties.map { it.name to it }.toMap() - val resultMap = mutableMapOf() + val resultMap = mutableMapOf() inputMap.forEach { entry -> val key = entry.key @@ -41,6 +41,7 @@ suspend inline fun ApplicationCall.receiveMap(): Map resultMap[key] = null entry.value is Map<*, *> -> { val element = ObjectMapper().configureForKDone().convertValue(entry.value, property.returnType.jvmErasure.java) resultMap[key] = element @@ -73,7 +74,7 @@ suspend inline fun ApplicationCall.receiveMap(): MapApplicationCall.receiveMultipartMap( uploader: Uploader, addUnknown: List = listOf(), - beforeUpload: (Map) -> Unit = {}): Map { + beforeUpload: (Map) -> Unit = {}): Map { val parts = this@receiveMultipartMap.receiveMultipart().readAllParts() @@ -152,13 +153,13 @@ suspend inline fun ApplicationCall.receiveMultipartMap( return resultMap } -suspend fun ApplicationCall.receiveMap(kClass: KClass): Map { +suspend fun ApplicationCall.receiveMap(kClass: KClass): Map { val inputMap = this.receive>() val propertiesMap = kClass.declaredMemberProperties.map { it.name to it }.toMap() - val resultMap = mutableMapOf() + val resultMap = mutableMapOf() inputMap.forEach { entry -> val key = entry.key @@ -167,6 +168,7 @@ suspend fun ApplicationCall.receiveMap(kClass: KClass): Map resultMap[key] = null entry.value is Map<*, *> -> { val element = ObjectMapper().configureForKDone().convertValue(entry.value, property.returnType.jvmErasure.java) resultMap[key] = element diff --git a/src/main/kotlin/com/dariopellegrini/kdone/extensions/MapExtensions.kt b/src/main/kotlin/com/dariopellegrini/kdone/extensions/MapExtensions.kt index 6011b21..8f2228b 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/extensions/MapExtensions.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/extensions/MapExtensions.kt @@ -4,7 +4,7 @@ import com.dariopellegrini.kdone.exceptions.MapCheckException import kotlin.reflect.full.memberProperties import kotlin.reflect.jvm.jvmErasure -inline fun Map.checkWithType() { +inline fun Map.checkWithType() { val kClass = T::class val parametersMap = kClass.memberProperties.associateBy { it.name } this.forEach { @@ -13,6 +13,6 @@ inline fun Map.checkWithType() { val value = entry.value val property = parametersMap[key] ?: throw MapCheckException("Parameter $key is not present $kClass") - if (property.returnType.jvmErasure != value::class) throw MapCheckException("Parameter $key is not compatible with $kClass") + if (value != null && property.returnType.jvmErasure != value::class) throw MapCheckException("Parameter $key is not compatible with $kClass") } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/dariopellegrini/kdone/routes/Module.kt b/src/main/kotlin/com/dariopellegrini/kdone/routes/Module.kt index aa0f2da..fd4f4bd 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/routes/Module.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/routes/Module.kt @@ -398,7 +398,7 @@ inline fun Route.module(endpoint: String, } webSocketController?.update(updatedElement, call.userAuthOrNull) } catch (e: Exception) { - call.respondWithException(e) +// call.respondWithException(e) configuration.exceptionHandler?.invoke(call, e) } } diff --git a/src/main/kotlin/com/dariopellegrini/kdone/routes/RouteConfiguration.kt b/src/main/kotlin/com/dariopellegrini/kdone/routes/RouteConfiguration.kt index 1229d9b..51f0741 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/routes/RouteConfiguration.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/routes/RouteConfiguration.kt @@ -24,8 +24,8 @@ class RouteConfiguration { var beforeGet: (suspend (ApplicationCall, Map) -> Unit)? = null var afterGet: (suspend (ApplicationCall, Map, List) -> Unit)? = null - var beforeUpdate: (suspend (ApplicationCall, Id, Map) -> Unit)? = null - var afterUpdate: (suspend (ApplicationCall, Map, T) -> Unit)? = null + var beforeUpdate: (suspend (ApplicationCall, Id, Map) -> Unit)? = null + var afterUpdate: (suspend (ApplicationCall, Map, T) -> Unit)? = null var beforeDelete: (suspend (ApplicationCall, Id) -> Unit)? = null var afterDelete: (suspend (ApplicationCall, DeleteResult) -> Unit)? = null @@ -76,11 +76,11 @@ class RouteConfiguration { afterGet = closure } - fun beforeUpdate(closure: suspend (ApplicationCall, Id, Map) -> Unit) { + fun beforeUpdate(closure: suspend (ApplicationCall, Id, Map) -> Unit) { beforeUpdate = closure } - fun afterUpdate(closure: suspend (ApplicationCall, Map, T) -> Unit) { + fun afterUpdate(closure: suspend (ApplicationCall, Map, T) -> Unit) { afterUpdate = closure } diff --git a/src/main/kotlin/com/dariopellegrini/kdone/startup/Startup.kt b/src/main/kotlin/com/dariopellegrini/kdone/startup/Startup.kt index 22c5d16..8d2fccb 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/startup/Startup.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/startup/Startup.kt @@ -6,6 +6,7 @@ import com.mongodb.ConnectionString import com.mongodb.MongoClientSettings import com.mongodb.client.MongoDatabase import com.mongodb.connection.SslSettings +import io.ktor.features.* import io.ktor.routing.Route import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty @@ -37,12 +38,12 @@ fun startKDone(port: Int, jwtConfig: JWTConfig, closure: Route.() -> Unit) { embeddedServer(Netty, port) { - val settings = MongoClientSettings.builder() - .applyConnectionString(ConnectionString(mongoURL)) - .applyToSslSettings { - builder: SslSettings.Builder -> builder.enabled(true).invalidHostNameAllowed(true) - } - .build() +// val settings = MongoClientSettings.builder() +// .applyConnectionString(ConnectionString(mongoURL)) +// .applyToSslSettings { +// builder: SslSettings.Builder -> builder.enabled(true).invalidHostNameAllowed(true) +// } +// .build() val client = KMongo.createClient(mongoURL) installKDone(client.getDatabase(databaseName), jwtConfig, diff --git a/src/main/kotlin/com/dariopellegrini/kdone/user/UserModule.kt b/src/main/kotlin/com/dariopellegrini/kdone/user/UserModule.kt index 216921a..3ba0e56 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/user/UserModule.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/user/UserModule.kt @@ -482,7 +482,7 @@ inline fun Route.userModule(endpoint: String = "users", if (!configuration.authorization.checkOwner(update)) throw NotAuthorizedException() call.checkToken(this@authenticate.database) - val patch: Map = if (call.request.isMultipart()) { + val patch: Map = if (call.request.isMultipart()) { val uploader = configuration.uploader ?: throw ServerException(500, "Uploader not configured") call.receiveMultipartMap(uploader) { map -> ownerForbiddenAttributes.forEach { diff --git a/src/main/kotlin/com/dariopellegrini/kdone/user/UserRouteConfiguration.kt b/src/main/kotlin/com/dariopellegrini/kdone/user/UserRouteConfiguration.kt index 3b8cb22..781955d 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/user/UserRouteConfiguration.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/user/UserRouteConfiguration.kt @@ -37,8 +37,8 @@ open class UserRouteConfiguration { var beforeGet: (suspend (ApplicationCall, Map) -> Unit)? = null var afterGet: (suspend (ApplicationCall, Map, List) -> Unit)? = null - var beforeUpdate: (suspend (ApplicationCall, Id, Map) -> Unit)? = null - var afterUpdate: (suspend (ApplicationCall, Map, T) -> Unit)? = null + var beforeUpdate: (suspend (ApplicationCall, Id, Map) -> Unit)? = null + var afterUpdate: (suspend (ApplicationCall, Map, T) -> Unit)? = null var beforeDelete: (suspend (ApplicationCall, Id) -> Unit)? = null var afterDelete: (suspend (ApplicationCall, DeleteResult) -> Unit)? = null @@ -116,11 +116,11 @@ open class UserRouteConfiguration { afterGet = closure } - fun beforeUpdate(closure: suspend (ApplicationCall, Id, Map) -> Unit) { + fun beforeUpdate(closure: suspend (ApplicationCall, Id, Map) -> Unit) { beforeUpdate = closure } - fun afterUpdate(closure: suspend (ApplicationCall, Map, T) -> Unit) { + fun afterUpdate(closure: suspend (ApplicationCall, Map, T) -> Unit) { afterUpdate = closure } diff --git a/src/main/kotlin/com/dariopellegrini/kdone/user/social/apple/AppleModule.kt b/src/main/kotlin/com/dariopellegrini/kdone/user/social/apple/AppleModule.kt index bfe44cc..f54fd82 100644 --- a/src/main/kotlin/com/dariopellegrini/kdone/user/social/apple/AppleModule.kt +++ b/src/main/kotlin/com/dariopellegrini/kdone/user/social/apple/AppleModule.kt @@ -136,7 +136,8 @@ suspend fun checkAppleToken(appleToken: String, appleId: String, bundleId: Strin override fun getPublicKeyById(kid: String): RSAPublicKey { val provider = UrlJwkProvider("https://appleid.apple.com/auth/keys/") - val jwk = provider.all.first() + val list = provider.all + val jwk = list.first { it.id == kid } return jwk.publicKey as RSAPublicKey } }