Vaadin closes the user interface of the same user in another browser / tab / system

I am doing a project in Vaadin 7. In this I need to implement something like below to enter.

User "A" logs in to system "1". And again he enters another system "2". Now I want to know how to close the user interface on system "1".

I tried something and can close the user interface if it is the same browser. But for different systems / browsers. I have no idea.

My code is:

private void closeUI(String attribute) {
        for (UI ui : getSession().getUIs()) {
            if(ui.getSession().getAttribute(attribute) != null)
                   if(ui.getSession().getAttribute(attribute).equals(attribute))
                         ui.close();

            }
}

Can someone help me with this?

+2
source share
1 answer

, , . , , , VaadinServlet ConcurrentHashmap, , SessionDestroyListener, . SessionInitListener, hashmap, , , , .

, - , , , :

public class SessionInfoServlet extends VaadinServlet {

  private static final ConcurrentHashMap<User, VaadinSession> userSessionInfo = new ConcurrentHashMap<>();

  // this could be called after login to save the session info
  public static void saveUserSessionInfo(User user, VaadinSession session) {
    VaadinSession oldSession = userSessionInfo.get(user);
    if(oldSession != null){
      // close the old session
      oldSession.close();
    }
    userSessionInfo.put(user, session);
  }

  public static Map<User, VaadinSession> getUserSessionInfos() {
    // access the cache if we need to, otherwise useless and removable
    return userSessionInfo;
  }

  @Override
  protected void servletInitialized() throws ServletException {
    super.servletInitialized();
    // register our session destroy listener
    SessionLifecycleListener sessionLifecycleListener = new SessionLifecycleListener();
    getService().addSessionDestroyListener(sessionLifecycleListener);
  }

  private class SessionLifecycleListener implements SessionDestroyListener {
    @Override
    public void sessionDestroy(SessionDestroyEvent event) {
      // remove saved session from cache, for the user that was stored in it
      userSessionInfo.remove(event.getSession().getAttribute("user"));
    }
  }
}
+1

All Articles