diff --git a/verify-service/src/main/java/io/inji/verify/enums/SubmissionStatus.java b/verify-service/src/main/java/io/inji/verify/enums/SubmissionStatus.java deleted file mode 100644 index 8bb867b2..00000000 --- a/verify-service/src/main/java/io/inji/verify/enums/SubmissionStatus.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.inji.verify.enums; - -public enum SubmissionStatus { - SUCCESS, - FAILED -} diff --git a/verify-service/src/main/java/io/inji/verify/models/VPSubmission.java b/verify-service/src/main/java/io/inji/verify/models/VPSubmission.java index c7c9e678..9c633ce5 100644 --- a/verify-service/src/main/java/io/inji/verify/models/VPSubmission.java +++ b/verify-service/src/main/java/io/inji/verify/models/VPSubmission.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.nimbusds.jose.shaded.gson.annotations.SerializedName; import io.inji.verify.dto.submission.PresentationSubmissionDto; -import io.inji.verify.enums.SubmissionStatus; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; @@ -33,6 +32,4 @@ public class VPSubmission { @Column(columnDefinition = "json") @JdbcTypeCode(SqlTypes.JSON) PresentationSubmissionDto presentationSubmission; - - SubmissionStatus submissionStatus; } diff --git a/verify-service/src/main/java/io/inji/verify/services/VerifiablePresentationSubmissionServiceImpl.java b/verify-service/src/main/java/io/inji/verify/services/VerifiablePresentationSubmissionServiceImpl.java index c6e27dca..3edb014d 100644 --- a/verify-service/src/main/java/io/inji/verify/services/VerifiablePresentationSubmissionServiceImpl.java +++ b/verify-service/src/main/java/io/inji/verify/services/VerifiablePresentationSubmissionServiceImpl.java @@ -44,26 +44,24 @@ public class VerifiablePresentationSubmissionServiceImpl implements VerifiablePr @Override public ResponseAcknowledgementDto submit(VPSubmissionDto vpSubmissionDto) { - new Thread(() -> { - processSubmission(vpSubmissionDto); - }).start(); + vpSubmissionRepository.save(new VPSubmission(vpSubmissionDto.getState(), vpSubmissionDto.getVpToken(), vpSubmissionDto.getPresentationSubmission())); return new ResponseAcknowledgementDto("", "", ""); } - private void processSubmission(VPSubmissionDto vpSubmissionDto) { - JSONObject vpProof = new JSONObject(vpSubmissionDto.getVpToken()).getJSONObject(Constants.KEY_PROOF); + private VPTokenResultDto processSubmission(VPSubmission vpSubmission, String transactionId) { + JSONObject vpProof = new JSONObject(vpSubmission.getVpToken()).getJSONObject(Constants.KEY_PROOF); String jws = vpProof.getString(Constants.KEY_JWS); String publicKeyPem = vpProof.getString(Constants.KEY_VERIFICATION_METHOD); - + List verificationResults = null; //TODO: Dynamic algo type try { Algorithm algorithm = Algorithm.RSA256(SecurityUtils.readX509PublicKey(publicKeyPem), null); JWTVerifier verifier = JWT.require(algorithm).build(); verifier.verify(jws); - JSONArray verifiableCredentials = new JSONObject(vpSubmissionDto.getVpToken()).getJSONArray(Constants.KEY_VERIFIABLE_CREDENTIAL); - List verificationResults = getVCVerificationResults(verifiableCredentials); + JSONArray verifiableCredentials = new JSONObject(vpSubmission.getVpToken()).getJSONArray(Constants.KEY_VERIFIABLE_CREDENTIAL); + verificationResults = getVCVerificationResults(verifiableCredentials); boolean combinedVerificationStatus = true; for (VCResult verificationResult : verificationResults) { combinedVerificationStatus = combinedVerificationStatus && (verificationResult.getVerificationStatus() == VerificationStatus.SUCCESS); @@ -71,27 +69,20 @@ private void processSubmission(VPSubmissionDto vpSubmissionDto) { if (!combinedVerificationStatus) { throw new VerificationFailedException(); } - vpSubmissionRepository.save(new VPSubmission(vpSubmissionDto.getState(), vpSubmissionDto.getVpToken(), vpSubmissionDto.getPresentationSubmission(), SubmissionStatus.SUCCESS)); + return new VPTokenResultDto(transactionId,SubmissionStatus.SUCCESS, verificationResults); } catch (Exception e) { log.error("Failed to verify",e); - vpSubmissionRepository.save(new VPSubmission(vpSubmissionDto.getState(), vpSubmissionDto.getVpToken(), vpSubmissionDto.getPresentationSubmission(), SubmissionStatus.FAILED)); + return new VPTokenResultDto(transactionId,SubmissionStatus.FAILED, verificationResults); } - - authorizationRequestCreateResponseRepository.findById(vpSubmissionDto.getState()).map(authorizationRequestCreateResponse -> { - authorizationRequestCreateResponseRepository.save(authorizationRequestCreateResponse); - return null; - }); } @Override public VPTokenResultDto getVPResult(String requestId, String transactionId) { - VPSubmission VPSubmissionResult = vpSubmissionRepository.findById(requestId).orElse(null); - if (VPSubmissionResult == null || VPSubmissionResult.getSubmissionStatus() == SubmissionStatus.FAILED){ - return new VPTokenResultDto(transactionId,SubmissionStatus.FAILED,null); + VPSubmission vpSubmission = vpSubmissionRepository.findById(requestId).orElse(null); + if (vpSubmission == null){ + return new VPTokenResultDto(transactionId,SubmissionStatus.NOT_SUBMITTED,null); } - JSONArray verifiableCredentials = new JSONObject(VPSubmissionResult.getVpToken()).getJSONArray(Constants.KEY_VERIFIABLE_CREDENTIAL); - List vcVerificationResults = getVCVerificationResults(verifiableCredentials); - return new VPTokenResultDto(transactionId,SubmissionStatus.SUCCESS,vcVerificationResults); + return processSubmission(vpSubmission,transactionId); } private List getVCVerificationResults(JSONArray verifiableCredentials) {