Skip to content

Commit

Permalink
[INJIMOB-1078] add support for wellknown response of mso_mdoc VC form…
Browse files Browse the repository at this point in the history
…at (#410)

* [INJIMOB-1078] add support for wellknown response of mso_mdoc VC format

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-1078] use builtin functions for performing equality check and map iteration

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-1078] use builtin functions for performing equality check and map iteration

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-1078] restructure test in CredentialIssuerWellknownResponseValidatorTest

Signed-off-by: KiruthikaJeyashankar <[email protected]>

* [INJIMOB-1078] refcator accessing of data

Signed-off-by: KiruthikaJeyashankar <[email protected]>

---------

Signed-off-by: KiruthikaJeyashankar <[email protected]>
  • Loading branch information
KiruthikaJeyashankar committed Sep 4, 2024
1 parent 0d13864 commit 38a07d9
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package io.mosip.mimoto.dto.mimoto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.List;
import java.util.Map;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

@Data
public class CredentialsSupportedResponse {

Expand All @@ -20,16 +22,21 @@ public class CredentialsSupportedResponse {
@NotBlank(message = "Scope must not be blank")
private String scope;

@JsonInclude(NON_NULL)
private String doctype;

@NotEmpty(message = "Proof types supported must not be empty")
@Valid
@SerializedName("proof_types_supported")
@JsonProperty("proof_types_supported")
private Map<@NotEmpty String, @Valid ProofTypesSupported> proofTypesSupported;

@Valid
@NotNull
@JsonInclude(NON_NULL)
private Map<String, Object> claims;

@SerializedName("credential_definition")
@JsonProperty("credential_definition")
@JsonInclude(NON_NULL)
private CredentialDefinitionResponseDto credentialDefinition;

@NotEmpty(message = "Display information must not be empty")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.annotations.SerializedName;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import javax.validation.constraints.NotEmpty;
import java.util.List;

@Data
public class ProofTypesSupported {

@NotEmpty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package io.mosip.mimoto.util;

import io.mosip.mimoto.dto.mimoto.CredentialDefinitionResponseDto;
import io.mosip.mimoto.dto.mimoto.CredentialIssuerWellKnownResponse;
import io.mosip.mimoto.dto.mimoto.CredentialsSupportedResponse;
import io.mosip.mimoto.exception.ApiNotAccessibleException;
import io.mosip.mimoto.exception.InvalidWellknownResponseException;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.Set;

public class CredentialIssuerWellknownResponseValidator {
public void validate(CredentialIssuerWellKnownResponse response, Validator validator) throws ApiNotAccessibleException, InvalidWellknownResponseException {
Set<ConstraintViolation<CredentialIssuerWellKnownResponse>> violations = validator.validate(response);
Expand All @@ -17,5 +22,31 @@ public void validate(CredentialIssuerWellKnownResponse response, Validator valid
}
throw new InvalidWellknownResponseException(sb.toString());
}

for (CredentialsSupportedResponse supportedCredentialConfiguration : response.getCredentialConfigurationsSupported().values()) {
//TODO: Extract the vc specific validations to separate classes
if (supportedCredentialConfiguration.getFormat().equals("mso_mdoc")) {
if (StringUtils.isBlank(supportedCredentialConfiguration.getDoctype())) {
throw new InvalidWellknownResponseException("Mandatory field 'doctype' missing");
}
if (CollectionUtils.isEmpty(supportedCredentialConfiguration.getClaims())) {
throw new InvalidWellknownResponseException("Mandatory field 'claims' missing");
}
}

if (supportedCredentialConfiguration.getFormat().equals("ldp_vc")) {
if (supportedCredentialConfiguration.getCredentialDefinition() == null) {
throw new InvalidWellknownResponseException("credentialDefinition: must not be null");
}
Set<ConstraintViolation<CredentialDefinitionResponseDto>> credentialDefinitionViolations = validator.validate(supportedCredentialConfiguration.getCredentialDefinition());
if (!credentialDefinitionViolations.isEmpty()) {
StringBuilder sb = new StringBuilder("Validation failed:");
for (ConstraintViolation<CredentialDefinitionResponseDto> violation : credentialDefinitionViolations) {
sb.append("\n").append(violation.getPropertyPath()).append(": ").append(violation.getMessage());
}
throw new InvalidWellknownResponseException(sb.toString());
}
}
}
}
}
Loading

0 comments on commit 38a07d9

Please sign in to comment.