Skip to content
Snippets Groups Projects
Commit 53e63b4b authored by Martin Vogel's avatar Martin Vogel
Browse files

Merge branch 'refactor/service-restructure' into 'main'

Überarbeitung der Service Struktur

See merge request !99
parents 62226fb8 2aa5d8f0
No related branches found
No related tags found
1 merge request!99Überarbeitung der Service Struktur
Showing
with 219 additions and 171 deletions
......@@ -46,6 +46,7 @@ class EventLogVerificationService {
}
class SubmissionService{
+ getDestination
+ announceSubmission
+ getSubmission
+ sendSubmission
......@@ -63,15 +64,12 @@ class MessageDigestService{
+ createHash
+ verify
}
class DestinationService{
+ getPublicKey
+ getDestination
}
class KeyService{
+ getPublicKey
+ getDestination
+ getPublicEncryptionKey
+ getPublicSignatureKey
+ getPortalSignatureKey
+ getSubmissionServiceSignatureKey
}
......@@ -81,10 +79,6 @@ class ValidationService{
+ validateIntegrity
}
class SelfServicePortalService {
+ getPublicKeys
}
class OAuthService{
+ getCurrentToken
}
......@@ -139,24 +133,20 @@ SubscriberClient ..> SubscriberFacade : Uses
SubscriberFacade ..> SubmissionService : Uses
SubscriberFacade ..> CryptoService : Uses
SubscriberFacade ..> EventLogService : Uses
SubscriberFacade ..> SecurityEventService : Uses
SubscriberFacade ..> EventLogVerificationService : Uses
SubscriberFacade ..> ValidationService : Uses
SenderFacade ..> SubmissionService : Uses
SenderFacade ..> CryptoService : Uses
SenderFacade ..> DestinationService : Uses
SenderFacade ..> KeyService : Uses
SenderFacade ..> EventLogService : Uses
SenderFacade ..> EventLogVerificationService : Uses
SenderFacade ..> ValidationService : Uses
DestinationService ..> OAuthService : Uses
SubmissionService ..> OAuthService : Uses
EventLogService ..> OAuthService : Uses
EventLogService ..> EventLogVerificationService : Uses
EventLogVerificationService ..> KeyService : Uses
EventLogVerificationService ..> ValidationService : Uses
......@@ -167,7 +157,8 @@ ValidationService ..> SchemaProvider : Uses
SecurityEventService ..> ValidationService : Uses
KeyService ..> DestinationService : Uses
KeyService ..> SelfServicePortalService : Uses
KeyService ..> ValidationService : Uses
KeyService ..> OAuthService : Uses
KeyService ..> SubmissionService : Uses
```
......@@ -39,7 +39,7 @@ public class ApplicationConfig {
private EnvironmentName activeEnvironment;
public Environment getEnvironmentByName(final EnvironmentName environmentName) {
private Environment getEnvironmentByName(final EnvironmentName environmentName) {
if (environments.containsKey(environmentName)) {
return environments.get(environmentName);
} else {
......@@ -79,14 +79,38 @@ public class ApplicationConfig {
return getSubmissionBaseUrl() + ResourcePaths.DESTINATIONS_KEY_PATH;
}
public String getWellKnownKeysEndpoint() {
public String getSelfServicePortalWellKnownKeysEndpoint() {
return getSelfServicePortalBaseUrl() + ResourcePaths.WELL_KNOWN_KEYS_PATH;
}
public String getSubmissionServiceWellKnownKeysEndpoint() {
return getSubmissionBaseUrl() + ResourcePaths.WELL_KNOWN_KEYS_PATH;
}
public String getAreaEndpoint() {
return getRoutingBaseUrl() + ResourcePaths.ROUTING_AREA_PATH;
}
public String getRoutesEndpoint() {
return getRoutingBaseUrl() + ResourcePaths.ROUTING_ROUTE_PATH;
}
public String getWellKnownKeysPath() {
return ResourcePaths.WELL_KNOWN_KEYS_PATH;
}
private String getSubmissionBaseUrl() {
return getCurrentEnvironment().getSubmissionBaseUrl();
}
private String getSelfServicePortalBaseUrl() {
return getCurrentEnvironment().getSelfServicePortalBaseUrl();
}
private String getRoutingBaseUrl() {
return getCurrentEnvironment().getRoutingBaseUrl();
}
private String getAvailableEnvironmentNames() {
return environments.keySet()
.stream()
......
......@@ -9,6 +9,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class Environment {
private String authBaseUrl;
private String routingBaseUrl;
private String submissionBaseUrl;
private String selfServicePortalBaseUrl;
private boolean allowInsecurePublicKey;
}
......@@ -12,6 +12,8 @@ final class ResourcePaths {
static final String SUBMISSION_PATH = "/v1/submissions/{submissionId}";
static final String SUBMISSIONS_PATH = "/v1/submissions";
static final String SUBMISSION_ATTACHMENT_PATH = "/v1/submissions/{submissionId}/attachments/{attachmentId}";
static final String ROUTING_AREA_PATH = "/v1/areas";
static final String ROUTING_ROUTE_PATH = "/v1/routes";
static final String WELL_KNOWN_KEYS_PATH = "/.well-known/jwks.json";
}
......@@ -13,37 +13,38 @@ public enum SchemaConfig {
SCHEMA_BASE_URL(URI.create("https://schema.fitko.de/fit-connect/")),
EVENTS_SCHEMA_PATH(SCHEMA_BASE_URL.schemaUri.resolve("events/")),
SET_V_1_0_1(SCHEMA_BASE_URL.schemaUri.resolve("set-payload/1.0.1/set-payload.schema.json"), "set_schema_1.0.1.json"),
SET_V_1_0_0(SCHEMA_BASE_URL.schemaUri.resolve("set-payload/1.0.0/set-payload.schema.json"),"set_schema_1.0.0.json"),
SET_V_1_0_0(SCHEMA_BASE_URL.schemaUri.resolve("set-payload/1.0.0/set-payload.schema.json"), "set_schema_1.0.0.json"),
METADATA_V_1_0_0(SCHEMA_BASE_URL.schemaUri.resolve("metadata/1.0.0/metadata.schema.json"), "metadata_schema_1.0.0.json");
private final URI schemaUri;
private final String fileName;
SchemaConfig(final URI schemaUri, final String fileName){
SchemaConfig(final URI schemaUri, final String fileName) {
this.schemaUri = schemaUri;
this.fileName = fileName;
}
SchemaConfig(final URI schemaUri){
SchemaConfig(final URI schemaUri) {
this.schemaUri = schemaUri;
this.fileName = "";
fileName = "";
}
public static List<String> getSetSchemaFilePaths(final String setSchemaBaseDir){
public static List<String> getSetSchemaFilePaths(final String setSchemaBaseDir) {
return Stream.of(SET_V_1_0_0.fileName, SET_V_1_0_1.fileName)
.map(fileName -> setSchemaBaseDir + "/" + fileName)
.collect(Collectors.toList());
}
public static List<String> getMetadataSchemaFileNames(final String metadataBaseDir){
public static List<String> getMetadataSchemaFileNames(final String metadataBaseDir) {
return Stream.of(METADATA_V_1_0_0.fileName)
.map(fileName -> metadataBaseDir + "/" + fileName)
.collect(Collectors.toList());
}
@Override
public String toString(){
return this.schemaUri.toString();
public String toString() {
return schemaUri.toString();
}
}
......@@ -40,24 +40,35 @@ public interface CryptoService {
/**
* Encrypts a string with the given public key.
*
* @param publicKey RSA public key for encryption of string payload
* @param data json or xml data that should be encrypted
* @param encryptionKey RSA public key for encryption of string payload
* @param data string data that should be encrypted
* @return Hex string of the encrypted JWE object
*
* @throws EncryptionException if the payload cannot be encrypted or there was an issue with the key
*/
String encryptString(RSAKey publicKey, String data) throws EncryptionException;
String encryptString(RSAKey encryptionKey, String data) throws EncryptionException;
/**
* Encrypts an object with the given public key.
*
* @param encryptionKey RSA public key for encryption of string payload
* @param obj object that should be encrypted
* @return Hex string of the encrypted JWE object
*
* @throws EncryptionException if the payload cannot be encrypted or there was an issue with the key
*/
String encryptObject(RSAKey encryptionKey, Object obj);
/**
* Encrypts a byte[] payload with the given public key.
*
* @param publicKey RSA public key the payload is encrypted with
* @param encryptionKey RSA public key the payload is encrypted with
* @param bytes byte[] of the data that should be encrypted
* @return Hex string of the encrypted JWE object
*
* @throws EncryptionException if the payload cannot be encrypted or there was an issue with the key
*/
String encryptBytes(RSAKey publicKey, byte[] bytes) throws EncryptionException;
String encryptBytes(RSAKey encryptionKey, byte[] bytes) throws EncryptionException;
/**
* Creates a message digest hash from the given input byte[]
......@@ -66,4 +77,5 @@ public interface CryptoService {
* @return hex encoded string of the hashed data
*/
String hashBytes(byte[] data);
}
package dev.fitko.fitconnect.api.services.destination;
import dev.fitko.fitconnect.api.domain.model.destination.Destination;
import dev.fitko.fitconnect.api.domain.model.jwk.ApiJwk;
import dev.fitko.fitconnect.api.domain.model.submission.Submission;
import dev.fitko.fitconnect.api.exceptions.RestApiException;
import java.util.UUID;
/**
* A service that provides access to a {@link Submission}s {@link Destination} and its public encryption key
* via the FIT-Connect REST-API.
*/
public interface DestinationService {
/**
* Get the {@link Destination} by id.
*
* @param destinationID unique destination identifier
* @return the destination
*
* @throws RestApiException if an error occurred
*/
Destination getDestination(UUID destinationID) throws RestApiException;
/**
* Get a public {@link ApiJwk} fo a given destination.
*
* @param destinationID unique destination identifier
* @param keyId the keyId property of the public key
* @return the {@link ApiJwk}
*
* @throws RestApiException if an error occurred
*/
ApiJwk getPublicKey(UUID destinationID, String keyId) throws RestApiException;
}
package dev.fitko.fitconnect.api.services.events;
import dev.fitko.fitconnect.api.domain.model.destination.Destination;
import dev.fitko.fitconnect.api.domain.model.event.EventLog;
import dev.fitko.fitconnect.api.domain.model.event.EventLogEntry;
import dev.fitko.fitconnect.api.domain.model.event.EventStatus;
import dev.fitko.fitconnect.api.domain.model.event.authtags.AuthenticationTags;
import dev.fitko.fitconnect.api.domain.model.submission.Submission;
import dev.fitko.fitconnect.api.exceptions.EventLogException;
import dev.fitko.fitconnect.api.exceptions.RestApiException;
import java.util.List;
import java.util.UUID;
/**
......@@ -19,9 +25,22 @@ public interface EventLogService {
* Get the {@link EventLog} by caseId.
*
* @param caseId unique case identifier
* @return EventLog
* @param destinationId unique identifier of the destination
* @return list of {@link EventLogEntry}
*/
EventLog getEventLog(UUID caseId) throws RestApiException;
List<EventLogEntry> getEventLog(UUID caseId, UUID destinationId) throws RestApiException, EventLogException;
/**
* Retrieve the current status of a {@link Submission}.
*
* @param destinationId unique identifier of the {@link Destination} the log should be retrieved for
* @param caseId unique identifier of the case the log should be retrieved for
* @param submissionId unique identifier of the submission the log should be retrieved for
* @param authenticationTags {@link AuthenticationTags} used for SET-Event integrity validation
*
* @return {@link EventStatus} the current status
*/
EventStatus getLastedEvent(UUID destinationId, UUID caseId, UUID submissionId, AuthenticationTags authenticationTags) throws RestApiException, EventLogException;
/**
* Send an event for a given caseId.
......
package dev.fitko.fitconnect.api.services.destination;
package dev.fitko.fitconnect.api.services.keys;
import com.nimbusds.jose.jwk.RSAKey;
import dev.fitko.fitconnect.api.domain.model.destination.Destination;
......@@ -9,7 +9,6 @@ import java.util.UUID;
/**
* Service to retrieve and validate public keys from a {@link Destination} or the submission service well-known keys.
*
* @see dev.fitko.fitconnect.api.services.portal.SelfServicePortalService
* @see ValidationService
*
*/
......@@ -34,10 +33,19 @@ public interface KeyService {
RSAKey getPublicSignatureKey(UUID destinationId, String keyId);
/**
* Get the public signature key of the submission service for a given signature key-id.
* Get a public signature key for a given key-id from the self-service portal well-known keys.
*
* @param keyId unique identifier of the {@link RSAKey}
* @return validated {@link RSAKey} (@see {@link ValidationService#validateEncryptionPublicKey(RSAKey)})
*/
RSAKey getPortalSignatureKey(String keyId);
/**
* Get a public signature key for a given key-id from the submission service well-known keys.
*
* @param keyId unique identifier of the {@link RSAKey}
* @return validated {@link RSAKey} (@see {@link ValidationService#validateEncryptionPublicKey(RSAKey)})
*/
RSAKey getSubmissionServiceSignatureKey(String keyId);
}
package dev.fitko.fitconnect.api.services.portal;
import dev.fitko.fitconnect.api.domain.model.jwk.ApiJwkSet;
/**
* Service class for access to all technical endpoints of the FIT-Connect Self-Service-Portal.
*/
public interface SelfServicePortalService {
/**
* Get all well-known keys of the self-service portal as set of JWKs.
*
* @return set JWKs
*/
ApiJwkSet getPublicKeys();
}
......@@ -10,6 +10,7 @@ import dev.fitko.fitconnect.api.domain.model.submission.Submission;
import dev.fitko.fitconnect.api.domain.model.submission.SubmissionForPickup;
import dev.fitko.fitconnect.api.domain.model.submission.SubmissionsForPickup;
import dev.fitko.fitconnect.api.domain.model.submission.SubmitSubmission;
import dev.fitko.fitconnect.api.exceptions.RestApiException;
import java.util.UUID;
......@@ -74,4 +75,14 @@ public interface SubmissionService {
* @return encrypted string of the attachment data
*/
String getAttachment(UUID submissionId, UUID attachmentId);
/**
* Get the submissions {@link Destination} by id.
*
* @param destinationID unique destination identifier
* @return the {@link Destination}
*
* @throws RestApiException if an error occurred
*/
Destination getDestination(UUID destinationID);
}
......@@ -57,7 +57,7 @@ public class SubscriberClient {
* Loads a list of available {@link SubmissionForPickup} that were submitted to the {@link Subscriber}.
*
* @param destinationId unique identifier for a destination
* @return set of unique available submissions for pickup
* @return set of the first 0..500 available submissions
*/
public Set<SubmissionForPickup> getAvailableSubmissions(final UUID destinationId) {
return getAvailableSubmissions(destinationId, 0, DEFAULT_SUBMISSION_LIMIT);
......@@ -69,7 +69,7 @@ public class SubscriberClient {
* @param destinationId unique identifier for a destination
* @param offset position in the dataset
* @param limit number of submissions in result (max. is 500)
* @return set of unique of available submissions for pickup
* @return set of available submissions in the given range
*/
public Set<SubmissionForPickup> getAvailableSubmissions(final UUID destinationId, final int offset, final int limit) {
final Set<SubmissionForPickup> submissions = subscriber.pollAvailableSubmissions(destinationId, offset, limit);
......
......@@ -12,12 +12,10 @@ import dev.fitko.fitconnect.api.services.Subscriber;
import dev.fitko.fitconnect.api.services.auth.OAuthService;
import dev.fitko.fitconnect.api.services.crypto.CryptoService;
import dev.fitko.fitconnect.api.services.crypto.MessageDigestService;
import dev.fitko.fitconnect.api.services.destination.DestinationService;
import dev.fitko.fitconnect.api.services.destination.KeyService;
import dev.fitko.fitconnect.api.services.keys.KeyService;
import dev.fitko.fitconnect.api.services.events.EventLogService;
import dev.fitko.fitconnect.api.services.events.EventLogVerificationService;
import dev.fitko.fitconnect.api.services.events.SecurityEventService;
import dev.fitko.fitconnect.api.services.portal.SelfServicePortalService;
import dev.fitko.fitconnect.api.services.schema.SchemaProvider;
import dev.fitko.fitconnect.api.services.submission.SubmissionService;
import dev.fitko.fitconnect.api.services.validation.ValidationService;
......@@ -28,13 +26,11 @@ import dev.fitko.fitconnect.core.SubmissionSubscriber;
import dev.fitko.fitconnect.core.auth.DefaultOAuthService;
import dev.fitko.fitconnect.core.crypto.HashService;
import dev.fitko.fitconnect.core.crypto.JWECryptoService;
import dev.fitko.fitconnect.core.destination.DestinationApiService;
import dev.fitko.fitconnect.core.destination.PublicKeyService;
import dev.fitko.fitconnect.core.keys.PublicKeyService;
import dev.fitko.fitconnect.core.events.EventLogApiService;
import dev.fitko.fitconnect.core.events.EventLogVerifier;
import dev.fitko.fitconnect.core.events.SecurityEventTokenService;
import dev.fitko.fitconnect.core.http.ProxyConfig;
import dev.fitko.fitconnect.core.portal.SelfServicePortalApiService;
import dev.fitko.fitconnect.core.schema.SchemaResourceProvider;
import dev.fitko.fitconnect.core.submission.SubmissionApiService;
import dev.fitko.fitconnect.core.validation.DefaultValidationService;
......@@ -111,34 +107,38 @@ public final class ClientFactory {
}
private static Subscriber getSubscriber(final ApplicationConfig config) {
final CryptoService cryptoService = getCryptoService();
final RestTemplate restTemplate = getRestTemplate(config);
final SchemaProvider schemaProvider = getSchemaProvider();
final ValidationService validator = getValidationService(config, schemaProvider);
final MessageDigestService messageDigestService = getMessageDigestService();
final CryptoService cryptoService = getCryptoService(messageDigestService);
final ValidationService validator = getValidationService(config, schemaProvider, messageDigestService);
final OAuthService authService = getSubscriberConfiguredAuthService(config, restTemplate);
final EventLogService eventLogService = getEventLogService(config, restTemplate, authService);
final SubmissionService submissionService = getSubmissionService(config, restTemplate, authService);
final SecurityEventService setService = getSecurityEventTokenService(config, validator);
final DestinationService destinationService = getDestinationService(config, restTemplate, authService);
final SelfServicePortalService portalService = getSelfServicePortalService(config, restTemplate);
final KeyService keyService = getKeyService(config, validator, destinationService, portalService);
final KeyService keyService = getKeyService(config, restTemplate, authService, submissionService, validator);
final EventLogVerificationService eventLogVerifier = getEventLogVerifier(keyService, validator);
return new SubmissionSubscriber(submissionService, eventLogService, eventLogVerifier, cryptoService, validator, setService);
final EventLogService eventLogService = getEventLogService(config, restTemplate, eventLogVerifier, authService);
final SecurityEventService setService = getSecurityEventTokenService(config, validator);
return new SubmissionSubscriber(submissionService, eventLogService, cryptoService, validator, setService);
}
private static Sender getSender(final ApplicationConfig config) {
final CryptoService cryptoService = getCryptoService();
final RestTemplate restTemplate = getRestTemplate(config);
final SchemaProvider schemaProvider = getSchemaProvider();
final ValidationService validator = getValidationService(config, schemaProvider);
final MessageDigestService messageDigestService = getMessageDigestService();
final CryptoService cryptoService = getCryptoService(messageDigestService);
final ValidationService validator = getValidationService(config, schemaProvider, messageDigestService);
final OAuthService authService = getSenderConfiguredAuthService(config, restTemplate);
final DestinationService destinationService = getDestinationService(config, restTemplate, authService);
final SelfServicePortalService portalService = getSelfServicePortalService(config, restTemplate);
final KeyService keyService = getKeyService(config, validator, destinationService, portalService);
final SubmissionService submissionService = getSubmissionService(config, restTemplate, authService);
final EventLogService eventLogService = getEventLogService(config, restTemplate, authService);
final KeyService keyService = getKeyService(config, restTemplate, authService, submissionService, validator);
final EventLogVerificationService eventLogVerifier = getEventLogVerifier(keyService, validator);
return new SubmissionSender(destinationService, submissionService, eventLogService, eventLogVerifier, cryptoService, validator, keyService);
final EventLogService eventLogService = getEventLogService(config, restTemplate, eventLogVerifier, authService);
return new SubmissionSender(submissionService, eventLogService, cryptoService, validator, keyService);
}
private static OAuthService getSenderConfiguredAuthService(final ApplicationConfig config, final RestTemplate restTemplate) {
......@@ -157,21 +157,15 @@ public final class ClientFactory {
return new SubmissionApiService(authService, restTemplate, config);
}
private static EventLogService getEventLogService(final ApplicationConfig config, final RestTemplate restTemplate, final OAuthService authService) {
return new EventLogApiService(authService, restTemplate, config);
}
private static DestinationService getDestinationService(final ApplicationConfig config, final RestTemplate restTemplate, final OAuthService authService) {
return new DestinationApiService(authService, restTemplate, config);
private static EventLogService getEventLogService(final ApplicationConfig config, final RestTemplate restTemplate, final EventLogVerificationService eventLogVerifier, final OAuthService authService) {
return new EventLogApiService(config, authService, restTemplate, eventLogVerifier);
}
private static ValidationService getValidationService(final ApplicationConfig config, final SchemaProvider schemaProvider) {
final MessageDigestService messageDigestService = getMessageDigestService();
private static ValidationService getValidationService(final ApplicationConfig config, final SchemaProvider schemaProvider, final MessageDigestService messageDigestService) {
return new DefaultValidationService(config, messageDigestService, schemaProvider);
}
private static CryptoService getCryptoService() {
final MessageDigestService messageDigestService = getMessageDigestService();
private static CryptoService getCryptoService(final MessageDigestService messageDigestService) {
return new JWECryptoService(messageDigestService);
}
......@@ -191,12 +185,8 @@ public final class ClientFactory {
return new SecurityEventTokenService(config, validationService, rsaKey);
}
private static SelfServicePortalService getSelfServicePortalService(final ApplicationConfig config, final RestTemplate restTemplate) {
return new SelfServicePortalApiService(config, restTemplate);
}
private static KeyService getKeyService(final ApplicationConfig config, final ValidationService validator, final DestinationService destinationService, final SelfServicePortalService portalService) {
return new PublicKeyService(config, destinationService, portalService, validator);
private static KeyService getKeyService(final ApplicationConfig config, final RestTemplate restTemplate, final OAuthService authService, final SubmissionService submissionService, final ValidationService validator) {
return new PublicKeyService(config, restTemplate, authService, submissionService, validator);
}
private static EventLogVerificationService getEventLogVerifier(final KeyService keyService, final ValidationService validationService) {
......
......@@ -66,14 +66,12 @@ public class SendNewSubmissionStrategy {
try {
LOGGER.info("Getting public encryption key from destination {}", destinationId);
final RSAKey encryptionKey = sender.getEncryptionKeyForDestination(destinationId);
final Destination destination = sender.getDestination(destinationId);
final List<AttachmentPayload> encryptedAttachments = encryptAndHashAttachments(encryptionKey, submissionPayload.getAttachments());
final CreateSubmission newSubmission = buildSubmissionToAnnounce(destinationId, serviceType, encryptedAttachments);
LOGGER.info("Announcing submission");
final SubmissionForPickup announcedSubmission = sender.createSubmission(newSubmission);
final UUID announcedSubmissionId = announcedSubmission.getSubmissionId();
......@@ -90,13 +88,9 @@ public class SendNewSubmissionStrategy {
return null;
}
LOGGER.info("Encrypting data");
final String encryptedData = sender.encryptBytes(encryptionKey, submissionPayload.getData().getBytes(StandardCharsets.UTF_8));
LOGGER.info("Encrypting metadata");
final String encryptedMetadata = sender.encryptObject(encryptionKey, metadata);
LOGGER.info("Uploading submission");
final var startTimeSubmissionUpload = StopWatch.start();
final Submission submission = sender.sendSubmission(buildSubmitSubmission(announcedSubmissionId, encryptedData, encryptedMetadata));
LOGGER.info("Uploading submission took {}", StopWatch.stopWithFormattedTime(startTimeSubmissionUpload));
......
......@@ -3,6 +3,7 @@ package dev.fitko.fitconnect.client;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.jose.jwk.RSAKey;
import dev.fitko.fitconnect.api.config.*;
import dev.fitko.fitconnect.api.domain.auth.OAuthToken;
import dev.fitko.fitconnect.api.domain.model.event.Event;
import dev.fitko.fitconnect.api.domain.model.event.EventLogEntry;
import dev.fitko.fitconnect.api.domain.model.event.EventStatus;
......@@ -24,12 +25,14 @@ import dev.fitko.fitconnect.client.sender.SubmissionBuilder;
import dev.fitko.fitconnect.client.subscriber.ReceivedSubmission;
import dev.fitko.fitconnect.client.sender.model.AttachmentPayload;
import dev.fitko.fitconnect.client.util.SubmissionUtil;
import dev.fitko.fitconnect.core.auth.DefaultOAuthService;
import dev.fitko.fitconnect.core.crypto.HashService;
import dev.fitko.fitconnect.core.crypto.JWECryptoService;
import org.apache.tika.mime.MimeTypes;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.io.IOException;
......@@ -63,8 +66,7 @@ class ClientIntegrationTest {
void testSendAndConfirmCycle() {
// Given
final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab(testEnv);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("TESTING", true);
final var submission = SubmissionBuilder.Builder()
.withAttachment(new File("src/test/resources/attachment.txt"))
......@@ -95,9 +97,10 @@ class ClientIntegrationTest {
void testSendAndConfirmCycleWithEncryptedData() throws ParseException, IOException {
// Given
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("TESTING", true);
final UUID destinationId = UUID.fromString(System.getenv("TEST_DESTINATION_ID"));
final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab(testEnv);
final CryptoService cryptoService = new JWECryptoService(new HashService());
final SenderClient client = ClientFactory.senderClient(config);
......@@ -171,8 +174,7 @@ class ClientIntegrationTest {
void testAbortedSendSubmissionWithKeyValidationNotSilent() {
// Given
final var prodEnv = new Environment(authBaseUrl, submissionBaseUrl, false);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("PROD", prodEnv);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("PROD", false);
// When
final var submission = SubmissionBuilder.Builder()
......@@ -196,8 +198,7 @@ class ClientIntegrationTest {
void testListSubmissions() {
// Given
final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab(testEnv);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("TESTING", true);
final var senderClient = ClientFactory.senderClient(config);
final var subscriberClient = ClientFactory.subscriberClient(config);
......@@ -248,8 +249,7 @@ class ClientIntegrationTest {
void testRejectEvent() {
// Given
final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab(testEnv);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("TESTING", true);
final var submission = SubmissionBuilder.Builder()
.withAttachment(new File("src/test/resources/attachment.txt"))
......@@ -280,8 +280,7 @@ class ClientIntegrationTest {
void testAcceptEvent() {
// Given
final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab(testEnv);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("TESTING", true);
final var submission = SubmissionBuilder.Builder()
.withAttachment(new File("src/test/resources/attachment.txt"))
......@@ -312,8 +311,7 @@ class ClientIntegrationTest {
void testReadEventLogFromSender() {
// Given
final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab(testEnv);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("TESTING", true);
final var submission = SubmissionBuilder.Builder()
.withJsonData("{ \"data\": \"Beispiel Fachdaten\" }")
......@@ -344,8 +342,7 @@ class ClientIntegrationTest {
void testReadEventLogFromSubscriber() {
// Given
final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab(testEnv);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("TESTING", true);
final var submission = SubmissionBuilder.Builder()
.withAttachment(new File("src/test/resources/attachment.txt"))
......@@ -382,8 +379,7 @@ class ClientIntegrationTest {
void testReadSubmissionStatusWithAuthTagEventValidationFromSender() {
// Given
final var testEnv = new Environment(authBaseUrl, submissionBaseUrl, true);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab(testEnv);
final ApplicationConfig config = getConfigWithCredentialsFromGitlab("TESTING", true);
final SenderClient senderClient = ClientFactory.senderClient(config);
......@@ -407,14 +403,37 @@ class ClientIntegrationTest {
return statusForSubmission.getStatus().equals(Event.SUBMIT.getState());
});
}
}
@Nested
class AuthenticationTests {
@Test
@EnabledIfEnvironmentVariable(named = "TEST_DESTINATION_ID", matches = ".*")
void retrieveAuthenticationToken() {
// Given
final var tokenUrl = "https://auth-testing.fit-connect.fitko.dev/token";
final var clientId = "781f6213-0f0f-4a79-9372-e7187ffda98b";
final var secret = "PnzR8Vbmhpv_VwTkT34wponqXWK8WBm-LADlryYdV4o";
final var scope1 = "send:region:DE";
final var scope2 = "send:region:EN";
final var authService = new DefaultOAuthService(new RestTemplate(), clientId, secret, tokenUrl);
// When
final OAuthToken token = authService.getCurrentToken();
private ApplicationConfig getConfigWithCredentialsFromGitlab(final Environment env) {
return getConfigWithCredentialsFromGitlab("TESTING", env);
// Then
assertNotNull(token);
assertNull(token.getError());
assertNotNull(token.getAccessToken());
assertEquals(1800, token.getExpiresIn());
}
}
private ApplicationConfig getConfigWithCredentialsFromGitlab(final String environmentName, final Environment env) {
private ApplicationConfig getConfigWithCredentialsFromGitlab(final String environmentName, final boolean allowInsecurePublicKey) {
final var sender = new SenderConfig(System.getenv("SENDER_CLIENT_ID"), System.getenv("SENDER_CLIENT_SECRET"));
......@@ -426,6 +445,7 @@ class ClientIntegrationTest {
.build();
final var envName = new EnvironmentName(environmentName);
final Environment env = getEnvironment(allowInsecurePublicKey);
return ApplicationConfig.builder()
.senderConfig(sender)
......@@ -434,4 +454,12 @@ class ClientIntegrationTest {
.activeEnvironment(envName)
.build();
}
private static Environment getEnvironment(final boolean allowInsecurePublicKey) {
final String authBaseUrl = "https://auth-testing.fit-connect.fitko.dev";
final String routingBaseUrl = "https://routing-api-testing.fit-connect.fitko.dev";
final String selfServicePortalUrl = "https://portal.auth-testing.fit-connect.fitko.dev";
final String submissionBaseUrl = "https://submission-api-testing.fit-connect.fitko.dev";
return new Environment(authBaseUrl, routingBaseUrl, submissionBaseUrl, selfServicePortalUrl, allowInsecurePublicKey);
}
}
......@@ -50,7 +50,9 @@ class ApplicationConfigLoaderTest {
final Environment devEnv = new Environment(
"https://auth-testing.fit-connect.fitko.dev",
"https://routing-api-testing.fit-connect.fitko.dev",
"https://submission-api-testing.fit-connect.fitko.dev",
"https://portal.auth-testing.fit-connect.fitko.dev",
true
);
......
......@@ -26,7 +26,7 @@ class ClientFactoryTest {
void testSenderClientConstruction() {
final var envName = new EnvironmentName("DEV");
final var environments = Map.of(envName, new Environment("https://auth", "", true));
final var environments = Map.of(envName, new Environment("https://auth", "", "", "", true));
final var sender = new SenderConfig("123", "abc");
......@@ -45,7 +45,7 @@ class ClientFactoryTest {
void testSubscriberClientConstruction() {
final var envName = new EnvironmentName("DEV");
final var environments = Map.of(envName, new Environment("https://auth", "", true));
final var environments = Map.of(envName, new Environment("https://auth", "", "", "", true));
final var subscriber = SubscriberConfig.builder()
.clientSecret("123")
......@@ -69,7 +69,7 @@ class ClientFactoryTest {
void testSigningKeyCannotBeParsed() {
final var envName = new EnvironmentName("DEV");
final var environments = Map.of(envName, new Environment("https://auth", "", true));
final var environments = Map.of(envName, new Environment("https://auth", "", "", "", true));
final var subscriberConfig = SubscriberConfig.builder()
.clientSecret("123")
......@@ -97,7 +97,7 @@ class ClientFactoryTest {
void testDecryptionKeyCannotBeParsed() {
final var envName = new EnvironmentName("DEV");
final var environments = Map.of(envName, new Environment("https://auth", "", true));
final var environments = Map.of(envName, new Environment("https://auth", "", "", "", true));
final var subscriberConfigWithoutKey = SubscriberConfig.builder()
.clientSecret("123")
......
......@@ -12,14 +12,20 @@ activeEnvironment: environment_that_does_not_exist
environments:
prod:
authBaseUrl: "https://auth-prod.fit-connect.fitko.dev"
submissionBaseUrl: "https://submission-api-prod.fit-connect.fitko.dev"
authBaseUrl: "https://auth-prod.fit-connect.fitko.net"
routingBaseUrl: "https://routing-api-prod.fit-connect.fitko.net"
submissionBaseUrl: "https://submission-api-prod.fit-connect.fitko.net"
selfServicePortalBaseUrl: "https://portal.auth-prod.fit-connect.fitko.net"
allowInsecurePublicKey: false
dev:
authBaseUrl: "https://auth-testing.fit-connect.fitko.dev"
routingBaseUrl: "https://routing-api-testing.fit-connect.fitko.dev"
submissionBaseUrl: "https://submission-api-testing.fit-connect.fitko.dev"
selfServicePortalBaseUrl: "https://portal.auth-testing.fit-connect.fitko.dev"
allowInsecurePublicKey: true
testing:
authBaseUrl: "https://auth-test.fit-connect.fitko.dev"
authBaseUrl: "https://auth-testing.fit-connect.fitko.dev"
routingBaseUrl: "https://routing-api-testing.fit-connect.fitko.dev"
submissionBaseUrl: "https://submission-api-testing.fit-connect.fitko.dev"
selfServicePortalBaseUrl: "https://portal.auth-testing.fit-connect.fitko.dev"
allowInsecurePublicKey: true
......@@ -12,14 +12,20 @@ activeEnvironment: dev
environments:
prod:
authBaseUrl: "https://auth-prod.fit-connect.fitko.dev"
submissionBaseUrl: "https://submission-api-prod.fit-connect.fitko.dev"
authBaseUrl: "https://auth-prod.fit-connect.fitko.net"
routingBaseUrl: "https://routing-api-prod.fit-connect.fitko.net"
submissionBaseUrl: "https://submission-api-prod.fit-connect.fitko.net"
selfServicePortalBaseUrl: "https://portal.auth-prod.fit-connect.fitko.net"
allowInsecurePublicKey: false
dev:
authBaseUrl: "https://auth-testing.fit-connect.fitko.dev"
routingBaseUrl: "https://routing-api-testing.fit-connect.fitko.dev"
submissionBaseUrl: "https://submission-api-testing.fit-connect.fitko.dev"
selfServicePortalBaseUrl: "https://portal.auth-testing.fit-connect.fitko.dev"
allowInsecurePublicKey: true
testing:
authBaseUrl: "https://auth-test.fit-connect.fitko.dev"
authBaseUrl: "https://auth-testing.fit-connect.fitko.dev"
routingBaseUrl: "https://routing-api-testing.fit-connect.fitko.dev"
submissionBaseUrl: "https://submission-api-testing.fit-connect.fitko.dev"
allowInsecurePublicKey: true
selfServicePortalBaseUrl: "https://portal.auth-testing.fit-connect.fitko.dev"
allowInsecurePublicKey: true
\ No newline at end of file
......@@ -34,6 +34,7 @@ activeEnvironment: testing
#
# name: -- identifier that can be referenced in 'activeEnvironment'
# authBaseUrl: "URL" -- base URL for OAuth requests
# routingBaseUrl: "URL" -- base URL for routing and area search requests
# submissionBaseUrl: "URL" -- base URL for submission/destination requests
# allowInsecurePublicKey: true | false -- allow public keys that failed a validation for e.g. testing purposes
#
......@@ -41,12 +42,16 @@ activeEnvironment: testing
environments:
prod:
authBaseUrl: "https://auth-prod.fit-connect.fitko.dev"
submissionBaseUrl: "https://submission-api-prod.fit-connect.fitko.dev"
authBaseUrl: "https://auth-prod.fit-connect.fitko.net"
routingBaseUrl: "https://routing-api-prod.fit-connect.fitko.net"
submissionBaseUrl: "https://submission-api-prod.fit-connect.fitko.net"
selfServicePortalBaseUrl: "https://portal.auth-prod.fit-connect.fitko.net"
allowInsecurePublicKey: false
testing:
authBaseUrl: "https://auth-testing.fit-connect.fitko.dev"
routingBaseUrl: "https://routing-api-testing.fit-connect.fitko.dev"
submissionBaseUrl: "https://submission-api-testing.fit-connect.fitko.dev"
selfServicePortalBaseUrl: "https://portal.auth-testing.fit-connect.fitko.dev"
allowInsecurePublicKey: true
#####################################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment