From 555236c3f0ab4578e19f969ddb5685269224876f Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Wed, 10 Feb 2016 14:01:49 +0100 Subject: [PATCH] KEYCLOAK-2466 Redirection back to account/password is broken --- .../AbstractSecuredLocalService.java | 11 +++++---- .../testsuite/account/AccountTest.java | 23 +++++++++++++++++++ .../testsuite/pages/AccountPasswordPage.java | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/AbstractSecuredLocalService.java b/services/src/main/java/org/keycloak/services/resources/AbstractSecuredLocalService.java index 8306972ad4..45df9825b0 100755 --- a/services/src/main/java/org/keycloak/services/resources/AbstractSecuredLocalService.java +++ b/services/src/main/java/org/keycloak/services/resources/AbstractSecuredLocalService.java @@ -21,6 +21,7 @@ import org.jboss.resteasy.spi.HttpRequest; import org.keycloak.AbstractOAuthClient; import org.keycloak.common.ClientConnection; import org.keycloak.OAuth2Constants; +import org.keycloak.common.util.KeycloakUriBuilder; import org.keycloak.models.ClientModel; import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; @@ -113,13 +114,15 @@ public abstract class AbstractSecuredLocalService { throw new BadRequestException("state not specified"); } - URI uri = getBaseRedirectUri(); - URI redirectUri = path != null ? uri.resolve(path) : uri; + KeycloakUriBuilder redirect = KeycloakUriBuilder.fromUri(getBaseRedirectUri()); + if (path != null) { + redirect.path(path); + } if (referrer != null) { - redirectUri = redirectUri.resolve("?referrer=" + referrer); + redirect.queryParam("referrer", referrer); } - return Response.status(302).location(redirectUri).build(); + return Response.status(302).location(redirect.build()).build(); } finally { } } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java index 4f08b9b02e..8d9e85d836 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/account/AccountTest.java @@ -774,4 +774,27 @@ public class AccountTest { Assert.assertEquals(0, thirdPartyEntry.getProtocolMappersGranted().size()); } + @Test + public void loginToSpecificPage() { + changePasswordPage.open(); + loginPage.login("test-user@localhost", "password"); + + Assert.assertTrue(changePasswordPage.isCurrent()); + + events.clear(); + } + + @Test + public void loginToSpecificPageWithReferrer() { + driver.navigate().to(changePasswordPage.getPath() + "?referrer=account"); + System.out.println(driver.getCurrentUrl()); + + loginPage.login("test-user@localhost", "password"); + System.out.println(driver.getCurrentUrl()); + + Assert.assertTrue(changePasswordPage.isCurrent()); + + events.clear(); + } + } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/AccountPasswordPage.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/AccountPasswordPage.java index 7231b2323c..1e1da65f8f 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/AccountPasswordPage.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/AccountPasswordPage.java @@ -58,7 +58,7 @@ public class AccountPasswordPage extends AbstractAccountPage { } public boolean isCurrent() { - return driver.getTitle().contains("Account Management") && driver.getCurrentUrl().endsWith("/account/password"); + return driver.getTitle().contains("Account Management") && driver.getCurrentUrl().split("\\?")[0].endsWith("/account/password"); } public void open() {