From 110ba60c6557bf16a3bfc5f7ff5af46a98164c75 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 1 Feb 2019 11:54:25 +0100 Subject: Refactor server-side interfaces. --- .../kotlin/pl/treksoft/kvision/remote/KVServer.kt | 32 ------ .../pl/treksoft/kvision/remote/KVServiceManager.kt | 22 ++-- .../kotlin/pl/treksoft/kvision/remote/Profile.kt | 27 +++++ .../pl/treksoft/kvision/remote/ServiceManager.kt | 45 -------- .../kotlin/pl/treksoft/kvision/remote/KVServer.kt | 117 --------------------- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 10 +- .../kotlin/pl/treksoft/kvision/remote/Profile.kt | 111 +++++++++++++++++++ .../kotlin/pl/treksoft/kvision/remote/KVServer.kt | 20 +--- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 4 +- .../kotlin/pl/treksoft/kvision/remote/Profile.kt | 40 +++++++ .../kotlin/pl/treksoft/kvision/remote/KVServer.kt | 7 +- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 7 +- .../kotlin/pl/treksoft/kvision/remote/Profile.kt | 29 +++++ .../kotlin/pl/treksoft/kvision/remote/KVServer.kt | 33 +----- .../pl/treksoft/kvision/remote/KVServiceManager.kt | 7 +- .../kotlin/pl/treksoft/kvision/remote/Profile.kt | 52 +++++++++ 16 files changed, 284 insertions(+), 279 deletions(-) delete mode 100644 kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt create mode 100644 kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt delete mode 100644 kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt delete mode 100644 kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt create mode 100644 kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt create mode 100644 kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt create mode 100644 kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt create mode 100644 kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt deleted file mode 100644 index 4933624e..00000000 --- a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package pl.treksoft.kvision.remote - -/** - * A server. - */ -expect open class KVServer - -/** - * A user profile. - */ -expect class Profile diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 4b4fcfd2..224a8542 100644 --- a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -23,10 +23,25 @@ package pl.treksoft.kvision.remote import kotlin.reflect.KClass +enum class RpcHttpMethod { + POST, + PUT, + DELETE, + OPTIONS +} + +enum class HttpMethod { + GET, + POST, + PUT, + DELETE, + OPTIONS +} + /** * Multiplatform service manager. */ -expect open class KVServiceManager(serviceClass: KClass) : ServiceManager { +expect open class KVServiceManager(serviceClass: KClass) { /** * Binds a given route with a function of the receiver. @@ -107,9 +122,4 @@ expect open class KVServiceManager(serviceClass: KClass) : ServiceMa protected fun bind( function: T.(String?, String?) -> List ) - - /** - * Applies all defined routes to the given server. - */ - fun applyRoutes(k: KVServer) } diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt new file mode 100644 index 00000000..16deb350 --- /dev/null +++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.remote + +/** + * A user profile. + */ +expect class Profile diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt deleted file mode 100644 index 6f696475..00000000 --- a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/ServiceManager.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package pl.treksoft.kvision.remote - -enum class RpcHttpMethod { - POST, - PUT, - DELETE, - OPTIONS -} - -enum class HttpMethod { - GET, - POST, - PUT, - DELETE, - OPTIONS -} - -interface ServiceManager { - /** - * Returns the map of defined paths. - */ - fun getCalls(): Map> = mapOf() - -} diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt deleted file mode 100644 index 7b74ab00..00000000 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2017-present Robert Jaros - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package pl.treksoft.kvision.remote - -import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient - -/** - * A server. - * Not used on the js platform. - */ -actual open class KVServer - -/** - * A user profile. - */ -@Serializable -actual data class Profile( - val id: String? = null, - val attributes: MutableMap = mutableMapOf(), - val authenticationAttributes: MutableMap = mutableMapOf(), - val roles: MutableSet = mutableSetOf(), - val permissions: MutableSet = mutableSetOf(), - val linkedId: String? = null, - val remembered: Boolean = false, - val clientName: String? = null -) { - @Transient - var username: String? - get() = attributes["username"] - set(value) { - if (value != null) { - attributes["username"] = value - } else { - attributes.remove("username") - } - } - @Transient - var firstName: String? - get() = attributes["first_name"] - set(value) { - if (value != null) { - attributes["first_name"] = value - } else { - attributes.remove("first_name") - } - } - @Transient - var familyName: String? - get() = attributes["family_name"] - set(value) { - if (value != null) { - attributes["family_name"] = value - } else { - attributes.remove("family_name") - } - } - @Transient - var displayName: String? - get() = attributes["display_name"] - set(value) { - if (value != null) { - attributes["display_name"] = value - } else { - attributes.remove("display_name") - } - } - @Transient - var email: String? - get() = attributes["email"] - set(value) { - if (value != null) { - attributes["email"] = value - } else { - attributes.remove("email") - } - } - @Transient - var pictureUrl: String? - get() = attributes["picture_url"] - set(value) { - if (value != null) { - attributes["picture_url"] = value - } else { - attributes.remove("picture_url") - } - } - @Transient - var profileUrl: String? - get() = attributes["profile_url"] - set(value) { - if (value != null) { - attributes["profile_url"] = value - } else { - attributes.remove("profile_url") - } - } -} diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 383e8bb2..c13c4c18 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -26,7 +26,7 @@ import kotlin.reflect.KClass /** * Multiplatform service manager. */ -actual open class KVServiceManager actual constructor(serviceClass: KClass) : ServiceManager { +actual open class KVServiceManager actual constructor(serviceClass: KClass) { protected val calls: MutableMap> = mutableMapOf() var counter: Int = 0 @@ -131,12 +131,6 @@ actual open class KVServiceManager actual constructor(serviceClass: KCl /** * Returns the map of defined paths. */ - override fun getCalls(): Map> = calls + fun getCalls(): Map> = calls - /** - * Applies all defined routes to the given server. - * Not used on the js platform. - */ - actual fun applyRoutes(k: KVServer) { - } } diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt new file mode 100644 index 00000000..d5745afe --- /dev/null +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.remote + +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient + +/** + * A user profile. + */ +@Serializable +actual data class Profile( + val id: String? = null, + val attributes: MutableMap = mutableMapOf(), + val authenticationAttributes: MutableMap = mutableMapOf(), + val roles: MutableSet = mutableSetOf(), + val permissions: MutableSet = mutableSetOf(), + val linkedId: String? = null, + val remembered: Boolean = false, + val clientName: String? = null +) { + @Transient + var username: String? + get() = attributes["username"] + set(value) { + if (value != null) { + attributes["username"] = value + } else { + attributes.remove("username") + } + } + @Transient + var firstName: String? + get() = attributes["first_name"] + set(value) { + if (value != null) { + attributes["first_name"] = value + } else { + attributes.remove("first_name") + } + } + @Transient + var familyName: String? + get() = attributes["family_name"] + set(value) { + if (value != null) { + attributes["family_name"] = value + } else { + attributes.remove("family_name") + } + } + @Transient + var displayName: String? + get() = attributes["display_name"] + set(value) { + if (value != null) { + attributes["display_name"] = value + } else { + attributes.remove("display_name") + } + } + @Transient + var email: String? + get() = attributes["email"] + set(value) { + if (value != null) { + attributes["email"] = value + } else { + attributes.remove("email") + } + } + @Transient + var pictureUrl: String? + get() = attributes["picture_url"] + set(value) { + if (value != null) { + attributes["picture_url"] = value + } else { + attributes.remove("picture_url") + } + } + @Transient + var profileUrl: String? + get() = attributes["profile_url"] + set(value) { + if (value != null) { + attributes["profile_url"] = value + } else { + attributes.remove("profile_url") + } + } +} diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt index dd5e2dfd..eab093ec 100644 --- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt +++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt @@ -23,17 +23,14 @@ package pl.treksoft.kvision.remote import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.jooby.Kooby -import org.jooby.Request import org.jooby.json.Jackson -import org.pac4j.core.profile.CommonProfile import pl.treksoft.kvision.types.KV_JSON_DATE_FORMAT import java.text.SimpleDateFormat -import kotlinx.coroutines.async as coroutinesAsync /** * A Jooby based server. */ -actual open class KVServer(init: KVServer.() -> Unit) : Kooby() { +open class KVServer(init: KVServer.() -> Unit) : Kooby() { init { @Suppress("LeakingThis") assets("/", "index.html") @@ -48,18 +45,3 @@ actual open class KVServer(init: KVServer.() -> Unit) : Kooby() { init.invoke(this) } } - -/** - * A user profile. - */ -actual typealias Profile = CommonProfile - -/** - * A helper extension function for processing with authenticated user profile. - */ -fun Request.withProfile(block: (Profile) -> RESP): RESP { - val profile = this.require(CommonProfile::class.java) as CommonProfile? - return profile?.let { - block(profile) - } ?: throw IllegalStateException("Profile not set!") -} diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index a9b132c5..4e8516d3 100644 --- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -38,7 +38,7 @@ import kotlin.reflect.KClass * Multiplatform service manager for Jooby. */ @Suppress("LargeClass") -actual open class KVServiceManager actual constructor(val serviceClass: KClass) : ServiceManager { +actual open class KVServiceManager actual constructor(val serviceClass: KClass) { companion object { val LOG: Logger = LoggerFactory.getLogger(KVServiceManager::class.java.name) @@ -374,7 +374,7 @@ actual open class KVServiceManager actual constructor(val serviceClass: * Applies all defined routes to the given server. * @param k a server */ - actual fun applyRoutes(k: KVServer) { + fun applyRoutes(k: KVServer) { routes.forEach { it.invoke(k) } diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt new file mode 100644 index 00000000..98f8bdb3 --- /dev/null +++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.remote + +import org.jooby.Request +import org.pac4j.core.profile.CommonProfile + +/** + * A user profile. + */ +actual typealias Profile = CommonProfile + +/** + * A helper extension function for processing with authenticated user profile. + */ +fun Request.withProfile(block: (Profile) -> RESP): RESP { + val profile = this.require(CommonProfile::class.java) as CommonProfile? + return profile?.let { + block(profile) + } ?: throw IllegalStateException("Profile not set!") +} diff --git a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt index 81d6ee34..29084e5d 100644 --- a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt +++ b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt @@ -27,9 +27,4 @@ import kotlinx.coroutines.async as coroutinesAsync /** * A Ktor based server. */ -actual open class KVServer(val services: List>) - -/** - * A user profile. - */ -actual typealias Profile = CommonProfile +open class KVServer(val services: List>) diff --git a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index ecf2d290..471eff2a 100644 --- a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -36,7 +36,7 @@ import kotlin.reflect.KClass * Multiplatform service manager for Ktor. */ @UseExperimental(ExperimentalCoroutinesApi::class) -actual open class KVServiceManager actual constructor(val serviceClass: KClass) : ServiceManager { +actual open class KVServiceManager actual constructor(val serviceClass: KClass) { companion object { val LOG: Logger = LoggerFactory.getLogger(KVServiceManager::class.java.name) @@ -392,9 +392,4 @@ actual open class KVServiceManager actual constructor(val serviceClass: } } ?: null as T } - - /** - * Applies all defined routes to the given server. - */ - actual fun applyRoutes(k: KVServer) {} } diff --git a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt new file mode 100644 index 00000000..77ceb339 --- /dev/null +++ b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.remote + +import org.pac4j.core.profile.CommonProfile + +/** + * A user profile. + */ +actual typealias Profile = CommonProfile diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt index b0052be0..e8dee5cc 100644 --- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt +++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServer.kt @@ -21,38 +21,7 @@ */ package pl.treksoft.kvision.remote -import org.pac4j.core.context.J2EContext -import org.pac4j.core.context.session.J2ESessionStore -import org.pac4j.core.profile.CommonProfile -import org.pac4j.core.profile.ProfileManager -import org.springframework.web.context.request.RequestContextHolder -import org.springframework.web.context.request.ServletRequestAttributes -import kotlinx.coroutines.async as coroutinesAsync - /** * A Spring boot based server. */ -actual open class KVServer(val services: List>) - -/** - * A user profile. - */ -actual typealias Profile = CommonProfile - -/** - * A helper extension function for processing with authenticated user profile. - */ -@Suppress("TooGenericExceptionCaught") -fun withProfile(block: (Profile) -> RESP): RESP { - val profile = try { - val requestAttributes = (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes) - val req = requestAttributes.request - val resp = requestAttributes.response - ProfileManager(J2EContext(req, resp, J2ESessionStore())).get(true).get() - } catch (e: Exception) { - null - } - return profile?.let { - block(it) - } ?: throw IllegalStateException("Profile not set!") -} +open class KVServer(val services: List>) diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 6e8ee86e..4820fb2e 100644 --- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -38,7 +38,7 @@ import kotlin.reflect.KClass * Multiplatform service manager for Spring Boot. */ @UseExperimental(ExperimentalCoroutinesApi::class) -actual open class KVServiceManager actual constructor(val serviceClass: KClass) : ServiceManager { +actual open class KVServiceManager actual constructor(val serviceClass: KClass) { companion object { val LOG: Logger = LoggerFactory.getLogger(KVServiceManager::class.java.name) @@ -446,11 +446,6 @@ actual open class KVServiceManager actual constructor(val serviceClass: } } ?: null as T } - - /** - * Applies all defined routes to the given server. - */ - actual fun applyRoutes(k: KVServer) {} } fun HttpServletResponse.writeJSON(json: String) { diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt new file mode 100644 index 00000000..02c0fe27 --- /dev/null +++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/Profile.kt @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017-present Robert Jaros + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package pl.treksoft.kvision.remote + +import org.pac4j.core.context.J2EContext +import org.pac4j.core.context.session.J2ESessionStore +import org.pac4j.core.profile.CommonProfile +import org.pac4j.core.profile.ProfileManager +import org.springframework.web.context.request.RequestContextHolder +import org.springframework.web.context.request.ServletRequestAttributes + +/** + * A user profile. + */ +actual typealias Profile = CommonProfile + +/** + * A helper extension function for processing with authenticated user profile. + */ +@Suppress("TooGenericExceptionCaught") +fun withProfile(block: (Profile) -> RESP): RESP { + val profile = try { + val requestAttributes = (RequestContextHolder.getRequestAttributes() as ServletRequestAttributes) + val req = requestAttributes.request + val resp = requestAttributes.response + ProfileManager(J2EContext(req, resp, J2ESessionStore())).get(true).get() + } catch (e: Exception) { + null + } + return profile?.let { + block(it) + } ?: throw IllegalStateException("Profile not set!") +} -- cgit