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

refactor: fix reply channel validation (planning#2499)

parent 96da35d1
No related branches found
No related tags found
1 merge request!436planning#2267: Destination API Client
......@@ -16,6 +16,7 @@ import com.nimbusds.jose.jwk.RSAKey;
import dev.fitko.fitconnect.api.config.ApplicationConfig;
import dev.fitko.fitconnect.api.domain.model.attachment.Fragment;
import dev.fitko.fitconnect.api.domain.model.destination.Destination;
import dev.fitko.fitconnect.api.domain.model.destination.DestinationReplyChannels;
import dev.fitko.fitconnect.api.domain.model.destination.DestinationService;
import dev.fitko.fitconnect.api.domain.model.event.EventClaimFields;
import dev.fitko.fitconnect.api.domain.model.event.authtags.AuthenticationTags;
......@@ -76,7 +77,6 @@ import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
......@@ -86,7 +86,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static dev.fitko.fitconnect.core.crypto.constants.CryptoConstants.HASH_OF_ZERO_BYTES;
import static dev.fitko.fitconnect.core.utils.EventLogUtil.getAuthenticationTagFromEncryptedData;
......@@ -418,7 +417,7 @@ public class DefaultValidationService implements ValidationService {
// https://docs.fitko.de/fit-connect/docs/receiving/verification/#r%C3%BCckkanal
if (metadata.getReplyChannel() != null && serviceType != null) {
final Optional<ReplyChannel> matchingServiceReplyChannel = destination.getServices().stream()
final Optional<DestinationReplyChannels> matchingServiceReplyChannel = destination.getServices().stream()
.filter(service -> service.getIdentifier().equals(serviceType.getIdentifier()))
.filter(service -> service.getSubmissionSchemas().stream().anyMatch(schema -> schema.equals(submissionSchema)))
.map(DestinationService::getReplyChannels)
......@@ -440,31 +439,23 @@ public class DefaultValidationService implements ValidationService {
.stream()
.map(ApiAttachment::getPurpose)
.noneMatch(purpose -> purpose.equals(Purpose.DATA));
return noAttachmentWithDataPurpose && !data.getHash().getContent().equals(HASH_OF_ZERO_BYTES);
}
private Predicate<ReplyChannel> destinationAllowsSubmissionReplyChannel(final ReplyChannel submissionReplyChannel) {
return replyChannel -> {
final var destinationReplyChannelTypes = getNonNullReplyChannels(replyChannel);
final var submissionReplyChannelTypes = getNonNullReplyChannels(submissionReplyChannel);
return new HashSet<>(destinationReplyChannelTypes).containsAll(submissionReplyChannelTypes);
private Predicate<DestinationReplyChannels> destinationAllowsSubmissionReplyChannel(final ReplyChannel submissionReplyChannel) {
return destinationReplyChannel -> {
// build a comparison object because we have different types with different field declarations
DestinationReplyChannels.Builder comparison = DestinationReplyChannels.builder();
Optional.ofNullable(submissionReplyChannel.getEMail()).ifPresent(r -> comparison.withEmail(r.getUsePgp()));
Optional.ofNullable(submissionReplyChannel.getDeMail()).ifPresent(r -> comparison.withDeMail());
Optional.ofNullable(submissionReplyChannel.getFink()).ifPresent(r -> comparison.withFink());
Optional.ofNullable(submissionReplyChannel.getElster()).ifPresent(r -> comparison.withElster());
Optional.ofNullable(submissionReplyChannel.getIdBundDeMailbox()).ifPresent(r -> comparison.withIdBundDeMailbox(r.getMailboxUuid() != null));
Optional.ofNullable(submissionReplyChannel.getFitConnect()).ifPresent(r -> comparison.withFitConnect(r.getProcessStandards()));
return destinationReplyChannel.equals(comparison.build());
};
}
private List<Class<?>> getNonNullReplyChannels(final ReplyChannel replyChannel) {
return Stream.of(replyChannel.getEMail(),
replyChannel.getDeMail(),
replyChannel.getFink(),
replyChannel.getElster(),
replyChannel.getFitConnect(),
replyChannel.getIdBundDeMailbox())
.filter(Objects::nonNull)
// Getting the type is sufficient. We do not want an actual content comparison of objects ,
// since the destinations reply channel content will be null even if they are set.
.map(Object::getClass).collect(Collectors.toList());
}
private static boolean matchingDestinationAndSubmissionSchema(final Destination destination, final URI submissionDataSchemaUri) {
return destination.getServices().stream()
.flatMap(service -> service.getSubmissionSchemas().stream())
......
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