KEYCLOAK-8069 Simplify config for fixed hostname provider

This commit is contained in:
stianst 2018-08-17 10:45:15 +02:00 committed by Stian Thorgersen
parent 90bafee5eb
commit e406e8f1f0
2 changed files with 24 additions and 11 deletions

View file

@ -34,7 +34,24 @@ public class FixedHostnameProvider implements HostnameProvider {
@Override @Override
public int getPort(UriInfo originalUriInfo) { 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;
}
}
} }
} }

View file

@ -114,9 +114,9 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
private void configureFixedHostname() throws Exception { private void configureFixedHostname() throws Exception {
if (suiteContext.getAuthServerInfo().isUndertow()) { 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()) { } 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 { } else {
throw new RuntimeException("Don't know how to config"); throw new RuntimeException("Don't know how to config");
} }
@ -127,9 +127,9 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
private void clearFixedHostname() throws Exception { private void clearFixedHostname() throws Exception {
if (suiteContext.getAuthServerInfo().isUndertow()) { if (suiteContext.getAuthServerInfo().isUndertow()) {
configureUndertow("request", "localhost", "-1", "-1"); configureUndertow("request", "localhost");
} else if (suiteContext.getAuthServerInfo().isJBossBased()) { } else if (suiteContext.getAuthServerInfo().isJBossBased()) {
configureWildFly("request", "localhost", "-1", "-1"); configureWildFly("request", "localhost");
} else { } else {
throw new RuntimeException("Don't know how to config"); throw new RuntimeException("Don't know how to config");
} }
@ -137,25 +137,21 @@ public class FixedHostnameTest extends AbstractKeycloakTest {
reconnectAdminClient(); reconnectAdminClient();
} }
private void configureUndertow(String provider, String hostname, String httpPort, String httpsPort) { private void configureUndertow(String provider, String hostname) {
controller.stop(suiteContext.getAuthServerInfo().getQualifier()); controller.stop(suiteContext.getAuthServerInfo().getQualifier());
System.setProperty("keycloak.hostname.provider", provider); System.setProperty("keycloak.hostname.provider", provider);
System.setProperty("keycloak.hostname.fixed.hostname", hostname); 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()); 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(); OnlineManagementClient client = AuthServerTestEnricher.getManagementClient();
Administration administration = new Administration(client); 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: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.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(); administration.reloadIfRequired();