mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-25 16:42:34 +00:00
KEYCLOAK-8349 KEYCLOAK-8659 Use TLS for all tests in the suite
This commit is contained in:
committed by
Pedro Igor
parent
885eec5ef2
commit
ee41a0450f
@@ -89,6 +89,9 @@ public abstract class AbstractAuthOptionsCmd extends AbstractGlobalOptionsCmd {
|
||||
@Option(name = "trustpass", description = "Truststore password (prompted for if not specified and --truststore is used)")
|
||||
String trustPass;
|
||||
|
||||
@Option(name = "insecure", description = "Turns off TLS validation", hasValue = false)
|
||||
boolean insecure;
|
||||
|
||||
@Option(name = "token", description = "Token to use for invocations. With this option set, every other authentication option is ignored")
|
||||
String externalToken;
|
||||
|
||||
@@ -178,6 +181,10 @@ public abstract class AbstractAuthOptionsCmd extends AbstractGlobalOptionsCmd {
|
||||
throw new RuntimeException("Failed to load truststore: " + truststore, e);
|
||||
}
|
||||
}
|
||||
|
||||
if (insecure) {
|
||||
HttpUtil.setSkipCertificateValidation();
|
||||
}
|
||||
}
|
||||
|
||||
protected ConfigData ensureAuthInfo(ConfigData config, CommandInvocation commandInvocation) {
|
||||
|
||||
@@ -30,9 +30,11 @@ import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.keycloak.client.admin.cli.httpcomponents.HttpDelete;
|
||||
import org.keycloak.client.admin.cli.operations.LocalSearch;
|
||||
@@ -53,6 +55,7 @@ import java.security.cert.CertificateException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.keycloak.common.util.ObjectUtil.capitalize;
|
||||
|
||||
@@ -68,6 +71,7 @@ public class HttpUtil {
|
||||
|
||||
private static HttpClient httpClient;
|
||||
private static SSLConnectionSocketFactory sslsf;
|
||||
private static final AtomicBoolean tlsWarningEmitted = new AtomicBoolean();
|
||||
|
||||
public static InputStream doGet(String url, String acceptType, String authorization) {
|
||||
try {
|
||||
@@ -257,11 +261,29 @@ public class HttpUtil {
|
||||
}
|
||||
SSLContext theContext = SSLContexts.custom()
|
||||
.useProtocol("TLS")
|
||||
.loadTrustMaterial(file, password == null ? null : password.toCharArray())
|
||||
.loadTrustMaterial(file, password == null ? null : password.toCharArray(), TrustSelfSignedStrategy.INSTANCE)
|
||||
.build();
|
||||
sslsf = new SSLConnectionSocketFactory(theContext);
|
||||
}
|
||||
|
||||
public static void setSkipCertificateValidation() {
|
||||
if (!tlsWarningEmitted.getAndSet(true)) {
|
||||
// Since this is a static util, it may happen that TLS is setup many times in one command
|
||||
// invocation (e.g. when a command requires logging in). However, we would like to
|
||||
// prevent this warning from appearing multiple times. That's why we need to guard it with a boolean.
|
||||
System.err.println("The server is configured to use TLS but there is no truststore specified.");
|
||||
System.err.println("The tool will skip certificate validation. This is highly discouraged for production use cases");
|
||||
}
|
||||
|
||||
SSLContextBuilder builder = new SSLContextBuilder();
|
||||
try {
|
||||
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
|
||||
sslsf = new SSLConnectionSocketFactory(builder.build());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed setting up TLS", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String extractIdFromLocation(String location) {
|
||||
int last = location.lastIndexOf("/");
|
||||
if (last != -1) {
|
||||
|
||||
Reference in New Issue
Block a user