public void testRedirectBackAfterLogin()
{
try {
// Test setup: disallow view right for unauthenticated users. We need to be logged as admin in order to
// do that. Since this is not what we are testing use the fast way to log in
GlobalRightsAdministrationSectionPage grasp = new GlobalRightsAdministrationSectionPage();
getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(grasp.getURL()));
getUtil().recacheSecretToken();
grasp.forceAuthenticatedView();
// Go to a page, log out and expire session by removing cookies, log in again and verify that the user is
// redirected to the initial page.
ViewPage page = getUtil().gotoPage("SomeSpace", "SomePage");
page.logout();
// Since view is disallowed for unauthenticated users, at this point we see a log in page.
LoginPage loginPage = new LoginPage();
// Remove all cookie to simulate a session expiry
getDriver().manage().deleteAllCookies();
loginPage.loginAsAdmin();
// We use startsWith since the URL contains a jsessionid and a srid.
Assert.assertTrue(getDriver().getCurrentUrl().startsWith(getUtil().getURL("SomeSpace", "SomePage")));
} finally {
GlobalRightsAdministrationSectionPage grasp = new GlobalRightsAdministrationSectionPage();
grasp.gotoPage();
if (!grasp.isAuthenticated()) {
getDriver().get(getUtil().getURLToLoginAsAdminAndGotoPage(grasp.getURL()));
}
grasp.unforceAuthenticatedView();
}
}