Skip to content

Commit

Permalink
Refactored to functional style
Browse files Browse the repository at this point in the history
  • Loading branch information
Hakky54 committed Sep 1, 2024
1 parent e51a75a commit db67c18
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions sslcontext-kickstart/src/main/java/nl/altindag/ssl/SSLFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import nl.altindag.ssl.util.SSLParametersUtils;
import nl.altindag.ssl.util.SSLSessionUtils;
import nl.altindag.ssl.util.TrustManagerUtils;
import nl.altindag.ssl.util.internal.CollectorsUtils;
import nl.altindag.ssl.util.internal.StringUtils;
import nl.altindag.ssl.util.internal.UriUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -66,6 +67,7 @@
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -75,6 +77,7 @@
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
Expand Down Expand Up @@ -886,17 +889,13 @@ private SSLParameters createSslParameters(SSLContext sslContext) {
}

private void trustCertificateChains() {
List<Certificate> certificates = new ArrayList<>();
for (KeyStore trustStore : trustStores) {
KeyStoreUtils.getCertificateChains(trustStore).values().forEach(certificates::addAll);
}

for (KeyStoreHolder identity : identities) {
KeyStoreUtils.getCertificateChains(identity.getKeyStore()).values().forEach(certificates::addAll);
}
KeyStore trustStore = Stream.concat(trustStores.stream(), identities.stream().map(KeyStoreHolder::getKeyStore))
.map(KeyStoreUtils::getCertificateChains)
.flatMap(aliasToCertificateChain -> aliasToCertificateChain.values().stream())
.flatMap(Collection::stream)
.collect(CollectorsUtils.toListAndThen(KeyStoreUtils::createTrustStore));

if (!certificates.isEmpty()) {
KeyStore trustStore = KeyStoreUtils.createTrustStore(certificates);
if (KeyStoreUtils.containsTrustMaterial(trustStore)) {
trustStores.add(trustStore);
}
}
Expand Down

0 comments on commit db67c18

Please sign in to comment.