Search in sources :

Example 1 with SessionHeartbeatEvent

use of com.haulmont.cuba.web.security.events.SessionHeartbeatEvent in project cuba by cuba-platform.

the class AppUI method refresh.

@Override
protected void refresh(VaadinRequest request) {
    super.refresh(request);
    boolean sessionIsAlive = true;
    Connection connection = app.getConnection();
    if (connection.isAuthenticated()) {
        // Ping middleware session if connected
        log.debug("Ping middleware session");
        try {
            UserSession session = connection.getSession();
            if (session instanceof ClientUserSession && ((ClientUserSession) session).isAuthenticated()) {
                userSessionService.getUserSession(session.getId());
            }
        } catch (Exception e) {
            sessionIsAlive = false;
            app.exceptionHandlers.handle(new com.vaadin.server.ErrorEvent(e));
        }
        if (sessionIsAlive) {
            events.publish(new SessionHeartbeatEvent(app));
        }
    }
    if (sessionIsAlive) {
        events.publish(new UIRefreshEvent(this));
    }
}
Also used : ClientUserSession(com.haulmont.cuba.client.ClientUserSession) SessionHeartbeatEvent(com.haulmont.cuba.web.security.events.SessionHeartbeatEvent) ClientUserSession(com.haulmont.cuba.client.ClientUserSession) UserSession(com.haulmont.cuba.security.global.UserSession) LoginException(com.haulmont.cuba.security.global.LoginException) UIRefreshEvent(com.haulmont.cuba.web.events.UIRefreshEvent)

Example 2 with SessionHeartbeatEvent

use of com.haulmont.cuba.web.security.events.SessionHeartbeatEvent in project cuba by cuba-platform.

the class App method onHeartbeat.

/**
 * Called from heartbeat request. <br>
 * Used for ping middleware session and show session messages
 */
public void onHeartbeat() {
    Connection connection = getConnection();
    boolean sessionIsAlive = false;
    if (connection.isAuthenticated()) {
        // Ping middleware session if connected and show messages
        log.debug("Ping middleware session");
        try {
            String message = userSessionService.getMessages();
            sessionIsAlive = true;
            if (message != null) {
                message = message.replace("\n", "<br/>");
                getWindowManager().showNotification(message, Frame.NotificationType.ERROR_HTML);
            }
        } catch (NoUserSessionException ignored) {
        // ignore no user session exception
        } catch (Exception e) {
            log.warn("Exception while session ping", e);
        }
    }
    if (sessionIsAlive) {
        events.publish(new SessionHeartbeatEvent(this));
    }
}
Also used : SessionHeartbeatEvent(com.haulmont.cuba.web.security.events.SessionHeartbeatEvent) LoginException(com.haulmont.cuba.security.global.LoginException) IllegalConcurrentAccessException(com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Aggregations

LoginException (com.haulmont.cuba.security.global.LoginException)2 SessionHeartbeatEvent (com.haulmont.cuba.web.security.events.SessionHeartbeatEvent)2 ClientUserSession (com.haulmont.cuba.client.ClientUserSession)1 IllegalConcurrentAccessException (com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException)1 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 UIRefreshEvent (com.haulmont.cuba.web.events.UIRefreshEvent)1