diff --git a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/AccountInitiationRequestHandler.java b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/AccountInitiationRequestHandler.java index 729e2281..63a22ef5 100644 --- a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/AccountInitiationRequestHandler.java +++ b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/AccountInitiationRequestHandler.java @@ -204,8 +204,8 @@ protected Map getConsentAttributesToPersist(ConsentManageData co consentAttributesMap.put(ConsentExtensionConstants.TPP_EXPLICIT_AUTH_PREFERRED_HEADER, headersMap.get(ConsentExtensionConstants.TPP_EXPLICIT_AUTH_PREFERRED_HEADER)); } - consentAttributesMap.put(ConsentExtensionConstants.X_REQUEST_ID, - headersMap.get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); + consentAttributesMap.put(CommonConsentUtil.constructAttributeKey(consentManageData.getRequestPath(), + ConsentExtensionConstants.X_REQUEST_ID), headersMap.get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); return consentAttributesMap; } diff --git a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/ExplicitAuthRequestHandler.java b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/ExplicitAuthRequestHandler.java index ff09e250..dce2eef7 100644 --- a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/ExplicitAuthRequestHandler.java +++ b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/ExplicitAuthRequestHandler.java @@ -218,15 +218,21 @@ public void handle(ConsentManageData consentManageData) throws ConsentException } else { Map attributesToStore = new HashMap<>(); if (StringUtils.equals(AuthTypeEnum.CANCELLATION.toString(), authType)) { - attributesToStore.put(ConsentExtensionConstants.AUTH_CANCEL_X_REQUEST_ID, - consentManageData.getHeaders().get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); - attributesToStore.put(ConsentExtensionConstants.AUTH_CANCEL_CREATED_TIME, - String.valueOf(OffsetDateTime.now().toEpochSecond())); + String xRequestIdKey = CommonConsentUtil.constructAttributeKey( + consentManageData.getRequestPath(), ConsentExtensionConstants.AUTH_CANCEL_X_REQUEST_ID); + attributesToStore.put(xRequestIdKey, consentManageData.getHeaders() + .get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); + String createdTimeKey = CommonConsentUtil.constructAttributeKey( + consentManageData.getRequestPath(), ConsentExtensionConstants.AUTH_CANCEL_CREATED_TIME); + attributesToStore.put(createdTimeKey, String.valueOf(OffsetDateTime.now().toEpochSecond())); } else { - attributesToStore.put(ConsentExtensionConstants.EXPLICIT_AUTH_X_REQUEST_ID, - consentManageData.getHeaders().get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); - attributesToStore.put(ConsentExtensionConstants.EXPLICIT_AUTH_CREATED_TIME, - String.valueOf(OffsetDateTime.now().toEpochSecond())); + String xRequestIdKey = CommonConsentUtil.constructAttributeKey( + consentManageData.getRequestPath(), ConsentExtensionConstants.EXPLICIT_AUTH_X_REQUEST_ID); + attributesToStore.put(xRequestIdKey, consentManageData.getHeaders() + .get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); + String createdTimeKey = CommonConsentUtil.constructAttributeKey( + consentManageData.getRequestPath(), ConsentExtensionConstants.EXPLICIT_AUTH_CREATED_TIME); + attributesToStore.put(createdTimeKey, String.valueOf(OffsetDateTime.now().toEpochSecond())); } try { @@ -290,15 +296,21 @@ protected Map getConsentAttributesToPersist(ConsentManageData co if (StringUtils.contains(consentManageData.getRequestPath(), ConsentExtensionConstants.PAYMENT_EXPLICIT_CANCELLATION_AUTHORISATION_PATH_END)) { - consentAttributesMap.put(ConsentExtensionConstants.AUTH_CANCEL_X_REQUEST_ID, - consentManageData.getHeaders().get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); - consentAttributesMap.put(ConsentExtensionConstants.AUTH_CANCEL_CREATED_TIME, - String.valueOf(OffsetDateTime.now().toEpochSecond())); + String xRequestIdKey = CommonConsentUtil.constructAttributeKey( + consentManageData.getRequestPath(), ConsentExtensionConstants.AUTH_CANCEL_X_REQUEST_ID); + consentAttributesMap.put(xRequestIdKey, consentManageData.getHeaders() + .get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); + String createdTimeKey = CommonConsentUtil.constructAttributeKey( + consentManageData.getRequestPath(), ConsentExtensionConstants.AUTH_CANCEL_CREATED_TIME); + consentAttributesMap.put(createdTimeKey, String.valueOf(OffsetDateTime.now().toEpochSecond())); } else { - consentAttributesMap.put(ConsentExtensionConstants.EXPLICIT_AUTH_X_REQUEST_ID, - consentManageData.getHeaders().get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); - consentAttributesMap.put(ConsentExtensionConstants.EXPLICIT_AUTH_CREATED_TIME, - String.valueOf(OffsetDateTime.now().toEpochSecond())); + String xRequestIdKey = CommonConsentUtil.constructAttributeKey( + consentManageData.getRequestPath(), ConsentExtensionConstants.EXPLICIT_AUTH_X_REQUEST_ID); + consentAttributesMap.put(xRequestIdKey, consentManageData.getHeaders() + .get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); + String createdTimeKey = CommonConsentUtil.constructAttributeKey( + consentManageData.getRequestPath(), ConsentExtensionConstants.EXPLICIT_AUTH_CREATED_TIME); + consentAttributesMap.put(createdTimeKey, String.valueOf(OffsetDateTime.now().toEpochSecond())); } return consentAttributesMap; diff --git a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/FundsConfirmationInitiationRequestHandler.java b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/FundsConfirmationInitiationRequestHandler.java index a2fda5e5..c85bcdd4 100644 --- a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/FundsConfirmationInitiationRequestHandler.java +++ b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/FundsConfirmationInitiationRequestHandler.java @@ -172,8 +172,8 @@ protected Map getConsentAttributesToPersist(ConsentManageData co consentAttributesMap.put(ConsentExtensionConstants.TPP_EXPLICIT_AUTH_PREFERRED_HEADER, headersMap.get(ConsentExtensionConstants.TPP_EXPLICIT_AUTH_PREFERRED_HEADER)); } - consentAttributesMap.put(ConsentExtensionConstants.X_REQUEST_ID, - headersMap.get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); + consentAttributesMap.put(CommonConsentUtil.constructAttributeKey(consentManageData.getRequestPath(), + ConsentExtensionConstants.X_REQUEST_ID), headersMap.get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); return consentAttributesMap; } diff --git a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/PaymentInitiationRequestHandler.java b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/PaymentInitiationRequestHandler.java index 28775291..0afbaf42 100644 --- a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/PaymentInitiationRequestHandler.java +++ b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/handler/request/impl/PaymentInitiationRequestHandler.java @@ -177,8 +177,8 @@ protected Map getConsentAttributesToPersist(ConsentManageData co consentAttributesMap.put(ConsentExtensionConstants.PAYMENT_SERVICE, paymentService); consentAttributesMap.put(ConsentExtensionConstants.PAYMENT_PRODUCT, paymentProduct); - consentAttributesMap.put(ConsentExtensionConstants.X_REQUEST_ID, - headersMap.get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); + consentAttributesMap.put(CommonConsentUtil.constructAttributeKey(consentManageData.getRequestPath(), + ConsentExtensionConstants.X_REQUEST_ID), headersMap.get(ConsentExtensionConstants.X_REQUEST_ID_HEADER)); if (!isExplicitAuth) { CommonConsentUtil.storeInitiationScaInfoToConsentAttributes(consentAttributesMap, createdConsent, diff --git a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/util/BerlinIdempotencyValidator.java b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/util/BerlinIdempotencyValidator.java index dbf22f74..82a6323b 100644 --- a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/util/BerlinIdempotencyValidator.java +++ b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/util/BerlinIdempotencyValidator.java @@ -39,11 +39,13 @@ public String getIdempotencyAttributeName(String resourcePath) { String path = ConsentExtensionUtil.getServiceDifferentiatingRequestPath(resourcePath); switch (path) { case ConsentExtensionConstants.EXPLICIT_AUTHORISATION_PATH_END: - return ConsentExtensionConstants.EXPLICIT_AUTH_X_REQUEST_ID; + return CommonConsentUtil.constructAttributeKey(resourcePath, + ConsentExtensionConstants.EXPLICIT_AUTH_X_REQUEST_ID); case ConsentExtensionConstants.PAYMENT_EXPLICIT_CANCELLATION_AUTHORISATION_PATH_END: - return ConsentExtensionConstants.AUTH_CANCEL_X_REQUEST_ID; + return CommonConsentUtil.constructAttributeKey(resourcePath, + ConsentExtensionConstants.AUTH_CANCEL_X_REQUEST_ID); default: - return ConsentExtensionConstants.X_REQUEST_ID; + return CommonConsentUtil.constructAttributeKey(resourcePath, ConsentExtensionConstants.X_REQUEST_ID); } } @@ -74,14 +76,14 @@ public long getCreatedTimeOfPreviousRequest(String resourcePath, String consentI } String path = ConsentExtensionUtil.getServiceDifferentiatingRequestPath(resourcePath); - if (ConsentExtensionConstants.PAYMENT_EXPLICIT_CANCELLATION_AUTHORISATION_PATH_END.equals(path) && - isPresentAsConsentAttribute(consentRequest, ConsentExtensionConstants.AUTH_CANCEL_CREATED_TIME)) { - return getCreatedTimeFromConsentAttributes(consentRequest, + if (ConsentExtensionConstants.PAYMENT_EXPLICIT_CANCELLATION_AUTHORISATION_PATH_END.equals(path)) { + String attributeKey = CommonConsentUtil.constructAttributeKey(resourcePath, ConsentExtensionConstants.AUTH_CANCEL_CREATED_TIME); - } else if (ConsentExtensionConstants.EXPLICIT_AUTHORISATION_PATH_END.equals(path) && - isPresentAsConsentAttribute(consentRequest, ConsentExtensionConstants.EXPLICIT_AUTH_CREATED_TIME)) { - return getCreatedTimeFromConsentAttributes(consentRequest, + return getCreatedTimeFromConsentAttributes(consentRequest, attributeKey); + } else if (ConsentExtensionConstants.EXPLICIT_AUTHORISATION_PATH_END.equals(path)) { + String attributeKey = CommonConsentUtil.constructAttributeKey(resourcePath, ConsentExtensionConstants.EXPLICIT_AUTH_CREATED_TIME); + return getCreatedTimeFromConsentAttributes(consentRequest, attributeKey); } else { return consentRequest.getCreatedTime(); } @@ -132,10 +134,10 @@ private boolean isPresentAsConsentAttribute(DetailedConsentResource consentReque * @return created time. */ private long getCreatedTimeFromConsentAttributes(DetailedConsentResource consentRequest, String key) { - if (consentRequest.getConsentAttributes() == null || !consentRequest.getConsentAttributes().containsKey(key)) { - return 0L; + if (isPresentAsConsentAttribute(consentRequest, key)) { + return Long.parseLong(consentRequest.getConsentAttributes().get(key)); } - return Long.parseLong(consentRequest.getConsentAttributes().get(key)); + return 0L; } /** diff --git a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/util/CommonConsentUtil.java b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/util/CommonConsentUtil.java index 898acc7c..451e8bbf 100644 --- a/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/util/CommonConsentUtil.java +++ b/components/com.wso2.openbanking.berlin.consent.extensions/src/main/java/com/wso2/openbanking/berlin/consent/extensions/manage/util/CommonConsentUtil.java @@ -26,6 +26,7 @@ import com.wso2.openbanking.berlin.common.models.TPPMessage; import com.wso2.openbanking.berlin.common.utils.CommonUtil; import com.wso2.openbanking.berlin.common.utils.ErrorUtil; +import com.wso2.openbanking.berlin.consent.extensions.common.AuthTypeEnum; import com.wso2.openbanking.berlin.consent.extensions.common.ConsentExtensionConstants; import com.wso2.openbanking.berlin.consent.extensions.common.ConsentExtensionUtil; import com.wso2.openbanking.berlin.consent.extensions.common.HeaderValidator; @@ -283,6 +284,7 @@ public static boolean isIdempotent(ConsentManageData consentManageData) { IdempotencyValidationResult result = idempotencyValidator.validateIdempotency(consentManageData); if (result.isIdempotent()) { if (result.isValid()) { + log.debug("Idempotent request. Returning the previous response."); appendResponsePayload(consentManageData, result.getConsent()); return true; } else { @@ -341,8 +343,8 @@ private static void appendResponsePayload(ConsentManageData consentManageData, D case ConsentExtensionConstants.PAYMENT_EXPLICIT_CANCELLATION_AUTHORISATION_PATH_END: consentManageData.setResponsePayload(CommonConsentUtil .constructStartAuthorisationResponse(consentManageData, - consent.getAuthorizationResources().get(0), true, apiVersion, - isSCARequired)); + getCancelAuthResource(consent.getAuthorizationResources()), true, + apiVersion, isSCARequired)); consentManageData.setResponseStatus(ResponseStatus.CREATED); break; default: @@ -351,6 +353,31 @@ private static void appendResponsePayload(ConsentManageData consentManageData, D } + /** + * Method to construct the attribute key to store parameters as a consent attribute. It will be constructed as + * requestPath_param. + * @param requestPath Request path + * @param param Parameter name + * @return constructed attribute key + */ + public static String constructAttributeKey(String requestPath, String param) { + return StringUtils.join(requestPath, "_", param); + } + + /** + * Method to filter the authorizations based on the cancellation authorization type. + * @param authResources List of authorization resources + * @return List of authorization resources filtered based on the cancellation authorization type + */ + private static AuthorizationResource getCancelAuthResource(ArrayList authResources) { + for (AuthorizationResource authResource : authResources) { + if (StringUtils.equals(AuthTypeEnum.CANCELLATION.toString(), authResource.getAuthorizationType())) { + return authResource; + } + } + return authResources.get(0); + } + @Generated(message = "Excluded from coverage since this is used for testing purposes") public static IdempotencyValidator getIdempotencyValidator() { diff --git a/toolkits/ob-apim/repository/resources/wso2am-4.0.0-deployment-berlin.toml b/toolkits/ob-apim/repository/resources/wso2am-4.0.0-deployment-berlin.toml index e5bf0449..fcb22051 100644 --- a/toolkits/ob-apim/repository/resources/wso2am-4.0.0-deployment-berlin.toml +++ b/toolkits/ob-apim/repository/resources/wso2am-4.0.0-deployment-berlin.toml @@ -53,7 +53,7 @@ validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" validationInterval="30000" -defaultAutoCommit=false +defaultAutoCommit=true # for api manager data [database.apim_db] @@ -71,7 +71,7 @@ validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" validationInterval="30000" -defaultAutoCommit=false +defaultAutoCommit=true # for am-config registry [database.config] @@ -89,7 +89,7 @@ validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" validationInterval="30000" -defaultAutoCommit=false +defaultAutoCommit=true # for user management data [[datasource]] @@ -107,7 +107,7 @@ pool_options.validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" pool_options.validationInterval="30000" -pool_options.defaultAutoCommit=false +pool_options.defaultAutoCommit=true # for Open Banking data [[datasource]] @@ -125,7 +125,7 @@ pool_options.validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" pool_options.validationInterval="30000" -pool_options.defaultAutoCommit=false +pool_options.defaultAutoCommit=true [tenant_mgt] enable_email_domain = true diff --git a/toolkits/ob-is/repository/resources/wso2is-5.11.0-deployment-berlin.toml b/toolkits/ob-is/repository/resources/wso2is-5.11.0-deployment-berlin.toml index c681e46a..fcc1635e 100644 --- a/toolkits/ob-is/repository/resources/wso2is-5.11.0-deployment-berlin.toml +++ b/toolkits/ob-is/repository/resources/wso2is-5.11.0-deployment-berlin.toml @@ -63,7 +63,7 @@ validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" validationInterval="30000" -defaultAutoCommit=false +defaultAutoCommit=true # for api manager data [database.identity_db] @@ -81,7 +81,7 @@ validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" validationInterval="30000" -defaultAutoCommit=false +defaultAutoCommit=true # for km-config registry [database.config] @@ -99,7 +99,7 @@ validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" validationInterval="30000" -defaultAutoCommit=false +defaultAutoCommit=true # for user-mgt data [database.user] @@ -117,7 +117,7 @@ validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" validationInterval="30000" -defaultAutoCommit=false +defaultAutoCommit=true # for Open Banking data [[datasource]] @@ -135,7 +135,7 @@ pool_options.validationQuery="SELECT 1" #Use below for oracle #validationQuery="SELECT 1 FROM DUAL" pool_options.validationInterval="30000" -pool_options.defaultAutoCommit=false +pool_options.defaultAutoCommit=true #================configs related to application-authentication.xml=============