diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java index 982b149e..66ddd1bb 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java @@ -346,7 +346,7 @@ public interface PageService { /** This triggers a logout on the current authorization context to logout the current user * and forward to the login page with showing a successful logout message to the user. */ - void logout(PageContext pageContext); + boolean logout(PageContext pageContext); default T logoutOnError(final Exception t, final PageContext pageContext) { log.error("Unexpected, Current User related error.Automatically logout and cleanup current user session. ", t); @@ -474,7 +474,7 @@ public interface PageService { public PageActionBuilder newAction(final ActionDefinition definition) { final PageActionBuilder newBuilder = new PageActionBuilder(this.pageService, this.originalPageContext); - newBuilder.pageContext = originalPageContext.copy(); + newBuilder.pageContext = this.originalPageContext.copy(); newBuilder.definition = definition; newBuilder.confirm = null; newBuilder.successMessage = null; @@ -489,17 +489,17 @@ public interface PageService { public PageAction create() { return new PageAction( - definition, - confirm, - successMessage, - selectionSupplier, - noSelectionMessage, - pageContext, - exec, - fireActionEvent, - ignoreMoveAwayFromEdit, - switchAction, - titleArgs); + this.definition, + this.confirm, + this.successMessage, + this.selectionSupplier, + this.noSelectionMessage, + this.pageContext, + this.exec, + this.fireActionEvent, + this.ignoreMoveAwayFromEdit, + this.switchAction, + this.titleArgs); } public PageActionBuilder publish() { @@ -507,7 +507,7 @@ public interface PageService { } public PageActionBuilder publish(final boolean active) { - pageService.publishAction(create(), active); + this.pageService.publishAction(create(), active); return this; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java index dabe4842..063050b7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/DefaultPageLayout.java @@ -145,19 +145,16 @@ public class DefaultPageLayout implements TemplateComposer { logout.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true)); logout.setData(RWT.CUSTOM_VARIANT, "header"); logout.addListener(SWT.Selection, event -> { - this.pageService.logout(pageContext); - // show successful logout message - final MessageBox logoutSuccess = new Message( - pageContext.getShell(), - this.polyglotPageService.getI18nSupport().getText("sebserver.logout"), - this.polyglotPageService.getI18nSupport().getText("sebserver.logout.success.message"), - SWT.ICON_INFORMATION, - pageContext.getI18nSupport()); - logoutSuccess.open(null); - - // TODO Try to invalidate RWT's user session. - // This seems to be more difficult then expected and just invalidate the HttpSession doesn't work - // Try to send a redirect JSON to the client: https://bugs.eclipse.org/bugs/show_bug.cgi?id=388249 + if (this.pageService.logout(pageContext)) { + // show successful logout message + final MessageBox logoutSuccess = new Message( + pageContext.getShell(), + this.polyglotPageService.getI18nSupport().getText("sebserver.logout"), + this.polyglotPageService.getI18nSupport().getText("sebserver.logout.success.message"), + SWT.ICON_INFORMATION, + pageContext.getI18nSupport()); + logoutSuccess.open(null); + } }); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java index ec47db36..43bc2ce3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java @@ -384,7 +384,7 @@ public class PageServiceImpl implements PageService { } @Override - public void logout(final PageContext pageContext) { + public boolean logout(final PageContext pageContext) { this.clearState(); try { @@ -392,14 +392,20 @@ public class PageServiceImpl implements PageService { if (!logoutSuccessful) { log.warn("Failed to logout. See log-files for more information"); + pageContext.forwardToMainPage(); + pageContext.publishInfo(new LocTextKey("sebserver.error.logout")); + return false; } } catch (final Exception e) { - log.info("Cleanup logout failed: {}", e.getMessage()); - } finally { - pageContext.forwardToLoginPage(); + log.info("Cleanup logout failed: {}", e.getMessage(), e); + pageContext.forwardToMainPage(); + pageContext.notifyError(new LocTextKey("sebserver.error.logout"), e); + return false; } + pageContext.forwardToLoginPage(); + return true; } @Override