KEYCLOAK-415 Make sure query params are included when navigating in acct mngmt

This commit is contained in:
Stian Thorgersen 2014-04-30 11:03:13 +01:00
parent 9811aaeecc
commit 38e6bde07e
5 changed files with 34 additions and 12 deletions

View file

@ -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<String, List<String>> 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));

View file

@ -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() {

View file

@ -20,7 +20,7 @@ import java.io.OutputStream;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
@Path("/rest/qrcode")
@Path("/qrcode")
public class QRCodeResource {
@GET

View file

@ -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();
}

View file

@ -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() {