Skip to content

Commit

Permalink
[INJIVER-846] - refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Sreenadh S <[email protected]>
  • Loading branch information
sree96 committed Jan 5, 2025
1 parent 66fe990 commit 0722960
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(path = "/vp-submission")
@RequestMapping(path = Constants.RESPONSE_SUBMISSION_URI_ROOT)
@Slf4j
public class VPSubmissionController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.inji.verify.dto.authorizationrequest;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.inji.verify.dto.presentation.VPDefinitionResponseDto;
import io.inji.verify.models.PresentationDefinition;
import io.inji.verify.shared.Constants;
import lombok.AllArgsConstructor;
Expand All @@ -16,10 +17,10 @@
public class AuthorizationRequestResponseDto {

private final String responseType = Constants.RESPONSE_TYPE;
private final String responseUri = Constants.RESPONSE_SUBMISSION_URI;
private final String responseUri = Constants.RESPONSE_SUBMISSION_URI_ROOT+Constants.RESPONSE_SUBMISSION_URI;
private final long issuedAt = Instant.now().toEpochMilli();
private final String clientId;
private final String presentationDefinitionUri;
private final PresentationDefinition presentationDefinition;
private final VPDefinitionResponseDto presentationDefinition;
private final String nonce;
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
package io.inji.verify.repository;

import io.inji.verify.models.AuthorizationRequestCreateResponse;
import io.inji.verify.shared.Constants;
import org.jetbrains.annotations.NotNull;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface AuthorizationRequestCreateResponseRepository extends JpaRepository<AuthorizationRequestCreateResponse, String> {
@Cacheable(cacheNames = Constants.CACHE_NAME, key = "#transactionId")
List<AuthorizationRequestCreateResponse> findAllByTransactionIdOrderByExpiresAtDesc(@NotNull String transactionId);

@NotNull
@Override
@Cacheable(value = Constants.CACHE_NAME, key = "requestId")
Optional<AuthorizationRequestCreateResponse> findById(@NotNull String requestId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ public VPRequestResponseDto createAuthorizationRequest(VPRequestCreateDto vpRequ
String requestId = Utils.generateID(Constants.REQUEST_ID_PREFIX);
long expiresAt = Instant.now().plusSeconds(Constants.DEFAULT_EXPIRY).toEpochMilli();
String nonce = vpRequestCreate.getNonce() != null ? vpRequestCreate.getNonce() : SecurityUtils.generateNonce();
PresentationDefinition presentationDefinition;
AuthorizationRequestResponseDto authorizationRequestResponseDto;
if (vpRequestCreate.getPresentationDefinitionId() != null) {
presentationDefinition = presentationDefinitionRepository.findById(vpRequestCreate.getPresentationDefinitionId()).orElse(null);
PresentationDefinition presentationDefinition = presentationDefinitionRepository.findById(vpRequestCreate.getPresentationDefinitionId()).orElse(null);
if (presentationDefinition == null) {
//todo :: is this what u have to do?
//Todo:: Examples of PD
return null;
}
authorizationRequestResponseDto = new AuthorizationRequestResponseDto(vpRequestCreate.getClientId(), presentationDefinition.getURL(), presentationDefinition, nonce);

VPDefinitionResponseDto vpDefinitionResponseDto = new VPDefinitionResponseDto(presentationDefinition.getId(),presentationDefinition.getInputDescriptors(),presentationDefinition.getSubmissionRequirements());
authorizationRequestResponseDto = new AuthorizationRequestResponseDto(vpRequestCreate.getClientId(), presentationDefinition.getURL(), vpDefinitionResponseDto, nonce);

} else {
VPDefinitionResponseDto VPDefinitionResponseDto = vpRequestCreate.getPresentationDefinition();
presentationDefinition = new PresentationDefinition(VPDefinitionResponseDto.getId(), VPDefinitionResponseDto.getInputDescriptors(), VPDefinitionResponseDto.getSubmissionRequirements());
authorizationRequestResponseDto = new AuthorizationRequestResponseDto(vpRequestCreate.getClientId(), null, presentationDefinition, nonce);
VPDefinitionResponseDto vpDefinitionResponseDto = vpRequestCreate.getPresentationDefinition();
authorizationRequestResponseDto = new AuthorizationRequestResponseDto(vpRequestCreate.getClientId(), null, vpDefinitionResponseDto, nonce);
}

AuthorizationRequestCreateResponse authorizationRequestCreateResponse = new AuthorizationRequestCreateResponse(requestId, transactionId, authorizationRequestResponseDto, expiresAt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ public VPTokenResultDto getVPResult(List<String> requestIds, String transactionI
private List<VCResult> getVCVerificationResults(JSONArray verifiableCredentials) {
List<VCResult> verificationResults = new ArrayList<>();
for (Object verifiableCredential : verifiableCredentials) {
JSONObject credential = new JSONObject((String) verifiableCredential).getJSONObject(Constants.KEY_VERIFIABLE_CREDENTIAL).getJSONObject(Constants.KEY_CREDENTIAL);
JSONObject fullVerifiableCredential = new JSONObject((String) verifiableCredential).getJSONObject(Constants.KEY_VERIFIABLE_CREDENTIAL);
JSONObject credential = fullVerifiableCredential.getJSONObject(Constants.KEY_CREDENTIAL);
VerificationResult verificationResult = credentialsVerifier.verify(credential.toString(), CredentialFormat.LDP_VC);
VerificationStatus singleVCVerification = Utils.getVerificationStatus(verificationResult);
verificationResults.add(new VCResult(credential.toString(),singleVCVerification));
verificationResults.add(new VCResult(fullVerifiableCredential.toString(),singleVCVerification));
}
return verificationResults;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class Constants {

public static final String CACHE_NAME = "auth-request-cache";
public static int DEFAULT_EXPIRY = 300;
public static final String RESPONSE_SUBMISSION_URI_ROOT = "/vp-submission";
public static final String RESPONSE_SUBMISSION_URI = "/direct-post";
public static final String VP_DEFINITION_URI = "/vp-definition/";
public static final String RESPONSE_TYPE = "vp_token";
Expand Down

0 comments on commit 0722960

Please sign in to comment.