From 3afd257320dc45fb7f3cd1241aff00205489aa0f Mon Sep 17 00:00:00 2001 From: dankl Date: Wed, 16 Oct 2019 14:11:19 +0200 Subject: [PATCH] Added enterTan(TanChallenge) to FinTsClientCallback to get tan from user --- .../android/ui/MainWindowPresenter.kt | 9 +++++---- .../kotlin/net/dankito/fints/FinTsClient.kt | 18 +++++++++++++++++- .../net/dankito/fints/FinTsClientCallback.kt | 3 +++ .../net/dankito/fints/model/TanChallenge.kt | 8 ++++++++ .../net/dankito/fints/java/JavaShowcase.java | 7 +++++++ .../net/dankito/fints/FinTsClientTest.kt | 9 +++++---- 6 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/model/TanChallenge.kt diff --git a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt index b69f193e..4f9e75ba 100644 --- a/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt +++ b/fints4javaAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/MainWindowPresenter.kt @@ -4,10 +4,7 @@ import net.dankito.banking.fints4java.android.Base64ServiceAndroid import net.dankito.fints.FinTsClient import net.dankito.fints.FinTsClientCallback import net.dankito.fints.banks.BankFinder -import net.dankito.fints.model.BankData -import net.dankito.fints.model.BankInfo -import net.dankito.fints.model.CustomerData -import net.dankito.fints.model.TanProcedure +import net.dankito.fints.model.* import net.dankito.fints.model.mapper.BankDataMapper import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.response.client.GetTransactionsResponse @@ -24,6 +21,10 @@ open class MainWindowPresenter { return supportedTanProcedures.first() } + override fun enterTan(tanChallenge: TanChallenge): String? { + return null + } + } protected val finTsClient = FinTsClient(callback, Base64ServiceAndroid()) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index ed6c4dac..d3f14b67 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -443,13 +443,29 @@ open class FinTsClient @JvmOverloads constructor( protected open fun handleMayRequiredTan(response: Response, bank: BankData, customer: CustomerData, dialogData: DialogData): Response { if (response.isStrongAuthenticationRequired) { response.tanResponse?.let { tanResponse -> - response.tanRequiredButNotProvided = true // TODO: show to user and wait for feedback + // TODO: is this true for all tan procedures? + val enteredTan = callback.enterTan(TanChallenge(tanResponse.challenge ?: "", + tanResponse.challengeHHD_UC ?: "", CustomerData.TanProcedureNotSelected)) // TODO: retrieve tan procedure + + if (enteredTan == null) { + // i tried to send a HKTAN with cancelJob = true but then i saw there are no tan procedures that support cancellation (at least not at my bank) + // but it's not required anyway, tan times out after some time. Simply don't respond anything and close dialog + response.tanRequiredButNotProvided = true + } + else { + return sendTanToBank(enteredTan, tanResponse) + } } } return response } + protected open fun sendTanToBank(enteredTan: String, tanResponse: TanResponse): Response { + // TODO + return Response(false) + } + protected open fun updateBankData(bank: BankData, response: Response) { response.getFirstSegmentById(InstituteSegmentId.BankParameters)?.let { bankParameters -> diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt index 00aa566c..67a4dbf9 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClientCallback.kt @@ -1,5 +1,6 @@ package net.dankito.fints +import net.dankito.fints.model.TanChallenge import net.dankito.fints.model.TanProcedure @@ -7,4 +8,6 @@ interface FinTsClientCallback { fun askUserForTanProcedure(supportedTanProcedures: List): TanProcedure? + fun enterTan(tanChallenge: TanChallenge): String? + } \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/TanChallenge.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/TanChallenge.kt new file mode 100644 index 00000000..e9886031 --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/TanChallenge.kt @@ -0,0 +1,8 @@ +package net.dankito.fints.model + + +open class TanChallenge( + val messageToShowToUser: String, + val tanChallenge: String, + val tanProcedure: TanProcedure +) \ No newline at end of file diff --git a/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java b/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java index f2e663a3..4e09c2f8 100644 --- a/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java +++ b/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java @@ -38,6 +38,13 @@ public class JavaShowcase { // TODO: if entering TAN is required select your tan procedure here return supportedTanProcedures.get(0); } + + @Nullable + @Override + public String enterTan(@NotNull TanChallenge tanChallenge) { + return null; + } + }; FinTsClient finTsClient = new FinTsClient(callback, new Java8Base64Service()); diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt index 54ec8f9a..d3f40baf 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt @@ -4,14 +4,12 @@ import net.dankito.fints.messages.datenelemente.abgeleiteteformate.Laenderkennze import net.dankito.fints.messages.datenelemente.implementierte.Dialogsprache import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatus import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatusWerte -import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion import net.dankito.fints.model.* import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.util.Java8Base64Service import org.assertj.core.api.Assertions.assertThat import org.junit.Ignore import org.junit.Test -import java.util.* @Ignore // not an automatic test, supply your settings below @@ -24,6 +22,10 @@ class FinTsClientTest { return supportedTanProcedures.first() } + override fun enterTan(tanChallenge: TanChallenge): String? { + return null + } + } @@ -40,8 +42,7 @@ class FinTsClientTest { // TODO: add your settings here: private val Bank = BankData("", Laenderkennzeichen.Germany, "", bic = "") - private val Customer = CustomerData("", "", name = "", iban = "", - selectedTanProcedure = TanProcedure("", Sicherheitsfunktion.PIN_TAN_911, TanProcedureType.ChipTan)) + private val Customer = CustomerData("", "", iban = "") // transfer 1 cent to yourself. Transferring money to oneself also doesn't require to enter a TAN according to PSD2 private val BankTransferData = BankTransferData(Customer.name, Customer.iban!!, Bank.bic!!, 0.01.toBigDecimal(), "Give it to me baby")