Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KEYCLOAK-5945 Strip default ports from urls #4774

Merged
merged 1 commit into from Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -154,6 +154,8 @@ protected void resolveUrls(KeycloakUriBuilder authUrlBuilder) {
log.debug("resolveUrls");
}

authServerBaseUrl = authUrlBuilder.build().toString();

String login = authUrlBuilder.clone().path(ServiceUrlConstants.AUTH_PATH).build(getRealm()).toString();
authUrl = KeycloakUriBuilder.fromUri(login);
realmInfoUrl = authUrlBuilder.clone().path(ServiceUrlConstants.REALM_INFO_PATH).build(getRealm()).toString();
Expand Down
Expand Up @@ -17,7 +17,9 @@
package org.keycloak.adapters;

import org.junit.Test;
import org.keycloak.representations.adapters.config.AdapterConfig;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -46,4 +48,21 @@ public void shouldEnableOAuthQueryParamWhenIgnoreNotSet() {

assertTrue(keycloakDeployment.isOAuthQueryParameterEnabled());
}

@Test
public void stripDefaultPorts() {
KeycloakDeployment keycloakDeployment = new KeycloakDeployment();
keycloakDeployment.setRealm("test");
AdapterConfig config = new AdapterConfig();
config.setAuthServerUrl("http://localhost:80/auth");
keycloakDeployment.setAuthServerBaseUrl(config);

assertEquals("http://localhost/auth", keycloakDeployment.getAuthServerBaseUrl());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


config.setAuthServerUrl("https://localhost:443/auth");
keycloakDeployment.setAuthServerBaseUrl(config);

assertEquals("https://localhost/auth", keycloakDeployment.getAuthServerBaseUrl());
}

}
Expand Up @@ -429,7 +429,9 @@ private String buildString(Map<String, ?> paramMap, boolean fromEncodedMap, bool
if ("".equals(host)) throw new RuntimeException("empty host name");
replaceParameter(paramMap, fromEncodedMap, isTemplate, host, buffer, encodeSlash);
}
if (port != -1) buffer.append(":").append(Integer.toString(port));
if (port != -1 && (scheme == null || (scheme.equals("http") && port != 80) || (scheme.equals("https") && port != 443)) ) {
buffer.append(":").append(Integer.toString(port));
}
} else if (authority != null) {
buffer.append("//");
replaceParameter(paramMap, fromEncodedMap, isTemplate, authority, buffer, encodeSlash);
Expand Down