diff options
Diffstat (limited to 'kvision-modules/kvision-server-ktor/src/main/kotlin/pl')
2 files changed, 96 insertions, 4 deletions
diff --git a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVModules.kt b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVModules.kt index 06018761..e322aec5 100644 --- a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVModules.kt +++ b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVModules.kt @@ -31,7 +31,7 @@ import io.ktor.application.ApplicationCallPipeline import io.ktor.application.call import io.ktor.application.install import io.ktor.features.ContentNegotiation -import io.ktor.http.content.default +import io.ktor.http.content.defaultResource import io.ktor.http.content.resources import io.ktor.http.content.static import io.ktor.jackson.jackson @@ -49,7 +49,7 @@ fun Application.kvisionInit(vararg modules: Module) { routing { static("/") { resources("assets") - default("index.html") + defaultResource("assets/index.html") } } 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 index 77ceb339..693c8e3c 100644 --- 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 @@ -21,9 +21,101 @@ */ package pl.treksoft.kvision.remote -import org.pac4j.core.profile.CommonProfile +import io.ktor.application.ApplicationCall +import io.ktor.sessions.get +import io.ktor.sessions.sessions +import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient /** * A user profile. */ -actual typealias Profile = CommonProfile +@Serializable +actual data class Profile( + val id: String? = null, + val attributes: MutableMap<String, String> = mutableMapOf(), + val authenticationAttributes: MutableMap<String, String> = mutableMapOf(), + val roles: MutableSet<String> = mutableSetOf(), + val permissions: MutableSet<String> = 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") + } + } +} + +suspend fun <RESP> ApplicationCall.withProfile(block: suspend (Profile) -> RESP): RESP { + val profile = this.sessions.get<Profile>() + return profile?.let { + block(profile) + } ?: throw IllegalStateException("Profile not set!") +} |