Allow setting context-path for KeycloakServer (#21590)

Closes #21589
This commit is contained in:
Stian Thorgersen 2023-07-11 16:24:07 +02:00 committed by GitHub
parent 153d1a9841
commit 5a411d8931
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,6 +97,7 @@ public class KeycloakServer {
public static class KeycloakServerConfig { public static class KeycloakServerConfig {
private String host = "localhost"; private String host = "localhost";
private int port = 8081; private int port = 8081;
private String path = "/auth";
private int portHttps = -1; private int portHttps = -1;
private int workerThreads = Math.max(Runtime.getRuntime().availableProcessors(), 2) * 8; private int workerThreads = Math.max(Runtime.getRuntime().availableProcessors(), 2) * 8;
private String resourcesHome; private String resourcesHome;
@ -117,6 +118,10 @@ public class KeycloakServer {
return resourcesHome; return resourcesHome;
} }
public String getPath() {
return path;
}
public void setHost(String host) { public void setHost(String host) {
this.host = host; this.host = host;
} }
@ -125,6 +130,10 @@ public class KeycloakServer {
this.port = port; this.port = port;
} }
public void setPath(String path) {
this.path = path;
}
public void setPortHttps(int portHttps) { public void setPortHttps(int portHttps) {
this.portHttps = portHttps; this.portHttps = portHttps;
} }
@ -184,6 +193,10 @@ public class KeycloakServer {
config.setPort(Integer.valueOf(System.getProperty("keycloak.port"))); config.setPort(Integer.valueOf(System.getProperty("keycloak.port")));
} }
if (System.getProperty("keycloak.path") != null) {
config.setPath(System.getProperty("keycloak.path"));
}
if (System.getProperty("keycloak.port.https") != null) { if (System.getProperty("keycloak.port.https") != null) {
config.setPortHttps(Integer.valueOf(System.getProperty("keycloak.port.https"))); config.setPortHttps(Integer.valueOf(System.getProperty("keycloak.port.https")));
} }
@ -414,7 +427,7 @@ public class KeycloakServer {
DeploymentInfo di = server.undertowDeployment(deployment, ""); DeploymentInfo di = server.undertowDeployment(deployment, "");
di.setClassLoader(getClass().getClassLoader()); di.setClassLoader(getClass().getClassLoader());
di.setContextPath("/auth"); di.setContextPath(config.getPath());
di.setDeploymentName("Keycloak"); di.setDeploymentName("Keycloak");
di.setDefaultEncoding("UTF-8"); di.setDefaultEncoding("UTF-8");
@ -452,7 +465,7 @@ public class KeycloakServer {
info("Loading resources from " + config.getResourcesHome()); info("Loading resources from " + config.getResourcesHome());
} }
info("Started Keycloak (http://" + config.getHost() + ":" + config.getPort() + "/auth" info("Started Keycloak (http://" + config.getHost() + ":" + config.getPort() + config.getPath()
+ (config.getPortHttps() > 0 ? ", https://" + config.getHost() + ":" + config.getPortHttps()+ "/auth" : "") + (config.getPortHttps() > 0 ? ", https://" + config.getHost() + ":" + config.getPortHttps()+ "/auth" : "")
+ ") in " + ") in "
+ (System.currentTimeMillis() - start) + " ms\n"); + (System.currentTimeMillis() - start) + " ms\n");