Skip to content

Commit

Permalink
feat(did issuance): update to new dtos for DID issuance & PUT -> POST
Browse files Browse the repository at this point in the history
  • Loading branch information
James Taylor committed Jun 8, 2021
1 parent 1531588 commit 3abd5a4
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> updateTemplateIdentity(@PathVariable final UUID id, @Valid @RequestBody final DIDStateDto state) throws JsonProcessingException;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ public ResponseEntity<UUID> createAgreement(Agreement agreement) throws JsonProc

@Override
public ResponseEntity<Void> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void> updateTemplateIdentity(@PathVariable final UUID slaId, @Valid @RequestBody final DIDStateDto state) throws JsonProcessingException;


Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -54,7 +58,13 @@ public ResponseEntity<UUID> createServiceLevelAgreement(ServiceLevelAgreement sl

@Override
public ResponseEntity<Void> 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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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<CredentialAttributeDto> attributes;

public CredentialPreviewDto() {
}

public List<CredentialAttributeDto> getAttributes() {
return attributes;
}

public void setAttributes(List<CredentialAttributeDto> 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 +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,58 +1,100 @@
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
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 + '\'' +
'}';
}
}

0 comments on commit 3abd5a4

Please sign in to comment.