Skip to content

Commit

Permalink
Merge pull request #14 from finarkein/feature/VAPT-issue-4---UUID-for…
Browse files Browse the repository at this point in the history
…mat-validation

Feature/VAPT issue- UUID format validation
  • Loading branch information
dheerajkhardwal authored Oct 15, 2021
2 parents 354467b + f82ca8b commit 90b9cf8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,9 +84,8 @@ public ResponseEntity<Mono<NotificationResponse>> 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)
Expand Down Expand Up @@ -129,10 +129,8 @@ public ResponseEntity<Mono<NotificationResponse>> 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<FIRequestState> optionalFIRequestState = dataFlowService.getFIRequestStateByTxnId(fiNotification.getTxnid());
if (optionalFIRequestState.isPresent()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<version.spring-webflux>5.3.8</version.spring-webflux>
<version.maven-dependency-plugin>3.1.1</version.maven-dependency-plugin>
<version.logger>2.14.0</version.logger>
<version.aa-commons>0.4.0</version.aa-commons>
<version.aa-commons>0.4.1</version.aa-commons>

<version.maven-compiler>3.8.1</version.maven-compiler>
<version.plugin-deploy>3.0.0-M1</version.plugin-deploy>
Expand Down

0 comments on commit 90b9cf8

Please sign in to comment.