Example usage for com.vaadin.server WrappedSession setMaxInactiveInterval

List of usage examples for com.vaadin.server WrappedSession setMaxInactiveInterval

Introduction

In this page you can find the example usage for com.vaadin.server WrappedSession setMaxInactiveInterval.

Prototype

public void setMaxInactiveInterval(int interval);

Source Link

Document

Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.

Usage

From source file:com.haulmont.cuba.web.DefaultApp.java

License:Apache License

protected void preventSessionFixation(Connection connection, UserSession userSession) {
    if (connection.isAuthenticated() && !isLoggedInWithExternalAuth(userSession)
            && webConfig.getUseSessionFixationProtection() && VaadinService.getCurrentRequest() != null) {

        VaadinService.reinitializeSession(VaadinService.getCurrentRequest());

        WrappedSession session = VaadinSession.getCurrent().getSession();
        int timeout = webConfig.getHttpSessionExpirationTimeoutSec();
        session.setMaxInactiveInterval(timeout);

        HttpSession httpSession = session instanceof WrappedHttpSession
                ? ((WrappedHttpSession) session).getHttpSession()
                : null;//from   w w  w .j  a  v  a  2s .  co m
        log.debug("Session reinitialized: HttpSession={}, timeout={}sec, UserSession={}", httpSession, timeout,
                connection.getSession());
    }
}

From source file:com.haulmont.cuba.web.sys.CubaVaadinServletService.java

License:Apache License

public CubaVaadinServletService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration)
        throws ServiceException {
    super(servlet, deploymentConfiguration);

    Configuration configuration = AppBeans.get(Configuration.NAME);
    webConfig = configuration.getConfig(WebConfig.class);
    webAuthConfig = configuration.getConfig(WebAuthConfig.class);
    testMode = configuration.getConfig(GlobalConfig.class).getTestMode();

    ServletContext sc = servlet.getServletContext();
    String resourcesTimestamp = sc.getInitParameter("webResourcesTs");
    if (StringUtils.isNotEmpty(resourcesTimestamp)) {
        this.webResourceTimestamp = resourcesTimestamp;
    } else {/*w  w  w.ja v a2s.c o m*/
        this.webResourceTimestamp = "DEBUG";
    }

    addSessionInitListener(event -> {
        WrappedSession wrappedSession = event.getSession().getSession();
        wrappedSession.setMaxInactiveInterval(webConfig.getHttpSessionExpirationTimeoutSec());

        HttpSession httpSession = wrappedSession instanceof WrappedHttpSession
                ? ((WrappedHttpSession) wrappedSession).getHttpSession()
                : null;

        log.debug("HttpSession {} initialized, timeout={}sec", httpSession,
                wrappedSession.getMaxInactiveInterval());
    });

    addSessionDestroyListener(event -> {
        WrappedSession wrappedSession = event.getSession().getSession();
        HttpSession httpSession = wrappedSession instanceof WrappedHttpSession
                ? ((WrappedHttpSession) wrappedSession).getHttpSession()
                : null;

        log.debug("HttpSession destroyed: {}", httpSession);
        App app = event.getSession().getAttribute(App.class);
        if (app != null) {
            app.cleanupBackgroundTasks();
        }
    });

    setSystemMessagesProvider(systemMessagesInfo -> {
        Locale locale = systemMessagesInfo.getLocale();

        CustomizedSystemMessages msgs = new CustomizedSystemMessages();

        if (AppContext.isStarted()) {
            try {
                Messages messages = AppBeans.get(Messages.NAME);

                msgs.setInternalErrorCaption(messages.getMainMessage("internalErrorCaption", locale));
                msgs.setInternalErrorMessage(messages.getMainMessage("internalErrorMessage", locale));

                msgs.setCommunicationErrorCaption(messages.getMainMessage("communicationErrorCaption", locale));
                msgs.setCommunicationErrorMessage(messages.getMainMessage("communicationErrorMessage", locale));

                msgs.setSessionExpiredCaption(messages.getMainMessage("sessionExpiredErrorCaption", locale));
                msgs.setSessionExpiredMessage(messages.getMainMessage("sessionExpiredErrorMessage", locale));
            } catch (Exception e) {
                log.error("Unable to set system messages", e);
                throw new RuntimeException("Unable to set system messages. "
                        + "It usually happens when the middleware web application is not responding due to "
                        + "errors on start. See logs for details.", e);
            }
        }

        String redirectUri;
        if (RequestContext.get() != null) {
            HttpServletRequest request = RequestContext.get().getRequest();
            redirectUri = StringUtils.replace(request.getRequestURI(), "/UIDL", "");
        } else {
            String webContext = AppContext.getProperty("cuba.webContextName");
            redirectUri = "/" + webContext;
        }

        msgs.setInternalErrorURL(redirectUri + "?restartApp");

        return msgs;
    });
}

