diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-05-25 13:39:51 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-05-25 13:39:51 +0200 |
commit | 4df5c5e0801e6077c6472883338ee6b9b66fadfa (patch) | |
tree | f549488adbd32a8b78b54b84f848176398eed6f1 /kvision-server | |
parent | f1bb9fa4fca9b49c861b0828a8ba2360417777de (diff) | |
download | kvision-4df5c5e0801e6077c6472883338ee6b9b66fadfa.tar.gz kvision-4df5c5e0801e6077c6472883338ee6b9b66fadfa.tar.bz2 kvision-4df5c5e0801e6077c6472883338ee6b9b66fadfa.zip |
Pac4j security module integration.
Diffstat (limited to 'kvision-server')
-rw-r--r-- | kvision-server/build.gradle | 1 | ||||
-rw-r--r-- | kvision-server/src/main/kotlin/pl/treksoft/kvision/remote/Jooby.kt | 24 |
2 files changed, 22 insertions, 3 deletions
diff --git a/kvision-server/build.gradle b/kvision-server/build.gradle index 6d623b3d..aa96a580 100644 --- a/kvision-server/build.gradle +++ b/kvision-server/build.gradle @@ -15,6 +15,7 @@ dependencies { compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" compile "org.jooby:jooby-lang-kotlin" compile "org.jooby:jooby-jackson" + compile "org.jooby:jooby-pac4j2" compile "com.github.andrewoma.kwery:mapper:${kweryVersion}" compile "com.fasterxml.jackson.module:jackson-module-kotlin:${jacksonModuleKotlinVersion}" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlinVersion" diff --git a/kvision-server/src/main/kotlin/pl/treksoft/kvision/remote/Jooby.kt b/kvision-server/src/main/kotlin/pl/treksoft/kvision/remote/Jooby.kt index 7d339d04..a529aa27 100644 --- a/kvision-server/src/main/kotlin/pl/treksoft/kvision/remote/Jooby.kt +++ b/kvision-server/src/main/kotlin/pl/treksoft/kvision/remote/Jooby.kt @@ -25,9 +25,11 @@ package pl.treksoft.kvision.remote import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import kotlinx.coroutines.experimental.Deferred +import kotlinx.coroutines.experimental.Unconfined import org.jooby.Kooby import org.jooby.Session import org.jooby.json.Jackson +import org.pac4j.core.profile.CommonProfile import kotlinx.coroutines.experimental.async as coroutinesAsync /** @@ -53,10 +55,15 @@ actual open class JoobyServer(init: JoobyServer.() -> Unit) : Kooby() { actual typealias Request = org.jooby.Request /** + * A user profile. + */ +actual typealias Profile = CommonProfile + +/** * A helper extension function for asynchronous request processing. */ fun <RESP> Request?.async(block: (Request) -> RESP): Deferred<RESP> = this?.let { req -> - coroutinesAsync { + coroutinesAsync(Unconfined) { block(req) } } ?: throw IllegalStateException("Request not set!") @@ -64,9 +71,20 @@ fun <RESP> Request?.async(block: (Request) -> RESP): Deferred<RESP> = this?.let /** * A helper extension function for asynchronous request processing with session. */ -fun <RESP> Request?.asyncSession(block: (Request, Session) -> RESP): Deferred<RESP> = this?.let { req -> +fun <RESP> Request?.async(block: (Request, Session) -> RESP): Deferred<RESP> = this?.let { req -> val session = req.session() - coroutinesAsync { + coroutinesAsync(Unconfined) { block(req, session) } } ?: throw IllegalStateException("Request not set!") + +/** + * A helper extension function for asynchronous request processing with session and user profile. + */ +fun <RESP> Request?.async(block: (Request, Session, Profile) -> RESP): Deferred<RESP> = this?.let { req -> + val session = req.session() + val profile = req.require(CommonProfile::class.java) + coroutinesAsync(Unconfined) { + block(req, session, profile) + } +} ?: throw IllegalStateException("Request not set!") |