Skip to content

Commit

Permalink
Merge pull request #19 from WorldHealthOrganization/feature/universal…
Browse files Browse the repository at this point in the history
…-resolver-integration

feat: did trustlist parsing and storing
  • Loading branch information
ascheibal authored Mar 28, 2024
2 parents 8ced96d + 22ddd81 commit 8f34e17
Show file tree
Hide file tree
Showing 50 changed files with 1,485 additions and 928 deletions.
832 changes: 331 additions & 501 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import tng.trustnetwork.keydistribution.model.DidDocument;

@FeignClient(value = "universalresolver", url = "${universal.resolver}",
configuration = UniversalResolverClientConfig.class)
public interface UniversalResolverClient {

@GetMapping(value = "/{didKey}", produces = "application/json")
DidDocument getDidDocument(@PathVariable("didKey") String didKey);
String getDidDocument(@PathVariable("didKey") String didKey);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

package tng.trustnetwork.keydistribution.config;

import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -30,6 +33,8 @@
@ConfigurationProperties("dgc") //TODO separate kds and dgc-lib properties
public class KdsConfigProperties {

private List<TrustedIssuer> staticTrustedIssuer = new ArrayList<>();

private final CertificatesDownloader certificatesDownloader = new CertificatesDownloader();

private final TrustedIssuerDownloader trustedIssuerDownloader = new TrustedIssuerDownloader();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package tng.trustnetwork.keydistribution.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.time.ZonedDateTime;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;


@Data
@Getter
@Setter
@Entity
@Table(name = "decentralized_identifier")
@AllArgsConstructor
@NoArgsConstructor
public class DecentralizedIdentifierEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", columnDefinition = "BIGINT")
private Long id;

@Column(name = "created_at", nullable = false)
private ZonedDateTime createdAt = ZonedDateTime.now();

@Column(name = "did_id", length = 100)
private String didId;

@OneToMany(mappedBy = "parentDocument", fetch = FetchType.EAGER)
private List<VerificationMethodEntity> verificationMethods;

@Column(name = "raw", length = 10_000_000)
private String raw;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tng.trustnetwork.keydistribution.entity;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@DiscriminatorValue("EC")
public class EcPublicKeyJwkEntity extends PublicKeyJwkEntity {

@Column(name = "crv", length = 100)
private String crv;

@Column(name = "x", length = 100)
private String xvalue;

@Column(name = "y", length = 100)
private String yvalue;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package tng.trustnetwork.keydistribution.entity;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.Table;
import java.time.ZonedDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "public_key_jwk")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "kty", columnDefinition = "varchar(10)")
public abstract class PublicKeyJwkEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "created_at", nullable = false)
private ZonedDateTime createdAt = ZonedDateTime.now();

@Column(name = "x5c", length = 7000)
private String x5c;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tng.trustnetwork.keydistribution.entity;

import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@DiscriminatorValue("RSA")
public class RsaPublicKeyJwkEntity extends PublicKeyJwkEntity {

@Column(name = "n", length = 1000)
private String nvalue;

@Column(name = "e", length = 1000)
private String evalue;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package tng.trustnetwork.keydistribution.entity;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import java.time.ZonedDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Data
@Getter
@Setter
@Entity
@Table(name = "verification_method")
@AllArgsConstructor
@NoArgsConstructor
public class VerificationMethodEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", columnDefinition = "BIGINT")
private Long id;

@Column(name = "vm_id", length = 100)
private String vmId;

@Column(name = "type", length = 100)
private String type;

@Column(name = "controller", length = 100)
private String controller;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "public_key_jwk_id")
private PublicKeyJwkEntity publicKeyJwk;

@ManyToOne
@JoinColumn(name = "parent_document_id")
private DecentralizedIdentifierEntity parentDocument;

@Column(name = "created_at", nullable = false)
private ZonedDateTime createdAt = ZonedDateTime.now();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package tng.trustnetwork.keydistribution.mapper;

