Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/event' into event
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashi1993 committed Oct 27, 2024
2 parents b74b5f0 + bd0da2b commit 867c2d6
Show file tree
Hide file tree
Showing 8 changed files with 2,767 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* under the License.
*/

package org.wso2.financial.services.accelerator.consent.mgt.extensions.common.idempotency;
package com.wso2.openbanking.accelerator.consent.extensions.common.idempotency;

import org.wso2.financial.services.accelerator.common.exception.ConsentManagementException;
import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;

/**
* Used for handling exceptions in Idempotency Validation.
*/
public class IdempotencyValidationException extends ConsentManagementException {
public class IdempotencyValidationException extends OpenBankingException {

public IdempotencyValidationException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,22 @@
* under the License.
*/

package org.wso2.financial.services.accelerator.consent.mgt.extensions.common.idempotency;
package com.wso2.openbanking.accelerator.consent.extensions.common.idempotency;

import com.wso2.openbanking.accelerator.common.config.OpenBankingConfigParser;
import com.wso2.openbanking.accelerator.common.exception.ConsentManagementException;
import com.wso2.openbanking.accelerator.consent.extensions.internal.ConsentExtensionsDataHolder;
import com.wso2.openbanking.accelerator.consent.mgt.service.ConsentCoreService;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigParser;
import org.wso2.financial.services.accelerator.common.exception.ConsentManagementException;
import org.wso2.financial.services.accelerator.consent.mgt.extensions.internal.ConsentExtensionsDataHolder;
import org.wso2.financial.services.accelerator.consent.mgt.service.ConsentCoreService;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Class to hold idempotency validation utils.
Expand All @@ -52,8 +49,8 @@ public class IdempotencyValidationUtils {
* @param idempotencyKeyValue Idempotency Key Value
* @return List of consent ids if available, else an empty list will be returned
*/
static List<String> getConsentIdsFromIdempotencyKey(String idempotencyKeyName,
String idempotencyKeyValue) {
static ArrayList<String> getConsentIdsFromIdempotencyKey(String idempotencyKeyName,
String idempotencyKeyValue) {
try {
return consentCoreService.getConsentIdByConsentAttributeNameAndValue(
idempotencyKeyName, idempotencyKeyValue);
Expand All @@ -63,21 +60,6 @@ static List<String> getConsentIdsFromIdempotencyKey(String idempotencyKeyName,
}
}

/**
* Method to retrieve the consent ids and idempotency key value using the idempotency key.
*
* @param idempotencyKeyName Idempotency Key Name
* @return Map of consent ids and idempotency key vallue if available, else an empty map will be returned
*/
static Map<String, String> getAttributesFromIdempotencyKey(String idempotencyKeyName) {
try {
return consentCoreService.getConsentAttributesByName(idempotencyKeyName);
} catch (ConsentManagementException e) {
log.debug("No consent ids found for the idempotency key value");
return new HashMap<>();
}
}

/**
* Method to compare the client ID sent in the request and client id retrieved from the database.
*
Expand All @@ -104,13 +86,13 @@ static boolean isRequestReceivedWithinAllowedTime(long createdTime) {
log.debug("Created time is of the previous request is not correctly set. Hence returning false");
return false;
}
String allowedTimeDuration = FinancialServicesConfigParser.getInstance().getIdempotencyAllowedTime();
String allowedTimeDuration = OpenBankingConfigParser.getInstance().getIdempotencyAllowedTime();
if (StringUtils.isNotBlank(allowedTimeDuration)) {
OffsetDateTime createdDate = OffsetDateTime.parse(toISO8601DateTime(createdTime));
OffsetDateTime currDate = OffsetDateTime.now(createdDate.getOffset());

long diffInHours = Duration.between(createdDate, currDate).toHours();
return diffInHours <= Long.parseLong(allowedTimeDuration);
long diffInMinutes = Duration.between(createdDate, currDate).toMinutes();
return diffInMinutes <= Long.parseLong(allowedTimeDuration);
} else {
log.error("Idempotency allowed duration is not configured in the system. Hence returning false");
return false;
Expand Down
Loading

0 comments on commit 867c2d6

Please sign in to comment.