diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-05-25 19:22:39 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-05-25 19:22:39 +0200 |
commit | c60488c51b2335a3848290e4a8e50b325b18ff5d (patch) | |
tree | 02ea8aee1788b12ad019c84e364d8114514434f2 /src/main/kotlin/pl/treksoft | |
parent | 0400c00cb69aac7b211b65cda5c38374a879a6bc (diff) | |
download | kvision-c60488c51b2335a3848290e4a8e50b325b18ff5d.tar.gz kvision-c60488c51b2335a3848290e4a8e50b325b18ff5d.tar.bz2 kvision-c60488c51b2335a3848290e4a8e50b325b18ff5d.zip |
Some fixes to pac4j security components.
Diffstat (limited to 'src/main/kotlin/pl/treksoft')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/remote/Security.kt | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt b/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt index 6373b27a..4e89f558 100644 --- a/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt +++ b/src/main/kotlin/pl/treksoft/kvision/remote/Security.kt @@ -47,11 +47,15 @@ class LoginService { * Login with Pac4j FormClient. * @param credentials username and password credentials */ - fun login(credentials: Credentials): Deferred<Boolean> = - loginAgent.remoteCall("callback?client_name=FormClient", obj { - this.username = credentials.username - this.password = credentials.password - }, HttpMethod.POST, "application/x-www-form-urlencoded").then { _: dynamic -> true }.asDeferred() + fun login(credentials: Credentials?): Deferred<Boolean> = + if (credentials?.username != null) { + loginAgent.remoteCall("callback?client_name=FormClient", obj { + this.username = credentials.username + this.password = credentials.password + }, HttpMethod.POST, "application/x-www-form-urlencoded").then { _: dynamic -> true }.asDeferred() + } else { + throw SecurityException("Credentials cannot be empty") + } } /** @@ -74,19 +78,23 @@ abstract class SecurityMgr { afterLogin() } } - } catch (e: SecurityException) { - afterError() - isLoggedIn = false - while (!isLoggedIn) { - try { - login().await() - isLoggedIn = true - afterLogin() - } catch (e: SecurityException) { - console.log(e) + } catch (e: Exception) { + if (e is SecurityException || !isLoggedIn) { + afterError() + isLoggedIn = false + while (!isLoggedIn) { + try { + login() + isLoggedIn = true + afterLogin() + } catch (e: Throwable) { + console.log(e) + } } + block() + } else { + throw e } - block() } } @@ -95,7 +103,7 @@ abstract class SecurityMgr { * @return true if login is successful * @throws SecurityException if login is not successful */ - abstract suspend fun login(): Deferred<Boolean> + abstract suspend fun login(): Boolean /** * Method called after successful login. |