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());
|
req.removeAttribute(KeycloakSecurityContext.class.getName());
|
||||||
HttpSession session = req.getSession(false);
|
HttpSession session = req.getSession(false);
|
||||||
if (session == null) return;
|
if (session == null) return;
|
||||||
KeycloakUndertowAccount account = (KeycloakUndertowAccount)session.getAttribute(KeycloakUndertowAccount.class.getName());
|
try {
|
||||||
if (account == null) return;
|
KeycloakUndertowAccount account = (KeycloakUndertowAccount) session.getAttribute(KeycloakUndertowAccount.class.getName());
|
||||||
session.removeAttribute(KeycloakSecurityContext.class.getName());
|
if (account == null) return;
|
||||||
session.removeAttribute(KeycloakUndertowAccount.class.getName());
|
session.removeAttribute(KeycloakSecurityContext.class.getName());
|
||||||
if (account.getKeycloakSecurityContext() != null) {
|
session.removeAttribute(KeycloakUndertowAccount.class.getName());
|
||||||
account.getKeycloakSecurityContext().logout(deployment);
|
} 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
|
// test logout
|
||||||
|
|
||||||
driver.navigate().to("http://localhost:8081/customer-portal/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");
|
driver.navigate().to("http://localhost:8081/customer-portal");
|
||||||
|
|
|
@ -113,6 +113,7 @@ public class CookieTokenStoreAdapterTest {
|
||||||
assertLogged();
|
assertLogged();
|
||||||
|
|
||||||
driver.navigate().to("http://localhost:8081/customer-portal/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");
|
driver.navigate().to("http://localhost:8081/customer-portal");
|
||||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||||
|
|
||||||
|
@ -167,7 +168,7 @@ public class CookieTokenStoreAdapterTest {
|
||||||
|
|
||||||
private void logoutFromCustomerCookiePortal() {
|
private void logoutFromCustomerCookiePortal() {
|
||||||
driver.navigate().to("http://localhost:8081/customer-cookie-portal/logout");
|
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));
|
Assert.assertNull(driver.manage().getCookieNamed(AdapterConstants.KEYCLOAK_ADAPTER_STATE_COOKIE));
|
||||||
driver.navigate().to("http://localhost:8081/customer-cookie-portal");
|
driver.navigate().to("http://localhost:8081/customer-cookie-portal");
|
||||||
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
Assert.assertTrue(driver.getCurrentUrl().startsWith(LOGIN_URL));
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class CustomerServlet extends HttpServlet {
|
||||||
PrintWriter pw = resp.getWriter();
|
PrintWriter pw = resp.getWriter();
|
||||||
if (req.getRequestURI().toString().endsWith("logout")) {
|
if (req.getRequestURI().toString().endsWith("logout")) {
|
||||||
resp.setStatus(200);
|
resp.setStatus(200);
|
||||||
pw.println("ok");
|
pw.println("servlet logout ok");
|
||||||
|
|
||||||
// Call logout before pw.flush
|
// Call logout before pw.flush
|
||||||
req.logout();
|
req.logout();
|
||||||
|
|
|
@ -173,6 +173,7 @@ public class RelativeUriAdapterTest {
|
||||||
|
|
||||||
// test logout
|
// test logout
|
||||||
driver.navigate().to("http://localhost:8081/customer-portal/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");
|
driver.navigate().to("http://localhost:8081/customer-portal");
|
||||||
String currentUrl = driver.getCurrentUrl();
|
String currentUrl = driver.getCurrentUrl();
|
||||||
|
|
Loading…
Reference in a new issue