Merge pull request #787 from stianst/master
KEYCLOAK-711 HttpServletReqest.logout() does not work with relative URI
This commit is contained in:
commit
dec82ddf68
5 changed files with 31 additions and 4 deletions
|
@ -67,7 +67,8 @@ public class KeycloakAuthenticatorValve extends FormAuthenticator implements Lif
|
|||
if (session != null) {
|
||||
session.removeNote(KeycloakSecurityContext.class.getName());
|
||||
if (ksc instanceof RefreshableKeycloakSecurityContext) {
|
||||
((RefreshableKeycloakSecurityContext)ksc).logout(deploymentContext.getDeployment());
|
||||
CatalinaHttpFacade facade = new CatalinaHttpFacade(request, null);
|
||||
((RefreshableKeycloakSecurityContext)ksc).logout(deploymentContext.resolveDeployment(facade));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,8 @@ public class KeycloakAuthenticatorValve extends FormAuthenticator implements Lif
|
|||
if (session != null) {
|
||||
session.removeNote(KeycloakSecurityContext.class.getName());
|
||||
try {
|
||||
ServerRequest.invokeLogout(deploymentContext.getDeployment(), ksc.getToken().getSessionState());
|
||||
CatalinaHttpFacade facade = new CatalinaHttpFacade(request, null);
|
||||
ServerRequest.invokeLogout(deploymentContext.resolveDeployment(facade), ksc.getToken().getSessionState());
|
||||
} catch (Exception e) {
|
||||
log.severe("failed to invoke remote logout. " + e.getMessage());
|
||||
}
|
||||
|
|
|
@ -79,7 +79,8 @@ public class ServletKeycloakAuthMech extends UndertowKeycloakAuthMech {
|
|||
session.removeAttribute(KeycloakSecurityContext.class.getName());
|
||||
session.removeAttribute(KeycloakUndertowAccount.class.getName());
|
||||
if (account.getKeycloakSecurityContext() != null) {
|
||||
account.getKeycloakSecurityContext().logout(deploymentContext.getDeployment());
|
||||
UndertowHttpFacade facade = new UndertowHttpFacade(notification.getExchange());
|
||||
account.getKeycloakSecurityContext().logout(deploymentContext.resolveDeployment(facade));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -66,7 +66,8 @@ public abstract class UndertowKeycloakAuthMech implements AuthenticationMechanis
|
|||
if (account == null) return;
|
||||
session.removeAttribute(KeycloakUndertowAccount.class.getName());
|
||||
if (account.getKeycloakSecurityContext() != null) {
|
||||
account.getKeycloakSecurityContext().logout(deploymentContext.getDeployment());
|
||||
UndertowHttpFacade facade = new UndertowHttpFacade(notification.getExchange());
|
||||
account.getKeycloakSecurityContext().logout(deploymentContext.resolveDeployment(facade));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -158,4 +158,27 @@ public class RelativeUriAdapterTest {
|
|||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServletRequestLogout() throws Exception {
|
||||
driver.navigate().to("http://localhost:8081/customer-portal");
|
||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||
loginPage.login("bburke@redhat.com", "password");
|
||||
Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/customer-portal");
|
||||
Assert.assertTrue(driver.getPageSource().contains("Bill Burke"));
|
||||
|
||||
driver.navigate().to("http://localhost:8081/product-portal");
|
||||
Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/product-portal");
|
||||
Assert.assertTrue(driver.getPageSource().contains("iPhone"));
|
||||
|
||||
// test logout
|
||||
driver.navigate().to("http://localhost:8081/customer-portal/logout");
|
||||
|
||||
driver.navigate().to("http://localhost:8081/customer-portal");
|
||||
String currentUrl = driver.getCurrentUrl();
|
||||
Assert.assertTrue(currentUrl.startsWith(LOGIN_URL));
|
||||
driver.navigate().to("http://localhost:8081/product-portal");
|
||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue