From f82ca8be59631b1ec2c454e09b52de6263481181 Mon Sep 17 00:00:00 2001 From: Prathamesh Mungarwadi Date: Fri, 15 Oct 2021 15:30:56 +0530 Subject: [PATCH] UUID format validator moved to aa-commons changed aa-commons version to 0.4.1 --- .../fiul/controller/NotificationController.java | 12 +++++------- .../fiul/validator/NotificationValidator.java | 14 +++----------- pom.xml | 2 +- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/fiul-rest/fiul-rest-notification/src/main/java/io/finarkein/fiul/controller/NotificationController.java b/fiul-rest/fiul-rest-notification/src/main/java/io/finarkein/fiul/controller/NotificationController.java index 4b060da2..ffd5572e 100644 --- a/fiul-rest/fiul-rest-notification/src/main/java/io/finarkein/fiul/controller/NotificationController.java +++ b/fiul-rest/fiul-rest-notification/src/main/java/io/finarkein/fiul/controller/NotificationController.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.finarkein.aa.registry.RegistryService; +import io.finarkein.aa.validators.ArgsValidator; import io.finarkein.api.aa.exception.Errors; import io.finarkein.api.aa.exception.SystemException; import io.finarkein.api.aa.notification.ConsentNotification; @@ -83,9 +84,8 @@ public ResponseEntity> consentResponseMono(@RequestBo return ResponseEntity.badRequest().body(Mono.just(NotificationResponse.invalidResponse(consentNotification.getTxnid(), Timestamp.from(Instant.now()), e.getMessage()))); } - if (!NotificationValidator.isValidUUID(consentNotification.getTxnid())) { - return ResponseEntity.badRequest().body(Mono.just(NotificationResponse.invalidResponse(consentNotification.getTxnid(), Timestamp.from(Instant.now()), "Invalid TxnId"))); - } + ArgsValidator.isValidUUID(consentNotification.getTxnid(), consentNotification.getTxnid(), "TxnId"); + ConsentState consentState = consentService.getConsentStateByTxnId(consentNotification.getTxnid()); if (consentState == null) @@ -129,10 +129,8 @@ public ResponseEntity> fiNotification(@RequestBody FI return ResponseEntity.badRequest().body(Mono.just(NotificationResponse.invalidResponse(fiNotification.getTxnid(), Timestamp.from(Instant.now()), e.getMessage()))); } - if (!NotificationValidator.isValidUUID(fiNotification.getTxnid())) { - return ResponseEntity.badRequest().body(Mono.just(NotificationResponse.invalidResponse(fiNotification.getTxnid(), - Timestamp.from(Instant.now()), "Invalid TxnId"))); - } + ArgsValidator.isValidUUID(fiNotification.getTxnid(), fiNotification.getTxnid(), "TxnId"); + Optional optionalFIRequestState = dataFlowService.getFIRequestStateByTxnId(fiNotification.getTxnid()); if (optionalFIRequestState.isPresent()) { try { diff --git a/fiul-rest/fiul-rest-notification/src/main/java/io/finarkein/fiul/validator/NotificationValidator.java b/fiul-rest/fiul-rest-notification/src/main/java/io/finarkein/fiul/validator/NotificationValidator.java index 3041a1ef..6aed6bf4 100644 --- a/fiul-rest/fiul-rest-notification/src/main/java/io/finarkein/fiul/validator/NotificationValidator.java +++ b/fiul-rest/fiul-rest-notification/src/main/java/io/finarkein/fiul/validator/NotificationValidator.java @@ -7,6 +7,7 @@ package io.finarkein.fiul.validator; import io.finarkein.aa.registry.models.EntityInfo; +import io.finarkein.aa.validators.ArgsValidator; import io.finarkein.aa.validators.BasicResponseValidator; import io.finarkein.api.aa.exception.Errors; import io.finarkein.api.aa.notification.ConsentNotification; @@ -23,15 +24,6 @@ public class NotificationValidator { private static final String REQUIRED_NOTIFIER_TYPE = "AA"; - private static final Pattern UUID_REGEX_PATTERN = - Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); - - public static boolean isValidUUID(String str) { - if (str == null || str.isEmpty()) { - return false; - } - return UUID_REGEX_PATTERN.matcher(str).matches(); - } public static void validateConsentNotification(ConsentNotification consentNotification, ConsentState consentState, EntityInfo entityInfo, boolean test, AaApiKeyBody aaApiKeyBody) { @@ -48,8 +40,8 @@ public static void validateConsentNotification(ConsentNotification consentNotifi if (!consentNotification.getNotifier().getType().equals(REQUIRED_NOTIFIER_TYPE)) { throw Errors.InvalidRequest.with(consentNotification.getTxnid(), "Invalid Notifier type"); } - if (!isValidUUID(consentNotification.getConsentStatusNotification().getConsentId())) - throw Errors.InvalidRequest.with(consentNotification.getTxnid(), "Consent Id is invalid"); + ArgsValidator.isValidUUID(consentNotification.getTxnid(), consentNotification.getConsentStatusNotification().getConsentId(), + "ConsentId"); if (!consentNotification.getConsentStatusNotification().getConsentHandle().equals(consentState.getConsentHandle())) throw Errors.InvalidRequest.with(consentNotification.getTxnid(), "ConsentHandle Id is invalid"); diff --git a/pom.xml b/pom.xml index 4d1bc815..1676b19d 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 5.3.8 3.1.1 2.14.0 - 0.4.0 + 0.4.1 3.8.1 3.0.0-M1