From 38e6bde07e357a04b0edd1d4fefdbfd9a905d6a5 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Wed, 30 Apr 2014 11:03:13 +0100 Subject: [PATCH] KEYCLOAK-415 Make sure query params are included when navigating in acct mngmt --- .../account/freemarker/FreeMarkerAccount.java | 8 +++++++- .../account/freemarker/model/UrlBean.java | 20 ++++++++++--------- .../services/resources/QRCodeResource.java | 2 +- .../testsuite/account/AccountTest.java | 14 +++++++++++++ .../testsuite/pages/AccountTotpPage.java | 2 +- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/FreeMarkerAccount.java b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/FreeMarkerAccount.java index 884484ff5d..fb30dacac4 100755 --- a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/FreeMarkerAccount.java +++ b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/FreeMarkerAccount.java @@ -22,6 +22,7 @@ import org.keycloak.models.UserModel; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; import java.io.IOException; import java.net.URI; @@ -85,6 +86,11 @@ public class FreeMarkerAccount implements Account { } URI baseUri = uriInfo.getBaseUri(); + UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder(); + for (Map.Entry> e : uriInfo.getQueryParameters().entrySet()) { + baseUriBuilder.queryParam(e.getKey(), e.getValue().toArray()); + } + URI baseQueryUri = baseUriBuilder.build(); if (message != null) { attributes.put("message", new MessageBean(messages.containsKey(message) ? messages.getProperty(message) : message, messageType)); @@ -94,7 +100,7 @@ public class FreeMarkerAccount implements Account { attributes.put("referrer", new ReferrerBean(referrer)); } - attributes.put("url", new UrlBean(realm, theme, baseUri)); + attributes.put("url", new UrlBean(realm, theme, baseUri, baseQueryUri)); attributes.put("features", new FeaturesBean(social, audit, passwordUpdateSupported)); diff --git a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/UrlBean.java b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/UrlBean.java index e626ddf33f..6467146dc3 100644 --- a/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/UrlBean.java +++ b/forms/account-freemarker/src/main/java/org/keycloak/account/freemarker/model/UrlBean.java @@ -14,43 +14,45 @@ public class UrlBean { private String realm; private Theme theme; private URI baseURI; + private URI baseQueryURI; - public UrlBean(RealmModel realm, Theme theme, URI baseURI) { + public UrlBean(RealmModel realm, Theme theme, URI baseURI, URI baseQueryURI) { this.realm = realm.getName(); this.theme = theme; this.baseURI = baseURI; + this.baseQueryURI = baseQueryURI; } public String getAccessUrl() { - return Urls.accountAccessPage(baseURI, realm).toString(); + return Urls.accountAccessPage(baseQueryURI, realm).toString(); } public String getAccountUrl() { - return Urls.accountPage(baseURI, realm).toString(); + return Urls.accountPage(baseQueryURI, realm).toString(); } public String getPasswordUrl() { - return Urls.accountPasswordPage(baseURI, realm).toString(); + return Urls.accountPasswordPage(baseQueryURI, realm).toString(); } public String getSocialUrl() { - return Urls.accountSocialPage(baseURI, realm).toString(); + return Urls.accountSocialPage(baseQueryURI, realm).toString(); } public String getTotpUrl() { - return Urls.accountTotpPage(baseURI, realm).toString(); + return Urls.accountTotpPage(baseQueryURI, realm).toString(); } public String getLogUrl() { - return Urls.accountLogPage(baseURI, realm).toString(); + return Urls.accountLogPage(baseQueryURI, realm).toString(); } public String getTotpRemoveUrl() { - return Urls.accountTotpRemove(baseURI, realm).toString(); + return Urls.accountTotpRemove(baseQueryURI, realm).toString(); } public String getLogoutUrl() { - return Urls.accountLogout(baseURI, realm).toString(); + return Urls.accountLogout(baseQueryURI, realm).toString(); } public String getResourcesPath() { diff --git a/services/src/main/java/org/keycloak/services/resources/QRCodeResource.java b/services/src/main/java/org/keycloak/services/resources/QRCodeResource.java index b2196131b3..3ae4b6756e 100755 --- a/services/src/main/java/org/keycloak/services/resources/QRCodeResource.java +++ b/services/src/main/java/org/keycloak/services/resources/QRCodeResource.java @@ -20,7 +20,7 @@ import java.io.OutputStream; /** * @author Stian Thorgersen */ -@Path("/rest/qrcode") +@Path("/qrcode") public class QRCodeResource { @GET 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 663eb6af56..78f82b4ce5 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 @@ -57,6 +57,7 @@ import org.keycloak.testsuite.rule.KeycloakRule; import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup; import org.keycloak.testsuite.rule.WebResource; import org.keycloak.testsuite.rule.WebRule; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import java.util.Collections; @@ -167,6 +168,19 @@ public class AccountTest { Assert.assertTrue(appPage.isCurrent()); Assert.assertEquals(appPage.baseUrl + "?test", driver.getCurrentUrl()); + driver.navigate().to(AccountUpdateProfilePage.PATH + "?referrer=test-app"); + Assert.assertTrue(profilePage.isCurrent()); + + driver.findElement(By.linkText("Authenticator")).click(); + Assert.assertTrue(totpPage.isCurrent()); + + driver.findElement(By.linkText("Account")).click(); + Assert.assertTrue(profilePage.isCurrent()); + + profilePage.backToApplication(); + + Assert.assertTrue(appPage.isCurrent()); + events.clear(); } diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/AccountTotpPage.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/AccountTotpPage.java index 02d6f4bac9..cd454de02f 100644 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/AccountTotpPage.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/pages/AccountTotpPage.java @@ -54,7 +54,7 @@ public class AccountTotpPage extends AbstractAccountPage { } public boolean isCurrent() { - return driver.getTitle().contains("Account Management") && driver.getCurrentUrl().endsWith("/account/totp"); + return driver.getTitle().contains("Account Management") && driver.getCurrentUrl().split("\\?")[0].endsWith("/account/totp"); } public void open() {