diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/FinTsClientCallback.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/FinTsClientCallback.kt index 195fb8f0..2b2f8638 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/FinTsClientCallback.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/FinTsClientCallback.kt @@ -27,4 +27,11 @@ interface FinTsClientCallback { */ suspend fun enterTanGeneratorAtc(bank: BankData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult + /** + * Gets fired when a FinTS message get sent to bank server, a FinTS message is received from bank server or an error occurred. + * + * Be aware, in order that this message gets fired [net.dankito.banking.fints.config.FinTsClientOptions.fireCallbackOnMessageLogs] has to be set to true. + */ + fun messageLogAdded(messageLogEntry: MessageLogEntry) + } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/NoOpFinTsClientCallback.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/NoOpFinTsClientCallback.kt index a1bb118a..a7506e83 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/NoOpFinTsClientCallback.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/NoOpFinTsClientCallback.kt @@ -18,4 +18,8 @@ open class NoOpFinTsClientCallback : FinTsClientCallback { return EnterTanGeneratorAtcResult.userDidNotEnterAtc() } + override fun messageLogAdded(messageLogEntry: MessageLogEntry) { + + } + } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/SimpleFinTsClientCallback.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/SimpleFinTsClientCallback.kt index 9b90695d..66b52f4b 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/SimpleFinTsClientCallback.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/callback/SimpleFinTsClientCallback.kt @@ -5,14 +5,15 @@ import net.dankito.banking.fints.model.* open class SimpleFinTsClientCallback( - protected open val enterTan: ((tanChallenge: TanChallenge) -> Unit)? = null, + protected open val askUserForTanMethod: ((supportedTanMethods: List, suggestedTanMethod: TanMethod?) -> TanMethod?)? = null, + protected open val messageLogAdded: ((MessageLogEntry) -> Unit)? = null, protected open val enterTanGeneratorAtc: ((bank: BankData, tanMedium: TanGeneratorTanMedium) -> EnterTanGeneratorAtcResult)? = null, - protected open val askUserForTanMethod: ((supportedTanMethods: List, suggestedTanMethod: TanMethod?) -> TanMethod?)? = null + protected open val enterTan: ((tanChallenge: TanChallenge) -> Unit)? = null ) : FinTsClientCallback { - constructor() : this(null) // Swift does not support default parameter values -> create constructor overloads + constructor() : this(null as ((tanChallenge: TanChallenge) -> Unit)?) // Swift does not support default parameter values -> create constructor overloads - constructor(enterTan: ((tanChallenge: TanChallenge) -> Unit)?) : this(enterTan, null) + constructor(enterTan: ((tanChallenge: TanChallenge) -> Unit)?) : this(null, null, null, enterTan) override suspend fun askUserForTanMethod(supportedTanMethods: List, suggestedTanMethod: TanMethod?): TanMethod? { @@ -28,4 +29,8 @@ open class SimpleFinTsClientCallback( return enterTanGeneratorAtc?.invoke(bank, tanMedium) ?: EnterTanGeneratorAtcResult.userDidNotEnterAtc() } + override fun messageLogAdded(messageLogEntry: MessageLogEntry) { + messageLogAdded?.invoke(messageLogEntry) + } + } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/config/FinTsClientOptions.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/config/FinTsClientOptions.kt index cab7bfa6..b37330a1 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/config/FinTsClientOptions.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/config/FinTsClientOptions.kt @@ -3,6 +3,19 @@ package net.dankito.banking.fints.config import net.dankito.banking.fints.model.ProductData data class FinTsClientOptions( + /** + * If set to true then [net.dankito.banking.fints.callback.FinTsClientCallback.messageLogAdded] get fired when a + * FinTS message get sent to bank server, a FinTS message is received from bank server or an error occurred. + * + * Defaults to false. + */ + val fireCallbackOnMessageLogs: Boolean = false, + + /** + * If sensitive data like user name, password, login name should be removed from FinTS messages before being logged. + * + * Defaults to true. + */ val removeSensitiveDataFromMessageLog: Boolean = true, val version: String = "1.0.0", // TODO: get version dynamically val productName: String = "15E53C26816138699C7B6A3E8" diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt index f955438b..e91f5de2 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/log/MessageLogCollector.kt @@ -2,6 +2,7 @@ package net.dankito.banking.fints.log import net.codinux.log.LoggerFactory import net.codinux.log.logger +import net.dankito.banking.fints.callback.FinTsClientCallback import net.dankito.banking.fints.config.FinTsClientOptions import net.dankito.banking.fints.model.BankData import net.dankito.banking.fints.model.MessageLogEntry @@ -14,6 +15,7 @@ import kotlin.reflect.KClass open class MessageLogCollector( + private val callback: FinTsClientCallback, private val options: FinTsClientOptions = FinTsClientOptions(), private val finTsUtils: FinTsUtils = FinTsUtils() ) { @@ -55,9 +57,9 @@ open class MessageLogCollector( open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext) { val messageTrace = createMessageTraceString(type, context) - addMessageLogEntry(type, context, messageTrace, message) - log.debug { "$messageTrace\n${prettyPrintFinTsMessage(message)}" } + + addMessageLogEntry(type, context, messageTrace, message) } open fun logError(loggingClass: KClass<*>, message: String, context: MessageContext, e: Exception? = null) { @@ -70,7 +72,14 @@ open class MessageLogCollector( } protected open fun addMessageLogEntry(type: MessageLogEntryType, context: MessageContext, messageTrace: String, message: String, error: Throwable? = null) { - _messageLog.add(MessageLogEntry(type, context, messageTrace, message, error)) + val newEntry = MessageLogEntry(type, context, messageTrace, message, error) + + _messageLog.add(newEntry) + + if (options.fireCallbackOnMessageLogs) { + // TODO: pretty print message + callback.messageLogAdded(newEntry) + } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/JobContext.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/JobContext.kt index 694943dc..213f9682 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/JobContext.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/JobContext.kt @@ -24,7 +24,7 @@ open class JobContext( * Only set if the current context is for a specific account (like get account's transactions). */ open val account: AccountData? = null, - protected open val messageLogCollector: MessageLogCollector = MessageLogCollector(config.options) + protected open val messageLogCollector: MessageLogCollector = MessageLogCollector(callback, config.options) ) : MessageBaseData(bank, config.options.product), IMessageLogAppender { companion object {