【发布时间】:2015-09-28 05:29:38
【问题描述】:
在我的 vaadin Web 应用程序中,管理员用户应该能够强制注销当前登录的用户。当用户被强制注销时,应立即将其重定向到登录页面,并向用户显示他已被强制注销的错误消息。
到目前为止,我已经编写了以下代码,成功将用户注销到登录页面。
try {
vaadinSession.lock(); //The session to be forcefully logged out
try {
vaadinSession.getUIs().forEach(ui -> {
if (ui.getPage() != null) {
ui.getPage().setLocation("");
ui.push();
Notification notification = new Notification("You have been forcefully logged out", Notification.Type.WARNING_MESSAGE);
notification.setDelayMsec(-1);
notification.show(ui.getPage());
ui.push();
}
});
} catch (Exception e) {
logger.error("Exception triggered when redirecting pages on forceDisconnect " + e.getLocalizedMessage(), e);
}
vaadinSession.close();
} finally {
vaadinSession.unlock();
}
但是,代码中显示的通知实际上并未显示给用户。我认为这是因为在调用 vaadinSession.close(); 时会创建一个新的 Vaadin 会话。如果我在新的 vaadin 会话中显示通知,我认为它会成功显示。
但是,我不知道在拨打vaadinSession.close(); 后如何访问新会话。
有人可以告诉我如何实现这一目标吗?
【问题讨论】: