Ejemplo n.º 1
0
  @Override
  public void enter(ViewChangeEvent event) {
    if (((MyUI) UI.getCurrent()).getLogged() == false) {
      getUI().getNavigator().navigateTo(MyUI.LOGIN_USER);
    }

    ((MyUI) UI.getCurrent()).setLogged(false);
    ((MyUI) UI.getCurrent()).setUserLogin(null);
    ((MyUI) UI.getCurrent()).setUserPass(null);
    ((MyUI) UI.getCurrent()).setUserId(-1);

    {
      Cookie newCookie = new Cookie("userLogin", "");
      newCookie.setComment("userLogin user");
      newCookie.setMaxAge(0);
      newCookie.setPath("/");
      VaadinService.getCurrentResponse().addCookie(newCookie);
      newCookie = new Cookie("userPass", "");
      newCookie.setComment("pass user");
      newCookie.setMaxAge(0);
      newCookie.setPath("/");
      VaadinService.getCurrentResponse().addCookie(newCookie);
      newCookie = new Cookie("userId", "");
      newCookie.setComment("id user");
      newCookie.setMaxAge(0);
      newCookie.setPath("/");
      VaadinService.getCurrentResponse().addCookie(newCookie);
    }

    getUI().getNavigator().navigateTo(MyUI.MAIN);
  }
Ejemplo n.º 2
0
  /**
   * Find the UI for the atmosphere resource, lock it and invoke the callback.
   *
   * @param resource the atmosphere resource for the current request
   * @param callback the push callback to call when a UI is found and locked
   */
  private void callWithUi(final AtmosphereResource resource, final PushEventCallback callback) {
    AtmosphereRequest req = resource.getRequest();
    VaadinServletRequest vaadinRequest = new VaadinServletRequest(req, service);
    VaadinSession session = null;

    service.requestStart(vaadinRequest, null);
    try {
      try {
        session = service.findVaadinSession(vaadinRequest);
      } catch (ServiceException e) {
        getLogger().log(Level.SEVERE, "Could not get session. This should never happen", e);
      } catch (SessionExpiredException e) {
        SystemMessages msg =
            service.getSystemMessages(
                ServletPortletHelper.findLocale(null, null, vaadinRequest), vaadinRequest);
        try {
          resource
              .getResponse()
              .getWriter()
              .write(
                  VaadinService.createCriticalNotificationJSON(
                      msg.getSessionExpiredCaption(),
                      msg.getSessionExpiredMessage(),
                      null,
                      msg.getSessionExpiredURL()));
        } catch (IOException e1) {
          getLogger().log(Level.WARNING, "Failed to notify client about unavailable session", e);
        }
        return;
      }

      session.lock();
      try {
        VaadinSession.setCurrent(session);
        // Sets UI.currentInstance
        final UI ui = service.findUI(vaadinRequest);
        if (ui == null) {
          // This a request through an already open push connection to
          // a UI which no longer exists.
          resource
              .getResponse()
              .getWriter()
              .write(UidlRequestHandler.getUINotFoundErrorJSON(service, vaadinRequest));
          // End the connection
          resource.resume();
          return;
        }

        callback.run(resource, ui);
      } catch (IOException e) {
        getLogger().log(Level.INFO, "An error occured while writing a push response", e);
      } finally {
        session.unlock();
      }
    } finally {
      service.requestEnd(vaadinRequest, null, session);
    }
  }
 @Override
 public void sessionDestroy(SessionDestroyEvent event) {
   VaadinRequest request = VaadinService.getCurrentRequest();
   HttpServletRequest httpRequest =
       request != null ? ((VaadinServletRequest) request).getHttpServletRequest() : null;
   getSecurityManager()
       .logout(
           new AuthorizationRequest(
               null, httpRequest, httpRequest != null ? httpRequest.getSession() : null));
 }
Ejemplo n.º 4
0
  /* (non-Javadoc)
   * @see com.mapping.configuration.ui.action.Action#exectuteAction()
   */
  @Override
  public void exectuteAction() {
    IkasanAuthentication ikasanAuthentication =
        (IkasanAuthentication)
            VaadinService.getCurrentRequest()
                .getWrappedSession()
                .getAttribute(DashboardSessionValueConstants.USER);

    VaadinService.getCurrentRequest()
        .getWrappedSession()
        .setAttribute(DashboardSessionValueConstants.USER, null);
    this.visibilityGroup.setVisible();
    this.editableGroup.setEditable(false);

    layout.removeComponent(this.logOutButton);
    layout.addComponent(this.loginButton, 2, 0);
    layout.addComponent(this.setupButton, 3, 0);
    layout.setComponentAlignment(this.setupButton, Alignment.MIDDLE_RIGHT);
    layout.setComponentAlignment(this.loginButton, Alignment.MIDDLE_RIGHT);
    this.layout.removeComponent(userLabel);

    VaadinSession vSession = VaadinSession.getCurrent();
    WrappedSession httpSession = vSession.getSession();

    this.navigationPanel.reset();

    // Invalidate HttpSession
    httpSession.invalidate();
    vSession.close();

    systemEventService.logSystemEvent(
        SystemEventConstants.DASHBOARD_LOGOUT_CONSTANTS,
        "User logging out: " + ikasanAuthentication.getName(),
        ikasanAuthentication.getName());

    // Redirect the user to the login/default Page
    Page.getCurrent().setLocation("/ikasan-dashboard");
  }
