Search in sources :

Example 6 with UserSessionService

use of com.haulmont.cuba.security.app.UserSessionService in project cuba by cuba-platform.

the class ClientUserSession method setTimeZone.

@Override
public void setTimeZone(TimeZone timeZone) {
    super.setTimeZone(timeZone);
    if (authenticated) {
        UserSessionService uss = AppBeans.get(UserSessionService.NAME);
        uss.setSessionTimeZone(id, timeZone);
    }
}
Also used : UserSessionService(com.haulmont.cuba.security.app.UserSessionService)

Example 7 with UserSessionService

use of com.haulmont.cuba.security.app.UserSessionService in project cuba by cuba-platform.

the class ClientUserSession method setClientInfo.

@Override
public void setClientInfo(String clientInfo) {
    super.setClientInfo(clientInfo);
    if (authenticated) {
        UserSessionService uss = AppBeans.get(UserSessionService.NAME);
        uss.setSessionClientInfo(id, clientInfo);
    }
}
Also used : UserSessionService(com.haulmont.cuba.security.app.UserSessionService)

Example 8 with UserSessionService

use of com.haulmont.cuba.security.app.UserSessionService in project cuba by cuba-platform.

the class SessionMessagesNotifier method syncMessages.

protected void syncMessages() {
    Connection connection = App.getInstance().getConnection();
    if (connection.isConnected()) {
        log.trace("Check session messages");
        asyncMessageLoader = new SwingWorker<String, Void>() {

            @Override
            protected String doInBackground() throws Exception {
                try {
                    UserSessionService uss = AppBeans.get(UserSessionService.NAME);
                    return uss.getMessages();
                } catch (NoUserSessionException e) {
                    log.warn("Unable to get messages for session, user session not found");
                } catch (Exception e) {
                    log.warn("Session messages exception: " + e.toString());
                }
                return null;
            }

            @Override
            protected void done() {
                try {
                    if (!isCancelled()) {
                        processServerMessage(get());
                    }
                } catch (InterruptedException | ExecutionException ignored) {
                // do nothing
                } finally {
                    asyncMessageLoader = null;
                }
            }
        };
        asyncMessageLoader.execute();
    }
}
Also used : UserSessionService(com.haulmont.cuba.security.app.UserSessionService) Connection(com.haulmont.cuba.desktop.Connection) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException) ExecutionException(java.util.concurrent.ExecutionException) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Example 9 with UserSessionService

use of com.haulmont.cuba.security.app.UserSessionService in project cuba by cuba-platform.

the class SecurityContextHandlerInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    // filter resource requests
    if (ClassUtils.isAssignableValue(ResourceHttpRequestHandler.class, handler)) {
        return true;
    }
    PortalSecurityContext portalSecurityContext;
    HttpSession httpSession = request.getSession();
    Connection connection = (Connection) httpSession.getAttribute(Connection.NAME);
    if (connection == null || connection.getSession() == null || !connection.isConnected()) {
        connection = AppBeans.get(Connection.NAME);
        connection.login(request.getLocale(), request.getRemoteAddr(), request.getHeader("User-Agent"));
        httpSession.setAttribute(Connection.NAME, connection);
        portalSecurityContext = new PortalSecurityContext(connection.getSession());
        AppContext.setSecurityContext(portalSecurityContext);
    } else {
        PortalSession session = connection.getSession();
        portalSecurityContext = new PortalSecurityContext(session);
        AppContext.setSecurityContext(portalSecurityContext);
        // ping only authenticated sessions
        if (session != null && session.isAuthenticated()) {
            UserSessionService userSessionSource = AppBeans.get(UserSessionService.NAME);
            try {
                userSessionSource.getMessages();
            } catch (NoUserSessionException e) {
                httpSession.invalidate();
                response.sendRedirect(request.getRequestURI());
                return false;
            }
        }
    }
    App app = new App(connection, request, response);
    portalSecurityContext.setPortalApp(app);
    return true;
}
Also used : App(com.haulmont.cuba.portal.App) HttpSession(javax.servlet.http.HttpSession) PortalSession(com.haulmont.cuba.portal.security.PortalSession) UserSessionService(com.haulmont.cuba.security.app.UserSessionService) Connection(com.haulmont.cuba.portal.Connection) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException)

Aggregations

UserSessionService (com.haulmont.cuba.security.app.UserSessionService)9 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)2 TimeSource (com.haulmont.cuba.core.global.TimeSource)1 Connection (com.haulmont.cuba.desktop.Connection)1 App (com.haulmont.cuba.portal.App)1 Connection (com.haulmont.cuba.portal.Connection)1 PortalSession (com.haulmont.cuba.portal.security.PortalSession)1 UserSessionEntity (com.haulmont.cuba.security.entity.UserSessionEntity)1 ExecutionException (java.util.concurrent.ExecutionException)1 HttpSession (javax.servlet.http.HttpSession)1