1
在我的vaadin web应用程序中,管理员用户应该能够强制注销当前登录的用户。当用户强制注销时,应立即将其重定向到登录页面,并向用户显示错误消息,表明他已被强制注销。强制注销vaadin中的用户。如何显示消息以强制注销用户
到目前为止,我已经编写了以下代码,它们已成功将用户注销到登录页面。
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();
后访问新会话。
有人可以指点我怎么做到这一点?