Search in sources :

Example 1 with App

use of com.haulmont.cuba.portal.App 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

App (com.haulmont.cuba.portal.App)1 Connection (com.haulmont.cuba.portal.Connection)1 PortalSession (com.haulmont.cuba.portal.security.PortalSession)1 UserSessionService (com.haulmont.cuba.security.app.UserSessionService)1 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)1 HttpSession (javax.servlet.http.HttpSession)1