[英]How to execute code after vaadin login with spring
用戶正在設置語言,然后從 vaadin 登錄視圖登錄。 我需要將用戶設置的語言保存在數據庫中。
我嘗試使用 vaadin LoginForm 的 addLoginListener function。 這個問題是它在身份驗證完成之前觸發。 所以有人可以更改他知道用戶名的人的語言。
我還嘗試了 Spring 身份驗證事件。 這個問題是我無法訪問 vaadin session 我保存了應該在數據庫中編寫的語言。
您可以使用當前請求在身份驗證成功處理程序中找到您想要的VaadinSession
:
public class CustomAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
Optional<VaadinSession> maybeSession = VaadinSession.getAllSessions(
request.getSession()).stream().findFirst();
maybeSession.ifPresent(session -> {
session.accessSynchronously(/* do something with session */);
});
super.onAuthenticationSuccess(request, response, authentication);
}
}
這僅在您已經有一個現有的VaadinSession
; 如果您的登錄機制使用的不是 Vaadin UI(例如 SSO),那么 session 還不存在,事情會變得有點復雜。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.