diff --git a/app/src/main/java/eu/_5gzorro/manager/api/controller/AgreementController.java b/app/src/main/java/eu/_5gzorro/manager/api/controller/AgreementController.java index 8095fbd..84d4ea3 100644 --- a/app/src/main/java/eu/_5gzorro/manager/api/controller/AgreementController.java +++ b/app/src/main/java/eu/_5gzorro/manager/api/controller/AgreementController.java @@ -65,7 +65,7 @@ public interface AgreementController { @ApiResponse(responseCode = "404", description = "An Agreement couldn't be found with the provided ID", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ApiErrorResponse.class))) }) - @PutMapping("{id}/identity") + @PostMapping("{id}/identity") ResponseEntity updateTemplateIdentity(@PathVariable final UUID id, @Valid @RequestBody final DIDStateDto state) throws JsonProcessingException; diff --git a/app/src/main/java/eu/_5gzorro/manager/api/controller/AgreementControllerImpl.java b/app/src/main/java/eu/_5gzorro/manager/api/controller/AgreementControllerImpl.java index 3529bc2..0851082 100644 --- a/app/src/main/java/eu/_5gzorro/manager/api/controller/AgreementControllerImpl.java +++ b/app/src/main/java/eu/_5gzorro/manager/api/controller/AgreementControllerImpl.java @@ -54,7 +54,14 @@ public ResponseEntity createAgreement(Agreement agreement) throws JsonProc @Override public ResponseEntity updateTemplateIdentity(UUID id, DIDStateDto state) throws JsonProcessingException { - agreementService.completeAgreementCreation(id, state.getDid()); + + String did = state.getCredentialOffer().getCredentialPreview().getDid(); + + if(did == null) + return ResponseEntity.badRequest().build(); + + agreementService.completeAgreementCreation(id, did); + return ResponseEntity.ok().build(); } diff --git a/app/src/main/java/eu/_5gzorro/manager/api/controller/ServiceLevelAgreementController.java b/app/src/main/java/eu/_5gzorro/manager/api/controller/ServiceLevelAgreementController.java index 6a55ab7..5233159 100644 --- a/app/src/main/java/eu/_5gzorro/manager/api/controller/ServiceLevelAgreementController.java +++ b/app/src/main/java/eu/_5gzorro/manager/api/controller/ServiceLevelAgreementController.java @@ -65,7 +65,7 @@ public interface ServiceLevelAgreementController { @ApiResponse(responseCode = "404", description = "An SLA couldn't be found with the provided ID", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ApiErrorResponse.class))) }) - @PutMapping("{slaId}/identity") + @PostMapping("{slaId}/identity") ResponseEntity updateTemplateIdentity(@PathVariable final UUID slaId, @Valid @RequestBody final DIDStateDto state) throws JsonProcessingException; diff --git a/app/src/main/java/eu/_5gzorro/manager/api/controller/ServiceLevelAgreementControllerImpl.java b/app/src/main/java/eu/_5gzorro/manager/api/controller/ServiceLevelAgreementControllerImpl.java index 7f90338..c6ef5d4 100644 --- a/app/src/main/java/eu/_5gzorro/manager/api/controller/ServiceLevelAgreementControllerImpl.java +++ b/app/src/main/java/eu/_5gzorro/manager/api/controller/ServiceLevelAgreementControllerImpl.java @@ -1,6 +1,9 @@ package eu._5gzorro.manager.api.controller; import com.fasterxml.jackson.core.JsonProcessingException; +import eu._5gzorro.manager.api.dto.identityPermisssions.CredentialAttributeDto; +import eu._5gzorro.manager.api.dto.identityPermisssions.CredentialPreviewDto; +import eu._5gzorro.manager.api.dto.identityPermisssions.CredentialSubjectDto; import eu._5gzorro.manager.api.dto.identityPermisssions.DIDStateDto; import eu._5gzorro.manager.api.dto.responses.PagedSlaResponse; import eu._5gzorro.manager.api.service.ServiceLevelAgreementService; @@ -11,6 +14,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; +import java.util.List; import java.util.UUID; @RestController @@ -54,7 +58,13 @@ public ResponseEntity createServiceLevelAgreement(ServiceLevelAgreement sl @Override public ResponseEntity updateTemplateIdentity(UUID slaId, DIDStateDto state) throws JsonProcessingException { - slaService.completeSLACreation(slaId, state.getDid()); + + String did = state.getCredentialOffer().getCredentialPreview().getDid(); + + if(did == null) + return ResponseEntity.badRequest().build(); + + slaService.completeSLACreation(slaId, did); return ResponseEntity.ok().build(); } diff --git a/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialAttributeDto.java b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialAttributeDto.java new file mode 100644 index 0000000..dc75d15 --- /dev/null +++ b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialAttributeDto.java @@ -0,0 +1,48 @@ +package eu._5gzorro.manager.api.dto.identityPermisssions; + +import java.util.Objects; + +public class CredentialAttributeDto { + private String name; + private String value; + + public CredentialAttributeDto() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CredentialAttributeDto that = (CredentialAttributeDto) o; + return Objects.equals(name, that.name) && Objects.equals(value, that.value); + } + + @Override + public int hashCode() { + return Objects.hash(name, value); + } + + @Override + public String toString() { + return "CredentialAttributeDto{" + + "name='" + name + '\'' + + ", value='" + value + '\'' + + '}'; + } +} diff --git a/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialOfferDto.java b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialOfferDto.java new file mode 100644 index 0000000..0df2cf4 --- /dev/null +++ b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialOfferDto.java @@ -0,0 +1,41 @@ +package eu._5gzorro.manager.api.dto.identityPermisssions; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +public class CredentialOfferDto { + @JsonProperty("credential_preview") + private CredentialPreviewDto credentialPreview; + + public CredentialOfferDto() { + } + + public CredentialPreviewDto getCredentialPreview() { + return credentialPreview; + } + + public void setCredentialPreview(CredentialPreviewDto credentialPreview) { + this.credentialPreview = credentialPreview; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CredentialOfferDto that = (CredentialOfferDto) o; + return Objects.equals(credentialPreview, that.credentialPreview); + } + + @Override + public int hashCode() { + return Objects.hash(credentialPreview); + } + + @Override + public String toString() { + return "CredentialOfferDto{" + + "credentialPreview=" + credentialPreview + + '}'; + } +} diff --git a/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialPreviewDto.java b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialPreviewDto.java new file mode 100644 index 0000000..cf8a667 --- /dev/null +++ b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialPreviewDto.java @@ -0,0 +1,60 @@ +package eu._5gzorro.manager.api.dto.identityPermisssions; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.lang3.tuple.Pair; + +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class CredentialPreviewDto { + private List attributes; + + public CredentialPreviewDto() { + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + + public String getDid() { + try { + CredentialAttributeDto attr = attributes.stream().filter(a -> a.getName().equals("credentialSubject")).findFirst().get(); + + String valToDeserialise = attr.getValue().replace("'", "\""); + ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + CredentialSubjectDto subject = mapper.readValue(valToDeserialise, CredentialSubjectDto.class); + return subject.getId(); + } + catch(Exception e) + { + return null; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CredentialPreviewDto that = (CredentialPreviewDto) o; + return Objects.equals(attributes, that.attributes); + } + + @Override + public int hashCode() { + return Objects.hash(attributes); + } + + @Override + public String toString() { + return "CredentialPreviewDto{" + + "attributes=" + attributes + + '}'; + } +} diff --git a/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialSubjectDto.java b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialSubjectDto.java new file mode 100644 index 0000000..4939cd1 --- /dev/null +++ b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/CredentialSubjectDto.java @@ -0,0 +1,39 @@ +package eu._5gzorro.manager.api.dto.identityPermisssions; + +import java.util.Objects; + + +public class CredentialSubjectDto { + private String id; + + public CredentialSubjectDto() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CredentialSubjectDto that = (CredentialSubjectDto) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + @Override + public String toString() { + return "CredentialSubjectDto{" + + "id='" + id + '\'' + + '}'; + } +} diff --git a/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/DIDStateDto.java b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/DIDStateDto.java index 2037118..b0e3d8e 100644 --- a/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/DIDStateDto.java +++ b/app/src/main/java/eu/_5gzorro/manager/api/dto/identityPermisssions/DIDStateDto.java @@ -1,38 +1,76 @@ package eu._5gzorro.manager.api.dto.identityPermisssions; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.Objects; public class DIDStateDto { - private String did; -// private DIDStateEnum state; + @JsonProperty("credential_exchange_id") + private String credentialExchangeId; + + @JsonProperty("credential_offer_dict") + private CredentialOfferDto credentialOffer; + + @JsonProperty("created_at") + private String createdAt; + + @JsonProperty("updated_at") + private String updatedAt; + + @JsonProperty("schema_id") + private String schemaId; + private String state; public DIDStateDto() { } - public String getDid() { - return did; + public String getState() { + return state; } - public void setDid(String did) { - this.did = did; + public void setState(String state) { + this.state = state; } -// public DIDStateEnum getState() { -// return state; -// } -// -// public void setState(DIDStateEnum state) { -// this.state = state; -// } + public String getCredentialExchangeId() { + return credentialExchangeId; + } + public void setCredentialExchangeId(String credentialExchangeId) { + this.credentialExchangeId = credentialExchangeId; + } - public String getState() { - return state; + public CredentialOfferDto getCredentialOffer() { + return credentialOffer; } - public void setState(String state) { - this.state = state; + public void setCredentialOffer(CredentialOfferDto credentialOffer) { + this.credentialOffer = credentialOffer; + } + + public String getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + public String getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + public String getSchemaId() { + return schemaId; + } + + public void setSchemaId(String schemaId) { + this.schemaId = schemaId; } @Override @@ -40,19 +78,23 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; DIDStateDto that = (DIDStateDto) o; - return did.equals(that.did) && state == that.state; + return credentialExchangeId.equals(that.credentialExchangeId); } @Override public int hashCode() { - return Objects.hash(did, state); + return Objects.hash(credentialExchangeId); } @Override public String toString() { return "DIDStateDto{" + - "did='" + did + '\'' + - ", state=" + state + + "credentialExchangeId='" + credentialExchangeId + '\'' + + ", credentialOffer=" + credentialOffer + + ", createdAt='" + createdAt + '\'' + + ", updatedAt='" + updatedAt + '\'' + + ", schemaId='" + schemaId + '\'' + + ", state='" + state + '\'' + '}'; } }