Fix servlet logout on wildfly/undertow
This commit is contained in:
parent
187fbfaf03
commit
229391d48b
5 changed files with 13 additions and 9 deletions
|
@ -89,12 +89,14 @@ public class ServletSessionTokenStore implements AdapterTokenStore {
|
|||
req.removeAttribute(KeycloakSecurityContext.class.getName());
|
||||
HttpSession session = req.getSession(false);
|
||||
if (session == null) return;
|
||||
KeycloakUndertowAccount account = (KeycloakUndertowAccount)session.getAttribute(KeycloakUndertowAccount.class.getName());
|
||||
if (account == null) return;
|
||||
session.removeAttribute(KeycloakSecurityContext.class.getName());
|
||||
session.removeAttribute(KeycloakUndertowAccount.class.getName());
|
||||
if (account.getKeycloakSecurityContext() != null) {
|
||||
account.getKeycloakSecurityContext().logout(deployment);
|
||||
try {
|
||||
KeycloakUndertowAccount account = (KeycloakUndertowAccount) session.getAttribute(KeycloakUndertowAccount.class.getName());
|
||||
if (account == null) return;
|
||||
session.removeAttribute(KeycloakSecurityContext.class.getName());
|
||||
session.removeAttribute(KeycloakUndertowAccount.class.getName());
|
||||
} catch (IllegalStateException ise) {
|
||||
// Session may be already logged-out in case that app has adminUrl
|
||||
log.debugf("Session %s logged-out already", session.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ public class AdapterTest {
|
|||
// test logout
|
||||
|
||||
driver.navigate().to("http://localhost:8081/customer-portal/logout");
|
||||
|
||||
Assert.assertTrue(driver.getPageSource().contains("servlet logout ok"));
|
||||
|
||||
|
||||
driver.navigate().to("http://localhost:8081/customer-portal");
|
||||
|
|
|
@ -113,6 +113,7 @@ public class CookieTokenStoreAdapterTest {
|
|||
assertLogged();
|
||||
|
||||
driver.navigate().to("http://localhost:8081/customer-portal/logout");
|
||||
Assert.assertTrue(driver.getPageSource().contains("servlet logout ok"));
|
||||
driver.navigate().to("http://localhost:8081/customer-portal");
|
||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||
|
||||
|
@ -167,7 +168,7 @@ public class CookieTokenStoreAdapterTest {
|
|||
|
||||
private void logoutFromCustomerCookiePortal() {
|
||||
driver.navigate().to("http://localhost:8081/customer-cookie-portal/logout");
|
||||
Assert.assertTrue(driver.getPageSource().contains("ok"));
|
||||
Assert.assertTrue(driver.getPageSource().contains("servlet logout ok"));
|
||||
Assert.assertNull(driver.manage().getCookieNamed(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE));
|
||||
driver.navigate().to("http://localhost:8081/customer-cookie-portal");
|
||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||
|
|
|
@ -28,7 +28,7 @@ public class CustomerServlet extends HttpServlet {
|
|||
PrintWriter pw = resp.getWriter();
|
||||
if (req.getRequestURI().toString().endsWith("logout")) {
|
||||
resp.setStatus(200);
|
||||
pw.println("ok");
|
||||
pw.println("servlet logout ok");
|
||||
|
||||
// Call logout before pw.flush
|
||||
req.logout();
|
||||
|
|
|
@ -173,6 +173,7 @@ public class RelativeUriAdapterTest {
|
|||
|
||||
// test logout
|
||||
driver.navigate().to("http://localhost:8081/customer-portal/logout");
|
||||
Assert.assertTrue(driver.getPageSource().contains("servlet logout ok"));
|
||||
|
||||
driver.navigate().to("http://localhost:8081/customer-portal");
|
||||
String currentUrl = driver.getCurrentUrl();
|
||||
|
|
Loading…
Reference in a new issue