From 989bbd65aa80039da6c49996a04ed48a188398ef Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 12 Aug 2020 15:08:54 +0200 Subject: [PATCH] Implemented that if a TAN procedure requires specifying TAN media name, that any tan media name gets supplied (in my tests it made absolutely no difference if the TAN media matches the TAN procedure) --- .../net/dankito/banking/fints/FinTsClient.kt | 3 +- .../banking/fints/messages/MessageBuilder.kt | 33 +++++++++++-------- .../banking/fints/model/TanProcedure.kt | 3 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt index 6d5acdc0..5b282d73 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -1137,7 +1137,8 @@ open class FinTsClient( } return TanProcedure(procedureName, parameters.securityFunction, - mapToTanProcedureType(parameters) ?: TanProcedureType.EnterTan, mapHhdVersion(parameters)) + mapToTanProcedureType(parameters) ?: TanProcedureType.EnterTan, mapHhdVersion(parameters), + parameters.nameOfTanMediaRequired == BezeichnungDesTanMediumsErforderlich.BezeichnungDesTanMediumsMussAngegebenWerden) } protected open fun mapToTanProcedureType(parameters: TanProcedureParameters): TanProcedureType? { diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt index 46016726..2fee9d7c 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/messages/MessageBuilder.kt @@ -115,10 +115,10 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg ) if (segmentIdForTwoStepTanProcess != null) { - segments.add(ZweiSchrittTanEinreichung(generator.getNextSegmentNumber(), TanProcess.TanProcess4, segmentIdForTwoStepTanProcess)) + segments.add(createTwoStepTanSegment(segmentIdForTwoStepTanProcess, dialogContext)) } else if (dialogContext.customer.isTanProcedureSelected) { - segments.add(ZweiSchrittTanEinreichung(generator.getNextSegmentNumber(), TanProcess.TanProcess4, CustomerSegmentId.Identification)) + segments.add(createTwoStepTanSegment(CustomerSegmentId.Identification, dialogContext)) } if (dialogContext.customer.customerSystemId == KundensystemID.Anonymous) { @@ -133,7 +133,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg return createSignedMessageBuilderResult(dialogContext, listOf( IdentifikationsSegment(generator.resetSegmentNumber(2), dialogContext), Verarbeitungsvorbereitung(generator.getNextSegmentNumber(), dialogContext), - ZweiSchrittTanEinreichung(generator.getNextSegmentNumber(), TanProcess.TanProcess4, CustomerSegmentId.Identification), + createTwoStepTanSegment(CustomerSegmentId.Identification, dialogContext), Synchronisierung(generator.getNextSegmentNumber(), Synchronisierungsmodus.NeueKundensystemIdZurueckmelden) )) } @@ -407,7 +407,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg } - private fun encryptPayload(dialogContext: DialogContext, date: Int, time: Int, + protected open fun encryptPayload(dialogContext: DialogContext, date: Int, time: Int, payload: List): List { val encryptionHeader = PinTanVerschluesselungskopf(dialogContext, date, time) @@ -460,11 +460,24 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg protected open fun addTanSegmentIfRequired(segmentId: CustomerSegmentId, dialogContext: DialogContext, segments: MutableList) { if (isTanRequiredForJob(segmentId, dialogContext)) { - segments.add(ZweiSchrittTanEinreichung( - generator.getNextSegmentNumber(), TanProcess.TanProcess4, segmentId)) + segments.add(createTwoStepTanSegment(segmentId, dialogContext)) } } + protected open fun createTwoStepTanSegment(segmentId: CustomerSegmentId, dialogContext: DialogContext): ZweiSchrittTanEinreichung { + return ZweiSchrittTanEinreichung(generator.getNextSegmentNumber(), TanProcess.TanProcess4, segmentId, tanMediaIdentifier = getTanMediaIdentifierIfRequired(dialogContext)) + } + + protected open fun getTanMediaIdentifierIfRequired(dialogContext: DialogContext): String? { + val customer = dialogContext.customer + + if (customer.isTanProcedureSelected && customer.selectedTanProcedure.nameOfTanMediaRequired) { + return customer.tanMedia.firstOrNull { it.mediumName != null }?.mediumName + } + + return null + } + protected open fun isTanRequiredForJob(segmentId: CustomerSegmentId, dialogContext: DialogContext): Boolean { return dialogContext.bank.pinInfo?.jobTanConfiguration?.first { it.segmentId == segmentId.id }?.tanRequired ?: false // TODO: actually in this case it's not allowed to execute job via PIN/TAN at all @@ -479,14 +492,6 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg .firstOrNull { it.contains(sepaDataFormat) } } - // TODO: this implementation is in most cases wrong, try to get rid of - protected open fun getAllowedJobs(segmentId: CustomerSegmentId, customer: CustomerData): List { - - return customer.accounts.flatMap { account -> - return account.allowedJobs.filter { it.jobName == segmentId.id } - } - } - // TODO: move to a library fun Collection.containsAny(otherCollection: Collection): Boolean { diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/TanProcedure.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/TanProcedure.kt index 5ee94b32..c1c0b66f 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/TanProcedure.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/TanProcedure.kt @@ -7,7 +7,8 @@ open class TanProcedure( val displayName: String, val securityFunction: Sicherheitsfunktion, val type: TanProcedureType, - val hhdVersion: HHDVersion? = null + val hhdVersion: HHDVersion? = null, + val nameOfTanMediaRequired: Boolean = false ) {