Skip to content
This repository has been archived by the owner on Dec 31, 2021. It is now read-only.

Commit

Permalink
adds support for disabling ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
jam01 authored and flytreeleft committed Dec 19, 2020
1 parent aa1e0c4 commit 3167f3a
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Pattern;

import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.shiro.util.StringUtils;
import org.github.flytreeleft.nexus3.keycloak.plugin.internal.http.ClientAuthenticator;
import org.github.flytreeleft.nexus3.keycloak.plugin.internal.http.Http;
Expand Down Expand Up @@ -302,7 +309,23 @@ public AdapterConfig getConfig() {

public synchronized Http getHttp() {
if (this.http == null) {
HttpClient httpClient = HttpClients.createDefault();
HttpClient httpClient = null;

try {
HttpClientBuilder builder = HttpClients.custom();

if (this.config.isDisableTrustManager()) {
builder.setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, TrustAllStrategy.INSTANCE).build());
}
if (this.config.isAllowAnyHostname()) {
builder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
}

httpClient = builder.build();
} catch (Exception e) {
throw new IllegalArgumentException(e);
}

ClientAuthenticator clientAuthenticator = (HttpMethod httpMethod) -> {
String token = getTokenManager().getAccessTokenString();

Expand Down

0 comments on commit 3167f3a

Please sign in to comment.