Skip to content

Commit

Permalink
Merge pull request #34 from WorldHealthOrganization/feat/ddccg-downlo…
Browse files Browse the repository at this point in the history
…ader

Feat: Add DDCCG Downloader
  • Loading branch information
f11h authored Mar 3, 2022
2 parents 7da7147 + 4f43203 commit 530769e
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<dependency>
<groupId>eu.europa.ec.dgc</groupId>
<artifactId>ddcc-gateway-lib</artifactId>
<version>1.1.13</version>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.vdurmont</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import eu.europa.ec.dgc.gateway.entity.TrustedIssuerEntity;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand Down Expand Up @@ -49,4 +50,7 @@ List<TrustedIssuerEntity> search(
@Param("ignoreCountry") boolean ignoreCountry,
@Param("domain") List<String> domain,
@Param("ignoreDomain") boolean ignoreDomain);

@Transactional
Long deleteBySourceGatewayGatewayId(String gatewayId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import eu.europa.ec.dgc.gateway.entity.TrustedReferenceEntity;
import java.util.List;
import java.util.Optional;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down Expand Up @@ -70,4 +71,7 @@ List<TrustedReferenceEntity> search(
@Param("signatureType") List<TrustedReferenceEntity.SignatureType> signatureType,
@Param("ignoreSignatureType") boolean ignoreSignatureType);

@Transactional
Long deleteBySourceGatewayGatewayId(String gatewayId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,28 @@ public class TrustedIssuerDto {
private String thumbprint;

@Schema(example = "o53CbAa77LyIMFc5Gz+B2Jc275Gdg/SdLayw7gx0GrTcinR95zfTLr8nNHgJMYlX3rD8Y11zB/Osyt0 ..."
+ " W+VIrYRGSEmgjGy2EwzvA5nVhsaA+/udnmbyQw9LjAOQ==")
+ " W+VIrYRGSEmgjGy2EwzvA5nVhsaA+/udnmbyQw9LjAOQ==")
private String sslPublicKey;

@Schema(example = "JWKS")
private String keyStorageType;

@Schema(example = "o53CbAa77LyIMFc5Gz+B2Jc275Gdg/SdLayw7gx0GrTcinR95zfTLr8nNHgJMYlX3rD8Y11zB/Osyt0 ..."
+ " W+VIrYRGSEmgjGy2EwzvA5nVhsaA+/udnmbyQw9LjAOQ==")
+ " W+VIrYRGSEmgjGy2EwzvA5nVhsaA+/udnmbyQw9LjAOQ==")
private String signature;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
private ZonedDateTime timestamp;

@Schema(example = "Example Service")
private String name;

@Schema(example = "e4d04ee1-2bfe-4e8c-ab82-0d2b1d223712")
private String uuid;

@Schema(example = "DCC")
private String domain;

public enum UrlTypeDto {
HTTP,
DID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
@Slf4j
public abstract class GwTrustListMapper {

@Mapping(source = "certificateType", target = "domain")
@Mapping(target = "sourceGateway", ignore = true)
@Mapping(target = "uuid", ignore = true)
@Mapping(target = "version", ignore = true)
public abstract TrustListDto trustListToTrustListDto(TrustList trustList);

public abstract List<TrustListDto> trustListToTrustListDto(List<TrustList> trustList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ public SignerInformationEntity addFederatedSignerCertificate(
String countryCode,
String kid,
String domain,
String uuid,
Integer version,
FederationGatewayEntity sourceGateway
) throws SignerCertCheckException {

Expand All @@ -275,6 +277,8 @@ public SignerInformationEntity addFederatedSignerCertificate(
newSignerInformation.setThumbprint(certificateUtils.getCertThumbprint(certificate));
newSignerInformation.setCertificateType(SignerInformationEntity.CertificateType.DSC);
newSignerInformation.setSignature(signature);
newSignerInformation.setUuid(uuid);
newSignerInformation.setVersion(version);
newSignerInformation.setDomain(domain == null ? "DCC" : domain);

log.info("Saving Federated SignerInformation Entity");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package eu.europa.ec.dgc.gateway.service;

import eu.europa.ec.dgc.gateway.config.DgcConfigProperties;
import eu.europa.ec.dgc.gateway.entity.FederationGatewayEntity;
import eu.europa.ec.dgc.gateway.entity.TrustedIssuerEntity;
import eu.europa.ec.dgc.gateway.entity.TrustedPartyEntity;
import eu.europa.ec.dgc.gateway.repository.TrustedIssuerRepository;
Expand All @@ -37,6 +38,7 @@
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -58,6 +60,19 @@ public class TrustedIssuerService {
private final DgcConfigProperties dgcConfigProperties;
private final CertificateUtils certificateUtils;

/**
* Deletes all TrustedIssuers assigned to given source gateway.
*
* @param gatewayId GatewayID of source gateway
*/
public void deleteBySourceGateway(String gatewayId) {
log.info("Deleting TrustedIssuer by GatewayId {}", gatewayId);

Long deleteCount = trustedIssuerRepository.deleteBySourceGatewayGatewayId(gatewayId);

log.info("Deleted {} TrustedIssuer with GatewayId {}", deleteCount, gatewayId);
}

/**
* Method to query the db for all trusted issuers.
*
Expand Down Expand Up @@ -168,6 +183,45 @@ private boolean validateTrustedIssuerIntegrity(TrustedIssuerEntity trustedIssuer
}
}

/**
* Add a new federated TrustedIssuer.
*/
public TrustedIssuerEntity addFederatedTrustedIssuer(String country,
String url,
String name,
TrustedIssuerEntity.UrlType urlType,
String thumbprint,
String sslPublicKey,
String keyStorageType,
String signature,
String domain,
String uuid,
Integer version,
FederationGatewayEntity sourceGateway) {
TrustedIssuerEntity trustedIssuerEntity = new TrustedIssuerEntity();
trustedIssuerEntity.setCountry(country);
trustedIssuerEntity.setName(name);
trustedIssuerEntity.setUrlType(urlType);
trustedIssuerEntity.setUrl(url);
trustedIssuerEntity.setThumbprint(thumbprint);
trustedIssuerEntity.setSslPublicKey(sslPublicKey);
trustedIssuerEntity.setKeyStorageType(keyStorageType);
trustedIssuerEntity.setSignature(signature);
trustedIssuerEntity.setVersion(version);
trustedIssuerEntity.setSourceGateway(sourceGateway);
trustedIssuerEntity.setDomain(domain == null ? "DCC" : domain);
if (uuid == null) {
trustedIssuerEntity.setUuid(UUID.randomUUID().toString());
}

log.info("Saving Federated Trusted Issuer Entity with uuid {}", trustedIssuerEntity.getUuid());

trustedIssuerEntity = trustedIssuerRepository.save(trustedIssuerEntity);

return trustedIssuerEntity;
}


private String getHashData(TrustedIssuerEntity entity) {
return entity.getUuid() + HASH_SEPARATOR
+ entity.getCountry() + HASH_SEPARATOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.europa.ec.dgc.gateway.entity.FederationGatewayEntity;
import eu.europa.ec.dgc.gateway.entity.TrustedPartyEntity;
import eu.europa.ec.dgc.gateway.entity.TrustedReferenceEntity;
import eu.europa.ec.dgc.gateway.repository.TrustedReferenceRepository;
Expand Down Expand Up @@ -59,6 +60,19 @@ public class TrustedReferenceService {
private static final String MDC_PROP_UPLOAD_CERT_THUMBPRINT = "uploadCertThumbprint";


/**
* Deletes all TrustedReferences assigned to given source gateway.
*
* @param gatewayId GatewayID of source gateway
*/
public void deleteBySourceGateway(String gatewayId) {
log.info("Deleting TrustedReferences by GatewayId {}", gatewayId);

Long deleteCount = trustedReferenceRepository.deleteBySourceGatewayGatewayId(gatewayId);

log.info("Deleted {} TrustedReferences with GatewayId {}", deleteCount, gatewayId);
}

/**
* Method to query the db for all trusted references.
*
Expand Down Expand Up @@ -127,6 +141,46 @@ public List<TrustedReferenceEntity> search(List<String> country, List<String> do

}

/**
* Add a new federated TrustedReference.
*/
public TrustedReferenceEntity addFederatedTrustedReference(String country,
TrustedReferenceEntity.ReferenceType referenceType,
String service,
String name,
TrustedReferenceEntity.SignatureType signatureType,
String thumbprint,
String sslPublicKey,
String referenceVersion,
String contentType,
String domain,
String uuid,
FederationGatewayEntity sourceGateway) {
TrustedReferenceEntity trustedReferenceEntity = new TrustedReferenceEntity();
trustedReferenceEntity.setCountry(country);
trustedReferenceEntity.setType(referenceType);
trustedReferenceEntity.setService(service);
trustedReferenceEntity.setName(name);
trustedReferenceEntity.setSignatureType(signatureType);
trustedReferenceEntity.setThumbprint(thumbprint);
trustedReferenceEntity.setSslPublicKey(sslPublicKey);
trustedReferenceEntity.setReferenceVersion(referenceVersion);
trustedReferenceEntity.setContentType(contentType);
trustedReferenceEntity.setSourceGateway(sourceGateway);
trustedReferenceEntity.setDomain(domain == null ? "DCC" : domain);
if (uuid == null) {
trustedReferenceEntity.setUuid(UUID.randomUUID().toString());
}

log.info("Saving Federated Trusted Reference Entity with uuid {}", trustedReferenceEntity.getUuid());

trustedReferenceEntity = trustedReferenceRepository.save(trustedReferenceEntity);

DgcMdc.remove(MDC_PROP_UPLOAD_CERT_THUMBPRINT);

return trustedReferenceEntity;
}

/**
* Add a new TrustedReference.
*/
Expand Down
Loading

0 comments on commit 530769e

Please sign in to comment.