Skip to content

Commit

Permalink
KEYCLOAK-8069 Simplify config for fixed hostname provider
Browse files Browse the repository at this point in the history
  • Loading branch information
stianst committed Aug 17, 2018
1 parent 90bafee commit e406e8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,24 @@ public String getHostname(UriInfo originalUriInfo) {

@Override
public int getPort(UriInfo originalUriInfo) {
return originalUriInfo.getRequestUri().getScheme().equals("https") ? httpsPort : httpPort;
boolean https = originalUriInfo.getRequestUri().getScheme().equals("https");
if (https) {
if (httpsPort == -1) {
return originalUriInfo.getRequestUri().getPort();
} else if (httpsPort == 443) {
return -1;
} else {
return httpsPort;
}
} else {
if (httpPort == -1) {
return originalUriInfo.getRequestUri().getPort();
} else if (httpPort == 80) {
return -1;
} else {
return httpPort;
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ private void assertWellKnown(String realm, String expectedHostname) {

private void configureFixedHostname() throws Exception {
if (suiteContext.getAuthServerInfo().isUndertow()) {
configureUndertow("fixed", "keycloak.127.0.0.1.nip.io", "8180", "8543");
configureUndertow("fixed", "keycloak.127.0.0.1.nip.io");
} else if (suiteContext.getAuthServerInfo().isJBossBased()) {
configureWildFly("fixed", "keycloak.127.0.0.1.nip.io", "8180", "8543");
configureWildFly("fixed", "keycloak.127.0.0.1.nip.io");
} else {
throw new RuntimeException("Don't know how to config");
}
Expand All @@ -127,35 +127,31 @@ private void configureFixedHostname() throws Exception {

private void clearFixedHostname() throws Exception {
if (suiteContext.getAuthServerInfo().isUndertow()) {
configureUndertow("request", "localhost", "-1", "-1");
configureUndertow("request", "localhost");
} else if (suiteContext.getAuthServerInfo().isJBossBased()) {
configureWildFly("request", "localhost", "-1", "-1");
configureWildFly("request", "localhost");
} else {
throw new RuntimeException("Don't know how to config");
}

reconnectAdminClient();
}

private void configureUndertow(String provider, String hostname, String httpPort, String httpsPort) {
private void configureUndertow(String provider, String hostname) {
controller.stop(suiteContext.getAuthServerInfo().getQualifier());

System.setProperty("keycloak.hostname.provider", provider);
System.setProperty("keycloak.hostname.fixed.hostname", hostname);
System.setProperty("keycloak.hostname.fixed.httpPort", httpPort);
System.setProperty("keycloak.hostname.fixed.httpsPort", httpsPort);

controller.start(suiteContext.getAuthServerInfo().getQualifier());
}

private void configureWildFly(String provider, String hostname, String httpPort, String httpsPort) throws Exception {
private void configureWildFly(String provider, String hostname) throws Exception {
OnlineManagementClient client = AuthServerTestEnricher.getManagementClient();
Administration administration = new Administration(client);

client.execute("/subsystem=keycloak-server/spi=hostname:write-attribute(name=default-provider, value=" + provider + ")");
client.execute("/subsystem=keycloak-server/spi=hostname/provider=fixed:write-attribute(name=properties.hostname,value=" + hostname + ")");
client.execute("/subsystem=keycloak-server/spi=hostname/provider=fixed:write-attribute(name=properties.httpPort,value=" + httpPort + ")");
client.execute("/subsystem=keycloak-server/spi=hostname/provider=fixed:write-attribute(name=properties.httpsPort,value=" + httpsPort + ")");

administration.reloadIfRequired();

Expand Down

0 comments on commit e406e8f

Please sign in to comment.