Added tanExpiredCallback, so that UI can react to when TAN expired

This commit is contained in:
dankito 2024-09-09 03:36:23 +02:00
parent 20f06387c5
commit 42bf002626
2 changed files with 37 additions and 2 deletions

View File

@ -392,7 +392,7 @@ open class FinTsJobExecutor(
// most TANs a valid 5 - 15 minutes. So terminate wait process after that time
(tanChallenge.tanExpirationTime == null && now > tanChallenge.challengeCreationTimestamp.plusMinutes(15))) {
if (tanChallenge.isEnteringTanDone == false) {
tanChallenge.userDidNotEnterTan()
tanChallenge.tanExpired()
}
break
@ -478,6 +478,8 @@ open class FinTsJobExecutor(
}
}
tanChallenge.tanExpired()
return null
}

View File

@ -5,6 +5,7 @@ import net.codinux.banking.fints.extensions.nowExt
import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanMedium
import net.codinux.banking.fints.response.BankResponse
import net.codinux.banking.fints.response.client.FinTsClientResponse
import net.codinux.log.Log
open class TanChallenge(
@ -30,6 +31,8 @@ open class TanChallenge(
open val isEnteringTanDone: Boolean
get() = enterTanResult != null
private val tanExpiredCallbacks = mutableListOf<() -> Unit>()
private val userApprovedDecoupledTanCallbacks = mutableListOf<() -> Unit>()
@ -40,7 +43,13 @@ open class TanChallenge(
internal fun userApprovedDecoupledTan(responseAfterApprovingDecoupledTan: BankResponse) {
this.enterTanResult = EnterTanResult(null, true, responseAfterApprovingDecoupledTan)
userApprovedDecoupledTanCallbacks.forEach { it.invoke() }
userApprovedDecoupledTanCallbacks.forEach {
try {
it.invoke()
} catch (e: Throwable) {
Log.error(e) { "Could not call userApprovedDecoupledTanCallback" }
}
}
clearUserApprovedDecoupledTanCallbacks()
}
@ -50,6 +59,20 @@ open class TanChallenge(
this.enterTanResult = EnterTanResult(null)
}
internal fun tanExpired() {
tanExpiredCallbacks.forEach {
try {
it.invoke()
} catch (e: Throwable) {
Log.error(e) { "Could not call tanExpiredCallback" }
}
}
clearTanExpiredCallbacks()
userDidNotEnterTan()
}
fun userAsksToChangeTanMethod(changeTanMethodTo: TanMethod) {
clearUserApprovedDecoupledTanCallbacks()
@ -63,6 +86,16 @@ open class TanChallenge(
}
fun addTanExpiredCallback(callback: () -> Unit) {
if (isEnteringTanDone == false) {
this.tanExpiredCallbacks.add(callback)
}
}
protected open fun clearTanExpiredCallbacks() {
tanExpiredCallbacks.clear()
}
fun addUserApprovedDecoupledTanCallback(callback: () -> Unit) {
if (isEnteringTanDone == false) {
this.userApprovedDecoupledTanCallbacks.add(callback)