Ejemplo n.º 5
0
Archivo: MyUI.java Proyecto: kaczla/TAS
 void loadCookies() {
   Cookie[] cookies = VaadinService.getCurrentRequest().getCookies();
   for (Cookie cookie : cookies) {
     if ("userLogin".equals(cookie.getName()) && cookie.getValue().isEmpty() == false) {
       this.userLogin = cookie.getValue();
     } else if ("userPass".equals(cookie.getName()) && cookie.getValue().isEmpty() == false) {
       this.userPass = cookie.getValue();
     } else if ("userId".equals(cookie.getName()) && cookie.getValue().isEmpty() == false) {
       this.userId = Integer.parseInt(cookie.getValue());
     }
   }
   if (this.userId > 0 && this.userLogin.isEmpty() == false && this.userPass.isEmpty() == false) {
     this.logged = true;
   }
 }
  @Override
  public void sessionInit(SessionInitEvent event) throws ServiceException {
    // event.getSession().setErrorHandler(new UIErrorHandler());
    Cookie langCookie = null;
    if (event.getRequest() != null) {
      for (Cookie cookie : event.getRequest().getCookies())
        if (cookie.getName().equals(VWebCommonConstants.USER_LANGUAGE_APPCOOKIE)) {
          langCookie = cookie;
          break;
        }
    }

    if (langCookie == null) langCookie = createLanguageCookie(event.getRequest());
    event.getSession().setLocale(LocaleUtils.toLocale(langCookie.getValue()));
    VaadinService.getCurrentResponse().addCookie(langCookie);
  }
Ejemplo n.º 7
0
        @Override
        public void run(AtmosphereResource resource, UI ui) throws IOException {
          getLogger()
              .log(Level.FINER, "New push connection with transport {0}", resource.transport());
          resource.getResponse().setContentType("text/plain; charset=UTF-8");

          VaadinSession session = ui.getSession();
          if (resource.transport() == TRANSPORT.STREAMING) {
            // IE8 requires a longer padding to work properly if the
            // initial message is small (#11573). Chrome does not work
            // without the original padding...
            WebBrowser browser = session.getBrowser();
            if (browser.isIE() && browser.getBrowserMajorVersion() == 8) {
              resource.padding(LONG_PADDING);
            }

            // Must ensure that the streaming response contains
            // "Connection: close", otherwise iOS 6 will wait for the
            // response to this request before sending another request to
            // the same server (as it will apparently try to reuse the same
            // connection)
            resource.getResponse().addHeader("Connection", "close");
          }

          String requestToken =
              resource.getRequest().getParameter(ApplicationConstants.CSRF_TOKEN_PARAMETER);
          if (!VaadinService.isCsrfTokenValid(session, requestToken)) {
            getLogger()
                .log(
                    Level.WARNING,
                    "Invalid CSRF token in new connection received from {0}",
                    resource.getRequest().getRemoteHost());
            // Refresh on client side, create connection just for
            // sending a message
            sendRefreshAndDisconnect(resource);
            return;
          }

          resource.suspend();

          AtmospherePushConnection connection = new AtmospherePushConnection(ui);
          connection.connect(resource);

          ui.setPushConnection(connection);
        }
Ejemplo n.º 8
0
        @Override
        public void run(AtmosphereResource resource, UI ui) throws IOException {
          AtmosphereRequest req = resource.getRequest();

          AtmospherePushConnection connection = getConnectionForUI(ui);

          assert connection != null
              : "Got push from the client "
                  + "even though the connection does not seem to be "
                  + "valid. This might happen if a HttpSession is "
                  + "serialized and deserialized while the push "
                  + "connection is kept open or if the UI has a "
                  + "connection of unexpected type.";

          Reader reader = connection.receiveMessage(req.getReader());
          if (reader == null) {
            // The whole message was not yet received
            return;
          }

          // Should be set up by caller
          VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
          assert vaadinRequest != null;

          try {
            new ServerRpcHandler().handleRpc(ui, reader, vaadinRequest);
            connection.push(false);
          } catch (JSONException e) {
            getLogger().log(Level.SEVERE, "Error writing JSON to response", e);
            // Refresh on client side
            sendRefreshAndDisconnect(resource);
          } catch (InvalidUIDLSecurityKeyException e) {
            getLogger()
                .log(
                    Level.WARNING,
                    "Invalid security key received from {0}",
                    resource.getRequest().getRemoteHost());
            // Refresh on client side
            sendRefreshAndDisconnect(resource);
          }
        }
Ejemplo n.º 9
0
 /**
  * Sends a refresh message to the given atmosphere resource. Uses an AtmosphereResource instead of
  * an AtmospherePushConnection even though it might be possible to look up the
  * AtmospherePushConnection from the UI to ensure border cases work correctly, especially when
  * there temporarily are two push connections which try to use the same UI. Using the
  * AtmosphereResource directly guarantees the message goes to the correct recipient.
  *
  * @param resource The atmosphere resource to send refresh to
  */
 private static void sendRefreshAndDisconnect(AtmosphereResource resource) throws IOException {
   AtmospherePushConnection connection = new AtmospherePushConnection(null);
   connection.connect(resource);
   connection.sendMessage(VaadinService.createCriticalNotificationJSON(null, null, null, null));
   connection.disconnect();
 }