Example usage for com.vaadin.server VaadinSession getAttribute

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

Introduction

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

Prototype

public <T> T getAttribute(Class<T> type) 

Source Link

Document

Gets a stored attribute value.

Usage

From source file:org.ripla.web.internal.services.ControllerManager.java

License:Open Source License

@SuppressWarnings("unchecked")
private void setActiveMenuItem(final String inBundleName) {
    final VaadinSession lCurrentSession = VaadinSession.getCurrent();
    MenuItem lOldItem = null;/*from   w  w  w  . j a v a 2s  .  co  m*/
    try {
        lCurrentSession.getLockInstance().lock();
        lOldItem = (MenuItem) lCurrentSession.getAttribute(Constants.SA_ACTIVE_MENU);
    } finally {
        lCurrentSession.getLockInstance().unlock();
    }

    if (lOldItem != null) {
        lOldItem.setStyleName("");
    }
    Map<String, MenuItem> lMenuMap = null;
    try {
        lCurrentSession.getLockInstance().lock();
        lMenuMap = (Map<String, MenuItem>) lCurrentSession.getAttribute(Constants.SA_MENU_MAP);
    } finally {
        lCurrentSession.getLockInstance().unlock();
    }
    final MenuItem lNewItem = lMenuMap == null ? null : lMenuMap.get(inBundleName);
    if (lNewItem != null) {
        lNewItem.setStyleName(Constants.CSS_ACTIVE_MENU);
    }
    try {
        lCurrentSession.getLockInstance().lock();
        lCurrentSession.setAttribute(Constants.SA_ACTIVE_MENU, lNewItem);
    } finally {
        lCurrentSession.getLockInstance().unlock();
    }
}

From source file:org.vaadin.spring.security.internal.SecurityContextVaadinRequestListener.java

License:Apache License

@Override
public void onRequestStart(VaadinRequest request, VaadinResponse response) {
    final WrappedSession wrappedSession = request.getWrappedSession(false);
    VaadinSession session = null;
    if (wrappedSession != null) {
        session = VaadinSession.getForSession(request.getService(), wrappedSession);
    }//from   w ww .  j  a v  a  2 s . c  om

    SecurityContextHolder.clearContext();
    if (session != null) {
        logger.debug("Loading security context from VaadinSession {}", session);
        SecurityContext securityContext;
        session.lock();
        try {
            securityContext = (SecurityContext) session.getAttribute(SECURITY_CONTEXT_SESSION_ATTRIBUTE);
        } finally {
            session.unlock();
        }
        if (securityContext == null) {
            logger.debug("No security context found in VaadinSession {}", session);
        } else {
            logger.debug("Setting security context to {}", securityContext);
            SecurityContextHolder.setContext(securityContext);
        }
    } else {
        logger.debug("No VaadinSession available for retrieving the security context");
    }
}

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

License:Apache License

@Override
public void onRequestStart(VaadinRequest request, VaadinResponse response) {
    final WrappedSession wrappedSession = request.getWrappedSession(false);
    VaadinSession session = null;
    if (wrappedSession != null) {
        session = VaadinSession.getForSession(request.getService(), wrappedSession);
    }/* w ww  .java2 s  .c om*/

    SecurityContextHolder.clearContext();
    if (session != null) {
        logger.trace("Loading security context from VaadinSession {}", session);
        SecurityContext securityContext;
        session.lock();
        try {
            securityContext = (SecurityContext) session.getAttribute(SECURITY_CONTEXT_SESSION_ATTRIBUTE);
        } finally {
            session.unlock();
        }
        if (securityContext == null) {
            logger.trace("No security context found in VaadinSession {}", session);
        } else {
            logger.trace("Setting security context to {}", securityContext);
            SecurityContextHolder.setContext(securityContext);
        }
    } else {
        logger.trace("No VaadinSession available for retrieving the security context");
    }
}

From source file:org.vaadin.tori.util.InputCacheUtil.java

License:Apache License

@SuppressWarnings("unchecked")
private Map<Object, String> getSessionCache() {
    VaadinSession session = UI.getCurrent().getSession();
    if (session.getAttribute(INPUT_CACHE) == null) {
        session.setAttribute(INPUT_CACHE, new HashMap<Object, String>());
    }//from   w  w w  .j  a  va  2 s  .c  om
    return (Map<Object, String>) session.getAttribute(INPUT_CACHE);
}

From source file:uk.q3c.krail.core.shiro.DefaultSubjectProvider.java

License:Apache License

/**
 * Returns the subject for the application and thread which represents the
 * current user. The subject is always available; however it may represent an
 * anonymous user./* w w w .ja  v a 2s  . c  o  m*/
 *
 * @return the subject for the current application and thread
 *
 * @see SecurityUtils#getSubject()
 */
public Subject getSubject() {
    VaadinSession session = VaadinSession.getCurrent();

    // This should never happen, but just in case we'll check.
    if (session == null) {
        throw new IllegalStateException("Unable to locate VaadinSession " + "to store Shiro Subject.");
    }

    Subject subject = (Subject) session.getAttribute(SUBJECT_ATTRIBUTE);

    if (subject == null) {

        // Create a new subject using the configured security manager.
        subject = (new Subject.Builder(securityManager)).buildSubject();
        session.setAttribute(SUBJECT_ATTRIBUTE, subject);
    }
    return subject;
}

From source file:uk.q3c.krail.core.shiro.VaadinSessionManager.java

License:Apache License

@Override
public Session getSession(SessionKey key) throws SessionException {

    // Retrieve the VaadinSession for the current user.
    VaadinSession vaadinSession = sessionProvider.get();

    String attributeName = SESSION_ATTRIBUTE_PREFIX + key.getSessionId();

    if (vaadinSession != null) {
        // If we have a valid VaadinSession, try to get the Shiro Session.
        SimpleSession shiroSession = (SimpleSession) vaadinSession.getAttribute(attributeName);

        if (shiroSession != null) {

            // Make sure the Shiro Session hasn't been stopped or expired (i.e. the
            // user logged out).
            if (shiroSession.isValid()) {
                return shiroSession;
            } else {
                // This is an invalid or expired session so we'll clean it up.
                vaadinSession.setAttribute(attributeName, null);
            }//from  w w w  .  j av  a 2  s .c  o m
        }
    }

    return null;
}

From source file:xyz.iipster.security.VaadinSessionSecurityContextHolderStrategy.java

License:Apache License

@Override
public SecurityContext getContext() {
    VaadinSession session = getSession();
    SecurityContext context = session.getAttribute(SecurityContext.class);
    if (context == null) {
        context = createEmptyContext();//from  w ww.  j  a va 2s.  co m
        session.setAttribute(SecurityContext.class, context);
    }
    return context;
}