From f0e31227928566a27c8a0a14d27f1c411c7dfce2 Mon Sep 17 00:00:00 2001 From: stianst Date: Fri, 14 Feb 2020 10:52:36 +0100 Subject: [PATCH] KEYCLOAK-12953 Ignore empty realm frontendUrl --- .../keycloak/url/DefaultHostnameProvider.java | 2 +- .../testsuite/url/DefaultHostnameTest.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/services/src/main/java/org/keycloak/url/DefaultHostnameProvider.java b/services/src/main/java/org/keycloak/url/DefaultHostnameProvider.java index 1472a10dd9..9f01d84957 100644 --- a/services/src/main/java/org/keycloak/url/DefaultHostnameProvider.java +++ b/services/src/main/java/org/keycloak/url/DefaultHostnameProvider.java @@ -97,7 +97,7 @@ public class DefaultHostnameProvider implements HostnameProvider { realmUri = null; String realmFrontendUrl = session.getContext().getRealm().getAttribute("frontendUrl"); - if (realmFrontendUrl != null) { + if (realmFrontendUrl != null && !realmFrontendUrl.isEmpty()) { try { realmUri = new URI(realmFrontendUrl); } catch (URISyntaxException e) { diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/url/DefaultHostnameTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/url/DefaultHostnameTest.java index 2114ff21b1..2398e1cc77 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/url/DefaultHostnameTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/url/DefaultHostnameTest.java @@ -9,6 +9,7 @@ import org.jboss.arquillian.test.api.ArquillianResource; import org.junit.BeforeClass; import org.junit.Test; import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.broker.provider.util.SimpleHttp; import org.keycloak.client.registration.Auth; import org.keycloak.client.registration.ClientRegistration; @@ -99,6 +100,26 @@ public class DefaultHostnameTest extends AbstractHostnameTest { } } + // KEYCLOAK-12953 + @Test + public void emptyRealmFrontendUrl() throws URISyntaxException { + expectedBackendUrl = AUTH_SERVER_ROOT; + oauth.clientId("direct-grant"); + + RealmResource realmResource = realmsResouce().realm("frontendUrl"); + RealmRepresentation rep = realmResource.toRepresentation(); + + try { + rep.getAttributes().put("frontendUrl", ""); + realmResource.update(rep); + + assertWellKnown("frontendUrl", AUTH_SERVER_ROOT); + } finally { + rep.getAttributes().put("frontendUrl", realmFrontEndUrl); + realmResource.update(rep); + } + } + @Test public void fixedAdminUrl() throws Exception { expectedBackendUrl = AUTH_SERVER_ROOT;