Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Mierzwa <dev.maciej.mierzwa@gmail.com>
  • Loading branch information
MaciejMierzwa committed Dec 22, 2023
1 parent 06f375f commit 7488f91
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 854 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HTTPMetadataResolver2 extends AbstractReloadingMetadataResolver {
private final Logger log = LoggerFactory.getLogger(HTTPMetadataResolver2.class);
public class HTTPMetadataResolver extends AbstractReloadingMetadataResolver {
private final Logger log = LoggerFactory.getLogger(HTTPMetadataResolver.class);
private HttpClient httpClient;
private URI metadataURI;
private String cachedMetadataETag;
private String cachedMetadataLastModified;

public HTTPMetadataResolver2(final HttpClient client, final String metadataURL) throws ResolverException {
public HTTPMetadataResolver(final HttpClient client, final String metadataURL) throws ResolverException {
this(null, client, metadataURL);
}

public HTTPMetadataResolver2(final Timer backgroundTaskTimer, final HttpClient client, final String metadataURL)
throws ResolverException {
public HTTPMetadataResolver(final Timer backgroundTaskTimer, final HttpClient client, final String metadataURL)
throws ResolverException {
super(backgroundTaskTimer);

if (client == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.http.HttpStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -333,7 +333,7 @@ private MetadataResolver createMetadataResolver(final Settings settings, final P
final String idpMetadataFile = settings.get(IDP_METADATA_FILE);
final String idpMetadataBody = settings.get(IDP_METADATA_CONTENT);
if (idpMetadataUrl != null) {
metadataResolver = new SamlHTTPMetadataResolver2(idpMetadataUrl, settings, configPath);
metadataResolver = new SamlHTTPMetadataResolver(idpMetadataUrl, settings, configPath);
} else if (idpMetadataFile != null) {
metadataResolver = new SamlFilesystemMetadataResolver(idpMetadataFile, settings, configPath);
} else if (idpMetadataBody != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@
import java.security.PrivilegedExceptionAction;
import java.time.Duration;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.core5.http.URIScheme;
import org.apache.hc.core5.http.config.Registry;
import org.apache.hc.core5.http.config.RegistryBuilder;

import org.opensearch.SpecialPermission;
import org.opensearch.common.settings.Settings;

import com.amazon.dlic.util.SettingsBasedSSLConfiguratorV4;
import com.amazon.dlic.util.SettingsBasedSSLConfiguratorV5;
import net.shibboleth.utilities.java.support.resolver.ResolverException;
import org.opensaml.saml.metadata.resolver.impl.HTTPMetadataResolver;

public class SamlHTTPMetadataResolver extends HTTPMetadataResolver {

Expand All @@ -38,10 +43,9 @@ public class SamlHTTPMetadataResolver extends HTTPMetadataResolver {
}

@Override
@SuppressWarnings("removal")
protected byte[] fetchMetadata() throws ResolverException {
try {
return AccessController.doPrivileged((PrivilegedExceptionAction<byte[]>) () -> SamlHTTPMetadataResolver.super.fetchMetadata());
return AccessController.doPrivileged((PrivilegedExceptionAction<byte[]>) SamlHTTPMetadataResolver.super::fetchMetadata);
} catch (PrivilegedActionException e) {

if (e.getCause() instanceof ResolverException) {
Expand All @@ -52,11 +56,10 @@ protected byte[] fetchMetadata() throws ResolverException {
}
}

private static SettingsBasedSSLConfiguratorV4.SSLConfig getSSLConfig(Settings settings, Path configPath) throws Exception {
return new SettingsBasedSSLConfiguratorV4(settings, configPath, "idp").buildSSLConfig();
private static SettingsBasedSSLConfiguratorV5.SSLConfig getSSLConfig(Settings settings, Path configPath) throws Exception {
return new SettingsBasedSSLConfiguratorV5(settings, configPath, "idp").buildSSLConfig();
}

@SuppressWarnings("removal")
private static HttpClient createHttpClient(Settings settings, Path configPath) throws Exception {
try {
final SecurityManager sm = System.getSecurityManager();
Expand Down Expand Up @@ -86,10 +89,16 @@ private static HttpClient createHttpClient0(Settings settings, Path configPath)

builder.useSystemProperties();

SettingsBasedSSLConfiguratorV4.SSLConfig sslConfig = getSSLConfig(settings, configPath);
SettingsBasedSSLConfiguratorV5.SSLConfig sslConfig = getSSLConfig(settings, configPath);

if (sslConfig != null) {
builder.setSSLSocketFactory(sslConfig.toSSLConnectionSocketFactory());
SSLConnectionSocketFactory sslConnectionSocketFactory = sslConfig.toSSLConnectionSocketFactory();
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register(URIScheme.HTTPS.id, sslConnectionSocketFactory)
.build();

BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager(socketFactoryRegistry);
builder.setConnectionManager(connectionManager);
}

return builder.build();
Expand Down

This file was deleted.

Loading

0 comments on commit 7488f91

Please sign in to comment.