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();
後訪問新會話。
有人可以指點我怎麼做到這一點?