Example usage for com.vaadin.server WrappedSession removeAttribute

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

Introduction

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

Prototype

public void removeAttribute(String name);

Source Link

Document

Removes the object bound with the specified name from this session.

Usage

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

License:Apache License

/**
 * Called to handle the link./* w w w  . j  a v a2  s  .c  o m*/
 */
public void handle() {
    try {
        String folderId = requestParams.get("folder");
        if (!StringUtils.isEmpty(folderId)) {
            AbstractSearchFolder folder = loadFolder(UUID.fromString(folderId));
            if (folder != null) {
                folders.openFolder(folder);
            } else {
                log.warn("Folder not found: {}", folderId);
            }
            return;
        }

        String screenName = requestParams.get("screen");
        if (screenName == null) {
            log.warn("ScreenId not found in request parameters");
            return;
        }

        WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
        final WindowInfo windowInfo = windowConfig.getWindowInfo(screenName);
        if (windowInfo == null) {
            log.warn("WindowInfo not found for screen: {}", screenName);
            return;
        }

        UUID userId = getUUID(requestParams.get("user"));
        UserSession userSession = app.getConnection().getSession();
        if (userSession == null) {
            log.warn("No user session");
            return;
        }

        if (!(userId == null || userSession.getCurrentOrSubstitutedUser().getId().equals(userId))) {
            substituteUserAndOpenWindow(windowInfo, userId);
        } else {
            openWindow(windowInfo, requestParams);
        }
    } catch (AccessDeniedException e) {
        accessDeniedHandler.handle(e, app.getWindowManager());
    } catch (NoSuchScreenException e) {
        noSuchScreenHandler.handle(e, app.getWindowManager());
    } catch (EntityAccessException e) {
        entityAccessExceptionHandler.handle(e, app.getWindowManager());
    } finally {
        VaadinRequest request = VaadinService.getCurrentRequest();
        WrappedSession wrappedSession = request.getWrappedSession();
        wrappedSession.removeAttribute(AppUI.LAST_REQUEST_PARAMS_ATTR);
        wrappedSession.removeAttribute(AppUI.LAST_REQUEST_ACTION_ATTR);
    }
}

From source file:org.opencms.ui.error.CmsErrorUI.java

License:Open Source License

/**
 * Reads the error attributes from current session.<p>
 *//*from w  w w.  j a  va2s . com*/
private void readErrorAttributes() {

    WrappedSession session = getSession().getSession();
    m_requestedPage = (String) session.getAttribute(PATH);
    m_throwable = (Throwable) session.getAttribute(THROWABLE);

    // remove the attributes after read to keep the session clean
    session.removeAttribute(THROWABLE);
    session.removeAttribute(PATH);
}

From source file:org.vaadin.spring.security.managed.DefaultVaadinManagedSecurity.java

License:Apache License

/**
 * Clears the session of all attributes except some internal Vaadin attributes and reinitializes it. If Websocket
 * Push is used, the session will never be reinitialized since this throws errors on at least
 * Tomcat 8./* w  ww.j  a va  2 s .c o  m*/
 */
protected void clearAndReinitializeSession() {
    final VaadinRequest currentRequest = VaadinService.getCurrentRequest();
    final UI currentUI = UI.getCurrent();
    if (currentUI != null) {
        final Transport transport = currentUI.getPushConfiguration().getTransport();
        if (Transport.WEBSOCKET.equals(transport) || Transport.WEBSOCKET_XHR.equals(transport)) {
            LOGGER.warn(
                    "Clearing and reinitializing the session is currently not supported when using Websocket Push.");
            return;
        }
    }
    if (currentRequest != null) {
        LOGGER.debug("Clearing the session");
        final WrappedSession session = currentRequest.getWrappedSession();
        final String serviceName = VaadinService.getCurrent().getServiceName();
        final Set<String> attributesToSpare = new HashSet<String>();
        attributesToSpare.add(serviceName + ".lock");
        attributesToSpare.add(VaadinSession.class.getName() + "." + serviceName);
        for (String s : currentRequest.getWrappedSession().getAttributeNames()) {
            if (!attributesToSpare.contains(s)) {
                LOGGER.trace("Removing attribute {} from session", s);
                session.removeAttribute(s);
            }
        }
        LOGGER.debug("Reinitializing the session {}", session.getId());
        VaadinService.reinitializeSession(currentRequest);
        LOGGER.debug("Session reinitialized, new ID is {}",
                VaadinService.getCurrentRequest().getWrappedSession().getId());
    } else {
        LOGGER.warn(
                "No VaadinRequest bound to current thread, could NOT clear/reinitialize the session after login");
    }
}