fixed logout error bug

This commit is contained in:
anhefti 2020-11-12 13:52:26 +01:00
parent af8cca8ab2
commit baee52a69a
No known key found for this signature in database
GPG key ID: E9AD9471B6BC114D
3 changed files with 33 additions and 30 deletions

View file

@ -309,7 +309,7 @@ public interface PageService {
/** This triggers a logout on the current authorization context to logout the current user /** 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. */ * 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> T logoutOnError(final Exception t, final PageContext pageContext) { default <T> T logoutOnError(final Exception t, final PageContext pageContext) {
log.error("Unexpected, Current User related error.Automatically logout and cleanup current user session. ", t); log.error("Unexpected, Current User related error.Automatically logout and cleanup current user session. ", t);
@ -416,7 +416,7 @@ public interface PageService {
public PageActionBuilder newAction(final ActionDefinition definition) { public PageActionBuilder newAction(final ActionDefinition definition) {
final PageActionBuilder newBuilder = new PageActionBuilder(this.pageService, this.originalPageContext); final PageActionBuilder newBuilder = new PageActionBuilder(this.pageService, this.originalPageContext);
newBuilder.pageContext = originalPageContext.copy(); newBuilder.pageContext = this.originalPageContext.copy();
newBuilder.definition = definition; newBuilder.definition = definition;
newBuilder.confirm = null; newBuilder.confirm = null;
newBuilder.successMessage = null; newBuilder.successMessage = null;
@ -431,16 +431,16 @@ public interface PageService {
public PageAction create() { public PageAction create() {
return new PageAction( return new PageAction(
definition, this.definition,
confirm, this.confirm,
successMessage, this.successMessage,
selectionSupplier, this.selectionSupplier,
noSelectionMessage, this.noSelectionMessage,
pageContext, this.pageContext,
exec, this.exec,
fireActionEvent, this.fireActionEvent,
ignoreMoveAwayFromEdit, this.ignoreMoveAwayFromEdit,
switchAction); this.switchAction);
} }
public PageActionBuilder publish() { public PageActionBuilder publish() {
@ -448,7 +448,7 @@ public interface PageService {
} }
public PageActionBuilder publish(final boolean active) { public PageActionBuilder publish(final boolean active) {
pageService.publishAction(create(), active); this.pageService.publishAction(create(), active);
return this; return this;
} }

View file

@ -145,7 +145,7 @@ public class DefaultPageLayout implements TemplateComposer {
logout.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true)); logout.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, true));
logout.setData(RWT.CUSTOM_VARIANT, "header"); logout.setData(RWT.CUSTOM_VARIANT, "header");
logout.addListener(SWT.Selection, event -> { logout.addListener(SWT.Selection, event -> {
this.pageService.logout(pageContext); if (this.pageService.logout(pageContext)) {
// show successful logout message // show successful logout message
final MessageBox logoutSuccess = new Message( final MessageBox logoutSuccess = new Message(
pageContext.getShell(), pageContext.getShell(),
@ -154,10 +154,7 @@ public class DefaultPageLayout implements TemplateComposer {
SWT.ICON_INFORMATION, SWT.ICON_INFORMATION,
pageContext.getI18nSupport()); pageContext.getI18nSupport());
logoutSuccess.open(null); 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
}); });
} }
} }

View file

@ -366,7 +366,7 @@ public class PageServiceImpl implements PageService {
} }
@Override @Override
public void logout(final PageContext pageContext) { public boolean logout(final PageContext pageContext) {
this.clearState(); this.clearState();
try { try {
@ -374,14 +374,20 @@ public class PageServiceImpl implements PageService {
if (!logoutSuccessful) { if (!logoutSuccessful) {
log.warn("Failed to logout. See log-files for more information"); 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) { } catch (final Exception e) {
log.info("Cleanup logout failed: {}", e.getMessage()); log.info("Cleanup logout failed: {}", e.getMessage(), e);
} finally { pageContext.forwardToMainPage();
pageContext.forwardToLoginPage(); pageContext.notifyError(new LocTextKey("sebserver.error.logout"), e);
return false;
} }
pageContext.forwardToLoginPage();
return true;
} }
@Override @Override