From f3133ebb4adadb31d9e31c31bc2d50ec76aa0863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Tue, 3 Jun 2025 16:14:36 +0200 Subject: [PATCH] feature/96 - TPP requests without PSU involvement --- .../scala/code/api/util/ConsentUtil.scala | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/obp-api/src/main/scala/code/api/util/ConsentUtil.scala b/obp-api/src/main/scala/code/api/util/ConsentUtil.scala index 675cb018b..4d40f75bc 100644 --- a/obp-api/src/main/scala/code/api/util/ConsentUtil.scala +++ b/obp-api/src/main/scala/code/api/util/ConsentUtil.scala @@ -532,25 +532,30 @@ object Consent extends MdcLoggable { } def checkFrequencyPerDay(storedConsent: consent.ConsentTrait) = { - def isSameDay(date1: Date, date2: Date): Boolean = { - val fmt = new SimpleDateFormat("yyyyMMdd") - fmt.format(date1).equals(fmt.format(date2)) - } - var usesSoFarTodayCounter = storedConsent.usesSoFarTodayCounter - storedConsent.recurringIndicator match { - case false => // The consent is for one access to the account data - if(usesSoFarTodayCounter == 0) // Maximum value is "1". - (true, 0) // All good - else - (false, 1) // Exceeded rate limit - case true => // The consent is for recurring access to the account data - if(!isSameDay(storedConsent.usesSoFarTodayCounterUpdatedAt, new Date())) { - usesSoFarTodayCounter = 0 // Reset counter - } - if(usesSoFarTodayCounter < storedConsent.frequencyPerDay) - (true, usesSoFarTodayCounter) // All good - else - (false, storedConsent.frequencyPerDay) // Exceeded rate limit + if(BerlinGroupCheck.isTppRequestsWithoutPsuInvolvement(callContext.requestHeaders)) { + def isSameDay(date1: Date, date2: Date): Boolean = { + val fmt = new SimpleDateFormat("yyyyMMdd") + fmt.format(date1).equals(fmt.format(date2)) + } + + var usesSoFarTodayCounter = storedConsent.usesSoFarTodayCounter + storedConsent.recurringIndicator match { + case false => // The consent is for one access to the account data + if (usesSoFarTodayCounter == 0) // Maximum value is "1". + (true, 0) // All good + else + (false, 1) // Exceeded rate limit + case true => // The consent is for recurring access to the account data + if (!isSameDay(storedConsent.usesSoFarTodayCounterUpdatedAt, new Date())) { + usesSoFarTodayCounter = 0 // Reset counter + } + if (usesSoFarTodayCounter < storedConsent.frequencyPerDay) + (true, usesSoFarTodayCounter) // All good + else + (false, storedConsent.frequencyPerDay) // Exceeded rate limit + } + } else { + (true, 0) // All good } }