Added all available TanMethods to TanChallenge

This commit is contained in:
dankito 2024-08-27 01:20:47 +02:00
parent 5ff2714512
commit 046a0c90eb
2 changed files with 33 additions and 5 deletions

View File

@ -1,7 +1,9 @@
package net.codinux.banking.client.model.tan
import net.codinux.banking.client.model.BankAccountViewInfo
import net.codinux.banking.client.model.CustomerAccount
import net.codinux.banking.client.model.CustomerAccountViewInfo
import net.codinux.banking.client.model.config.JsonIgnore
import net.codinux.banking.client.model.config.NoArgConstructor
@NoArgConstructor
@ -9,16 +11,39 @@ open class TanChallenge(
val type: TanChallengeType,
val forAction: ActionRequiringTan,
val messageToShowToUser: String,
val tanMethod: TanMethod,
/**
* Identifier of selected TanMethod.
*
* As [availableTanMethods] also contains selected TanMethod, we didn't want to duplicate this object. Use
* [selectedTanMethod] to get selected TanMethod or iterate over [availableTanMethods] and filter selected one by this id.
*/
val selectedTanMethodId: String,
/**
* When adding an account, frontend has no Customer object in BankingClientCallback to know which TanMethods are
* available for Customer.
* Also on other calls to bank server, bank server may returned an updated list of available TanMethods, so that
* [CustomerAccount] may contains an outdated list of available TanMethods.
*
* Therefore i added list with up to date TanMethods here to ensure EnterTanDialog can display user's up to date TanMethods.
*/
val availableTanMethods: List<TanMethod>,
// TODO: add available TanMedia - which frontend cannot know when adding an account - and selected TanMedium
val tanImage: TanImage? = null,
val flickerCode: FlickerCode? = null,
val customer: CustomerAccountViewInfo,
val account: BankAccountViewInfo? = null
// TODO: add availableTanMethods, selectedTanMedium, availableTanMedia
) {
@get:JsonIgnore
val selectedTanMethod: TanMethod
get() = availableTanMethods.first { it.identifier == selectedTanMethodId }
override fun toString(): String {
return "$tanMethod $forAction: $messageToShowToUser" + when (type) {
return "$selectedTanMethod $forAction: $messageToShowToUser" + when (type) {
TanChallengeType.EnterTan -> ""
TanChallengeType.Image -> ", Image: $tanImage"
TanChallengeType.Flickercode -> ", FlickerCode: $flickerCode"

View File

@ -120,14 +120,17 @@ open class FinTs4kMapper {
open fun mapTanChallenge(challenge: net.codinux.banking.fints.model.TanChallenge): TanChallenge {
val type = mapTanChallengeType(challenge)
val action = mapActionRequiringTan(challenge.forAction)
val tanMethod = mapTanMethod(challenge.tanMethod)
val tanMethods = challenge.bank.tanMethodsAvailableForUser.map { mapTanMethod(it) }
val selectedTanMethodId = challenge.tanMethod.securityFunction.code
val customer = mapToCustomerAccountViewInfo(challenge.bank)
val account = challenge.account?.let { mapToBankAccountViewInfo(it) }
val tanImage = if (challenge is ImageTanChallenge) mapTanImage(challenge.image) else null
val flickerCode = if (challenge is FlickerCodeTanChallenge) mapFlickerCode(challenge.flickerCode) else null
return TanChallenge(type, action, challenge.messageToShowToUser, tanMethod, tanImage, flickerCode, customer, account)
return TanChallenge(type, action, challenge.messageToShowToUser, selectedTanMethodId, tanMethods, tanImage, flickerCode, customer, account)
}
protected open fun mapTanChallengeType(challenge: net.codinux.banking.fints.model.TanChallenge): TanChallengeType = when {