Skip to content

Commit

Permalink
[INJIVER-587] - remove thread
Browse files Browse the repository at this point in the history
Signed-off-by: Sreenadh S <[email protected]>
  • Loading branch information
sree96 committed Dec 20, 2024
1 parent fb2f8d1 commit ca0ae6c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,6 +32,4 @@ public class VPSubmission {
@Column(columnDefinition = "json")
@JdbcTypeCode(SqlTypes.JSON)
PresentationSubmissionDto presentationSubmission;

SubmissionStatus submissionStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,54 +44,45 @@ 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<VCResult> 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<VCResult> 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);
}
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<VCResult> vcVerificationResults = getVCVerificationResults(verifiableCredentials);
return new VPTokenResultDto(transactionId,SubmissionStatus.SUCCESS,vcVerificationResults);
return processSubmission(vpSubmission,transactionId);
}

private List<VCResult> getVCVerificationResults(JSONArray verifiableCredentials) {
Expand Down

0 comments on commit ca0ae6c

Please sign in to comment.