Search in sources :

Example 16 with NoUserSessionException

use of com.haulmont.cuba.security.global.NoUserSessionException in project cuba by cuba-platform.

the class FileUploadController method getSession.

protected UserSession getSession(HttpServletRequest request, HttpServletResponse response) {
    UUID sessionId;
    try {
        sessionId = UUID.fromString(request.getParameter("s"));
    } catch (Exception e) {
        return null;
    }
    AppContext.setSecurityContext(new SecurityContext(sessionId));
    try {
        return userSessionService.getUserSession(sessionId);
    } catch (NoUserSessionException e) {
        return null;
    } finally {
        AppContext.setSecurityContext(null);
    }
}
Also used : SecurityContext(com.haulmont.cuba.core.sys.SecurityContext) UUID(java.util.UUID) FileStorageException(com.haulmont.cuba.core.global.FileStorageException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Example 17 with NoUserSessionException

use of com.haulmont.cuba.security.global.NoUserSessionException 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

NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)17 UserSession (com.haulmont.cuba.security.global.UserSession)9 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)6 IOException (java.io.IOException)3 UUID (java.util.UUID)3 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)2 RemoteException (com.haulmont.cuba.core.global.RemoteException)2 UserSessionService (com.haulmont.cuba.security.app.UserSessionService)2 HttpSession (javax.servlet.http.HttpSession)2 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 Messages (com.haulmont.cuba.core.global.Messages)1 Connection (com.haulmont.cuba.desktop.Connection)1 Type (com.haulmont.cuba.gui.components.DialogAction.Type)1 IllegalConcurrentAccessException (com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException)1 Icons (com.haulmont.cuba.gui.icons.Icons)1 App (com.haulmont.cuba.portal.App)1 Connection (com.haulmont.cuba.portal.Connection)1 PortalSession (com.haulmont.cuba.portal.security.PortalSession)1