Skip to content

Commit

Permalink
KEYCLOAK-5242 Added means to run KeycloakServer with https
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlnarik committed Jul 27, 2017
1 parent dd6a7b2 commit 36080b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 9 additions & 0 deletions misc/Testsuite.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ When starting the server it can also import a realm from a json file:

mvn exec:java -Pkeycloak-server -Dimport=testrealm.json

When starting the server, https transport can be set up by setting keystore containing the server certificate
and https port, optionally setting the truststore.

mvn exec:java -Pkeycloak-server \
-Djavax.net.ssl.trustStore=/path/to/truststore.jks \
-Djavax.net.ssl.keyStore=/path/to/keystore.jks \
-Djavax.net.ssl.keyStorePassword=CHANGEME \
-Dkeycloak.port.https=8443

### Live edit of html and styles

The Keycloak test server can load resources directly from the filesystem instead of the classpath. This allows editing html, styles and updating images without restarting the server. To make the server use resources from the filesystem start with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.keycloak.services.resources.KeycloakApplication;
import org.keycloak.testsuite.util.cli.TestsuiteCLI;
import org.keycloak.util.JsonSerialization;
import org.mvel2.util.Make;

import javax.servlet.DispatcherType;
import java.io.File;
Expand All @@ -51,6 +50,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.net.ssl.SSLContext;

/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
Expand All @@ -64,6 +64,7 @@ public class KeycloakServer {
public static class KeycloakServerConfig {
private String host = "localhost";
private int port = 8081;
private int portHttps = -1;
private int workerThreads = Math.max(Runtime.getRuntime().availableProcessors(), 2) * 8;
private String resourcesHome;

Expand All @@ -75,6 +76,10 @@ public int getPort() {
return port;
}

public int getPortHttps() {
return portHttps;
}

public String getResourcesHome() {
return resourcesHome;
}
Expand All @@ -87,6 +92,10 @@ public void setPort(int port) {
this.port = port;
}

public void setPortHttps(int portHttps) {
this.portHttps = portHttps;
}

public void setResourcesHome(String resourcesHome) {
this.resourcesHome = resourcesHome;
}
Expand Down Expand Up @@ -140,6 +149,10 @@ public static KeycloakServer bootstrapKeycloakServer(String[] args) throws Throw
config.setPort(Integer.valueOf(System.getProperty("keycloak.port")));
}

if (System.getProperty("keycloak.port.https") != null) {
config.setPortHttps(Integer.valueOf(System.getProperty("keycloak.port.https")));
}

if (System.getProperty("keycloak.bind.address") != null) {
config.setHost(System.getProperty("keycloak.bind.address"));
}
Expand Down Expand Up @@ -312,6 +325,10 @@ public void start() throws Throwable {
.setWorkerThreads(config.getWorkerThreads())
.setIoThreads(config.getWorkerThreads() / 8);

if (config.getPortHttps() != -1) {
builder = builder.addHttpsListener(config.getPortHttps(), config.getHost(), SSLContext.getDefault());
}

server = new UndertowJaxrsServer();
try {
server.start(builder);
Expand Down Expand Up @@ -350,7 +367,9 @@ public void start() throws Throwable {
info("Loading resources from " + config.getResourcesHome());
}

info("Started Keycloak (http://" + config.getHost() + ":" + config.getPort() + "/auth) in "
info("Started Keycloak (http://" + config.getHost() + ":" + config.getPort() + "/auth"
+ (config.getPortHttps() > 0 ? ", https://" + config.getHost() + ":" + config.getPortHttps()+ "/auth" : "")
+ ") in "
+ (System.currentTimeMillis() - start) + " ms\n");
} catch (RuntimeException e) {
server.stop();
Expand Down

0 comments on commit 36080b9

Please sign in to comment.