Merge pull request #2210 from stianst/KEYCLOAK-2466

KEYCLOAK-2466 Redirection back to account/password is broken
This commit is contained in:
Stian Thorgersen 2016-02-10 14:44:54 +01:00
commit 72ded04517
3 changed files with 31 additions and 5 deletions

View file

@ -21,6 +21,7 @@ import org.jboss.resteasy.spi.HttpRequest;
import org.keycloak.AbstractOAuthClient; import org.keycloak.AbstractOAuthClient;
import org.keycloak.common.ClientConnection; import org.keycloak.common.ClientConnection;
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
import org.keycloak.common.util.KeycloakUriBuilder;
import org.keycloak.models.ClientModel; import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
@ -113,13 +114,15 @@ public abstract class AbstractSecuredLocalService {
throw new BadRequestException("state not specified"); throw new BadRequestException("state not specified");
} }
URI uri = getBaseRedirectUri(); KeycloakUriBuilder redirect = KeycloakUriBuilder.fromUri(getBaseRedirectUri());
URI redirectUri = path != null ? uri.resolve(path) : uri; if (path != null) {
redirect.path(path);
}
if (referrer != null) { 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 { } finally {
} }
} }

View file

@ -774,4 +774,27 @@ public class AccountTest {
Assert.assertEquals(0, thirdPartyEntry.getProtocolMappersGranted().size()); 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();
}
} }

View file

@ -58,7 +58,7 @@ public class AccountPasswordPage extends AbstractAccountPage {
} }
public boolean isCurrent() { 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() { public void open() {