From source file:edu.nps.moves.mmowgli.modules.registrationlogin.RegistrationPageBase.java

License:Open Source License

@HibernateUpdate
@HibernateUserUpdate/*from ww w .j  ava2  s  .co m*/
private void wereInReallyTL(User _u_) {
    boolean updateneeded = false; // avoid db hit if possible

    if (currentPopup != null)
        UI.getCurrent().removeWindow(currentPopup); // app.getMainWindow().removeWindow(currentPopup);

    MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals();
    globs.setLoggedIn(true);

    if (_u_ != null) {
        Object cacId = CACManager.getCacId(globs.getCACInfo());
        if (cacId == null) {
            if (_u_.getCacId() != null) {
                _u_.setCacId(null);
                updateneeded = true;
            }
        } else if (!_u_.getCacId().equals(cacId.toString())) {
            _u_.setCacId(cacId.toString());
            updateneeded = true;
        }
        //_u_.setCacId(cacId == null? null :cacId.toString());
        if (!_u_.isWelcomeEmailSent()) {
            MailManager mmgr = AppMaster.instance().getMailManager();
            mmgr.onNewUserSignupTL(_u_);
            _u_.setWelcomeEmailSent(true);
            updateneeded = true;
        }
        // If we're here, we've either been email-confirmed or that is not necessary; make sure here
        if (!_u_.isEmailConfirmed()) {
            _u_.setEmailConfirmed(true);
            updateneeded = true;
        }

        // Adjust session timeouts.  Default (standard user) is set in web.xml
        VaadinSession vsess = UI.getCurrent().getSession();
        WrappedSession sess = vsess.getSession();
        if (_u_.isGameMaster())
            sess.setMaxInactiveInterval(GAMEMASTER_SESSION_TIMEOUT_SECONDS);
        if (_u_.isAdministrator())
            sess.setMaxInactiveInterval(ADMINSTRATOR_SESSION_TIMEOUT_SECONDS);

        MSysOut.println(SYSTEM_LOGS,
                "Vaadin heartbeat interval (sec): " + vsess.getConfiguration().getHeartbeatInterval());
        MSysOut.println(SYSTEM_LOGS,
                "Tomcat timeout (\"maxInactiveInterval\") (sec): " + sess.getMaxInactiveInterval());
        GameEventLogger.logUserLoginTL(_u_);
        if (updateneeded) {
            User.updateTL(_u_);
        }

        HSess.closeAndReopen(); // should be ok
        _u_ = User.merge(_u_, HSess.get());

        MmowgliController cntlr = globs.getController();
        if (cntlr != null)
            cntlr.handleEventTL(MmowgliEvent.HANDLE_LOGIN_STARTUP, _u_, null); //don't want User.get() in this session, userId, null);
        else
            System.err.println("No controller in RegistrationPageBase.wereIn()");

        AppMaster.instance().sendMySessionReport();
    }
}

From source file:makeithappen.vaadin.app.internal.servlet.VaadinOsgiUIProvider.java

License:Open Source License

@Override
public UI createInstance(UICreateEvent event) {
    final UI ui = super.createInstance(event);
    final WrappedSession session = VaadinSession.getCurrent().getSession();
    session.setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
    return ui;//from  w w  w  .  ja  v a2 s  .c o m
}