import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.SubclassExhaustiveStrategy;
import org.mapstruct.SubclassMapping;
import tng.trustnetwork.keydistribution.entity.DecentralizedIdentifierEntity;
import tng.trustnetwork.keydistribution.entity.EcPublicKeyJwkEntity;
import tng.trustnetwork.keydistribution.entity.PublicKeyJwkEntity;
import tng.trustnetwork.keydistribution.entity.RsaPublicKeyJwkEntity;
import tng.trustnetwork.keydistribution.entity.VerificationMethodEntity;
import tng.trustnetwork.keydistribution.model.DidDocument;
import tng.trustnetwork.keydistribution.model.EcPublicKeyJwk;
import tng.trustnetwork.keydistribution.model.JwkVerificationMethod;
import tng.trustnetwork.keydistribution.model.PublicKeyJwk;
import tng.trustnetwork.keydistribution.model.RsaPublicKeyJwk;
import tng.trustnetwork.keydistribution.model.StringOrObject;
import tng.trustnetwork.keydistribution.model.VerificationMethod;

@Mapper(componentModel = "spring", subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION)
public interface DidMapper {

@Mapping(target = "didId", source = "didDocument.id")
@Mapping(target = "verificationMethods", source = "didDocument.verificationMethod")
@Mapping(target = "id", ignore = true)
@Mapping(target = "createdAt", ignore = true)
DecentralizedIdentifierEntity toEntity(DidDocument didDocument, String raw);

@SubclassMapping(target = RsaPublicKeyJwkEntity.class, source = RsaPublicKeyJwk.class)
@SubclassMapping(target = EcPublicKeyJwkEntity.class, source = EcPublicKeyJwk.class)
@Mapping(target = "id", ignore = true)
@Mapping(target = "createdAt", ignore = true)
PublicKeyJwkEntity toEntity(PublicKeyJwk publicKeyJwk);

@Mapping(target = "id", ignore = true)
@Mapping(target = "createdAt", ignore = true)
EcPublicKeyJwkEntity toEntity(EcPublicKeyJwk model);

@Mapping(target = "id", ignore = true)
@Mapping(target = "createdAt", ignore = true)
RsaPublicKeyJwkEntity toEntity(RsaPublicKeyJwk model);

@SubclassMapping(target = VerificationMethodEntity.class, source = JwkVerificationMethod.class)
@Mapping(target = "vmId", source = "verificationMethod.id")
@Mapping(target = "id", ignore = true)
@Mapping(target = "createdAt", ignore = true)
@Mapping(target = "parentDocument", ignore = true)
@Mapping(target = "publicKeyJwk", ignore = true)
VerificationMethodEntity toEntity(VerificationMethod verificationMethod);

@Mapping(target = "type", constant = "JsonWebKey2020")
@Mapping(target = "vmId", source = "verificationMethod.id")
@Mapping(target = "id", ignore = true)
@Mapping(target = "parentDocument", ignore = true)
@Mapping(target = "createdAt", ignore = true)
VerificationMethodEntity toEntity(JwkVerificationMethod verificationMethod);

default <T> T unwrap(StringOrObject<T> wrapped) {
return wrapped.getObjectValue();
}

default String toSingleString(List<String> list) {

return list == null ? null : String.join(",", list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
public interface IssuerMapper {

@Mapping(source = "type", target = "urlType")
@Mapping(target = "id", ignore = true)
@Mapping(target = "etag", ignore = true)
@Mapping(target = "createdAt", ignore = true)
TrustedIssuerEntity trustedIssuerToTrustedIssuerEntity(TrustedIssuer trustedIssuer);


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tng.trustnetwork.keydistribution.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DidContext {

private String base;

private String rating;

private String publicAccess;

private String additionalType;
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package tng.trustnetwork.keydistribution.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DidDocument {

@JsonProperty("@context")
@JsonIgnoreProperties(ignoreUnknown = true)
private List<String> context;
@JsonIgnoreProperties(ignoreUnknown = true)
private List<StringOrObject<DidContext>> context;

private String id;
@JsonIgnoreProperties(ignoreUnknown = true)

private String controller;
@JsonIgnoreProperties(ignoreUnknown = true)
private Object verificationMethod;
@JsonIgnoreProperties(ignoreUnknown = true)


private List<StringOrObject<VerificationMethod>> verificationMethod;

private Proof proof;

}

This file was deleted.

Loading

0 comments on commit 8f34e17

Please sign in to comment.