Example usage for com.vaadin.server VaadinSession getCurrent

List of usage examples for com.vaadin.server VaadinSession getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server VaadinSession getCurrent.

Prototype

public static VaadinSession getCurrent() 

Source Link

Document

Gets the currently used session.

Usage

From source file:com.haulmont.cuba.web.security.ConnectionImpl.java

License:Apache License

protected void setSessionInternal(ClientUserSession userSession) {
    VaadinSession.getCurrent().setAttribute(UserSession.class, userSession);
    if (userSession != null) {
        AppContext.setSecurityContext(new SecurityContext(userSession));
    } else {//from w  ww. java2s.c  o m
        AppContext.setSecurityContext(null);
    }
}

From source file:com.haulmont.cuba.web.security.listeners.LegacyLoginEventsForwarder.java

License:Apache License

protected boolean isTryLoginOnStart() {
    Object attribute = VaadinSession.getCurrent().getAttribute(LOGIN_ON_START_ATTRIBUTE);
    if (attribute != null) {
        return (Boolean) attribute;
    }/* www. j a  va  2 s.  co  m*/
    return true;
}

From source file:com.haulmont.cuba.web.security.listeners.LegacyLoginEventsForwarder.java

License:Apache License

protected void setTryLoginOnStart(boolean tryLoginOnStart) {
    VaadinSession.getCurrent().setAttribute(EXTERNAL_PRINCIPAL_ATTRIBUTE, tryLoginOnStart);
}

From source file:com.haulmont.cuba.web.security.listeners.LegacyLoginEventsForwarder.java

License:Apache License

protected Principal getSessionPrincipal() {
    return (Principal) VaadinSession.getCurrent().getAttribute(EXTERNAL_PRINCIPAL_ATTRIBUTE);
}

From source file:com.haulmont.cuba.web.security.listeners.LegacyLoginEventsForwarder.java

License:Apache License

protected void setSessionPrincipal(Principal principal) {
    VaadinSession.getCurrent().setAttribute(EXTERNAL_PRINCIPAL_ATTRIBUTE, principal);
}

From source file:com.haulmont.cuba.web.settings.WebSettingsClient.java

License:Apache License

public void clearCache() {
    VaadinSession session = VaadinSession.getCurrent();
    session.setAttribute(SettingsClient.NAME, null);
}

From source file:com.haulmont.cuba.web.settings.WebSettingsClient.java

License:Apache License

protected Map<String, Optional<String>> getCache() {
    VaadinSession session = VaadinSession.getCurrent();
    @SuppressWarnings("unchecked")
    Map<String, Optional<String>> settings = (Map<String, Optional<String>>) session
            .getAttribute(SettingsClient.NAME);
    if (settings == null) {
        settings = new ConcurrentHashMap<>();
        session.setAttribute(SettingsClient.NAME, settings);
    }/* w w  w  .j av  a 2s  .co  m*/
    return settings;
}

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

License:Apache License

@SuppressWarnings("deprecation")
@Override//  w ww  . ja  va2  s. c o  m
protected void handleAdditionalDependencies(List<Class<? extends ClientConnector>> newConnectorTypes,
        List<String> scriptDependencies, List<String> styleDependencies) {
    LegacyCommunicationManager manager = VaadinSession.getCurrent().getCommunicationManager();

    for (Class<? extends ClientConnector> connector : newConnectorTypes) {
        WebJarResource webJarResource = connector.getAnnotation(WebJarResource.class);
        if (webJarResource == null)
            continue;

        for (String uri : webJarResource.value()) {
            String resourceUri = processResourceUri(uri);
            String resourcePath = getResourceActualPath(resourceUri);

            resourcePath = resourcePath.replace(META_INF_PREFIX, VAADIN_PREFIX);

            if (resourcePath.endsWith(JAVASCRIPT_EXTENSION)) {
                scriptDependencies.add(manager.registerDependency(resourcePath, connector));
            }

            if (resourcePath.endsWith(CSS_EXTENSION)) {
                styleDependencies.add(manager.registerDependency(resourcePath, connector));
            }
        }
    }
}

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

License:Apache License

@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
    if (VaadinSession.getCurrent() == null || !VaadinSession.getCurrent().hasLock()) {
        throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread");
    }/*from   ww w.  j  a v  a2s . c o  m*/

    Object object = VaadinSession.getCurrent().getAttribute(name);
    if (object == null) {
        object = objectFactory.getObject();
        VaadinSession.getCurrent().setAttribute(name, object);
    }
    return object;
}

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

License:Apache License

@Override
public Object remove(String name) {
    if (VaadinSession.getCurrent() == null || !VaadinSession.getCurrent().hasLock()) {
        throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread");
    }/*from ww  w  . j a  v  a  2  s. c  om*/

    Object bean = VaadinSession.getCurrent().getAttribute(name);
    VaadinSession.getCurrent().setAttribute(name, null);
    return bean;
}