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:me.uni.emuseo.service.AuthManager.java

License:Open Source License

public boolean isAuthorizedTo(String viewName, String parameters) {
    boolean authorized = false;
    // SecurityContext securityContext = SecurityContextHolder.getContext();
    // System.out.println(Thread.currentThread().getName()+ " Context " +
    // securityContext.hashCode());
    // Authentication authentication = securityContext.getAuthentication();
    Authentication authentication = (Authentication) VaadinSession.getCurrent().getAttribute("authentication");
    if (authentication != null && authentication.isAuthenticated()) {
        // String name = authentication.getName();
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        for (GrantedAuthority ga : authorities) {
            String authority = ga.getAuthority();
            authorized = authorized || viewPermission.isAuthorizedTo(authority, viewName, parameters);
        }/*from  w w w  .  ja  va 2s.c  o  m*/
    }
    return authorized;
}

From source file:me.uni.emuseo.service.AuthManager.java

License:Open Source License

public boolean isAuthorizedTo(String fullViewName) {
    boolean authorized = false;
    // SecurityContext securityContext = SecurityContextHolder.getContext();
    // System.out.println(Thread.currentThread().getName()+ " Context " +
    // securityContext.hashCode());
    // Authentication authentication = securityContext.getAuthentication();
    Authentication authentication = (Authentication) VaadinSession.getCurrent().getAttribute("authentication");
    if (authentication != null && authentication.isAuthenticated()) {
        // String name = authentication.getName();
        Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
        for (GrantedAuthority ga : authorities) {
            String authority = ga.getAuthority();
            authorized = authorized || viewPermission.isAuthorizedTo(authority, fullViewName);
        }/*from   w w  w . j a va  2s  .com*/
    }
    return authorized;
}

From source file:me.uni.emuseo.service.AuthManager.java

License:Open Source License

public UserDetailsDTO getUserDetails() {
    Authentication authentication = (Authentication) VaadinSession.getCurrent().getAttribute("authentication");
    if (authentication == null || authentication.getDetails() == null) {
        UserDetailsDTO userDetailsDTO = new UserDetailsDTO();
        setDefaultUserDetails(userDetailsDTO, null);
        return userDetailsDTO;
    }//from w  ww.  jav  a  2 s  . com
    UserDetailsDTO userDetailsDTO = (UserDetailsDTO) authentication.getDetails();
    return userDetailsDTO;
}

From source file:me.uni.emuseo.service.AuthManager.java

License:Open Source License

public void setUserDetails(UserDetailsDTO userDetailsDTO) {
    userDetailsService.setUserSettings(userDetailsDTO);
    UserDetailsDTO userDetails = userDetailsService.getUserDetails(userDetailsDTO.getUserId());
    setDefaultUserDetails(userDetails, null);
    AbstractAuthenticationToken authentication = (AbstractAuthenticationToken) VaadinSession.getCurrent()
            .getAttribute("authentication");
    authentication.setDetails(userDetails);
}

From source file:metacom.sprut7.AllPu.java

public void init() {
    statePlat = (StatePlat) VaadinSession.getCurrent().getAttribute("statePlat");
    linkRes = statePlat.getLinkRes();/*from w w  w.j  a  va2  s .com*/
    linkPool = statePlat.getLinkPool();
    this.idplat = statePlat.getIdPlat();

    setMargin(true);
    setHeight("100%");
    setStyleName("DolgiWindow");
    setSizeFull();

    pan = new Panel("?     ");
    pan.setWidth("100%");
    pan.setHeight("585px");

    BuildMain();
    addComponent(pan);
    setImmediate(true);
}

From source file:metacom.sprut7.HistoryNalNak.java

@Override
public void init() {
    statePlat = (StatePlat) VaadinSession.getCurrent().getAttribute("statePlat");
    linkRes = statePlat.getLinkRes();/*w w  w .ja  v  a2  s  .  c  o  m*/
    config = (Config) VaadinSession.getCurrent().getAttribute("config");
    this.idplat = statePlat.getIdPlat();
    linkPool = statePlat.getLinkPool();

    puthReady = config.getPathToReadyLS();
    try {
        nameKeystore = (String) VaadinSession.getCurrent().getAttribute("nameKeystore");
    } catch (Exception ex) {
        //    Logger.getLogger(LispReadySchets.class.getName()).log(Level.SEVERE, null, ex);
        Notification.show(
                "? ?   ? ?? ",
                Notification.Type.ERROR_MESSAGE);
    }
    keystore = config.getPathKeystore() + "\\" + nameKeystore;
    keystorePassword = config.getLispKeystorePasswords().get(nameKeystore);

    setMargin(true);
    setStyleName("DolgiWindow");
    BuildMain();
    setImmediate(true);
}

From source file:metacom.sprut7.Statistika.java

public void init(Integer idplat, short idVidActivn) {
    if (linkRes == null) {
        statePlat = (StatePlat) VaadinSession.getCurrent().getAttribute("statePlat");
        linkRes = statePlat.getLinkRes();
        //linkRes =(String) VaadinSession.getCurrent().getAttribute("linkRes");
    }//  w  w w  . j a  v  a  2  s. c  o m
    //linkRes = SprutVaadinApplication.getInstance().getLinkRes(); 
    WebStatist e;
    //dt = java.util.Calendar.getInstance().getTime(); 

    final Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(dt);
    int y = calendar.get(Calendar.YEAR);
    int m = calendar.get(Calendar.MONTH);
    int d = calendar.get(Calendar.DAY_OF_MONTH);
    calendar.clear();
    calendar.set(Calendar.YEAR, y);
    calendar.set(Calendar.MONTH, m);
    calendar.set(Calendar.DAY_OF_MONTH, d);
    dt = calendar.getTime();

    Integer NewID = null;
    EntityManager em = Persistence.createEntityManagerFactory(linkRes).createEntityManager();
    Date dt1 = new Date();
    Date dt2 = new Date();
    long l = dt.getTime();
    dt1.setTime(l - 2);
    dt2.setTime(l + 2);
    Collection emps = em.createQuery(
            "SELECT g FROM WebStatist g WHERE (g.idPlat = :idplat) and (g.dt between :dt1 AND :dt2) and (g.idVidActivn = :idVidActivn)")
            .setParameter("idplat", idplat).setParameter("dt1", dt1).setParameter("dt2", dt2)
            .setParameter("idVidActivn", idVidActivn).setMaxResults(1).getResultList();
    Boolean recordExists = !emps.isEmpty();
    em.getTransaction().begin();
    if (recordExists) {
        Iterator it = emps.iterator();
        e = (WebStatist) it.next();
        e.setCount(e.getCount() + 1);
    } else {
        EntityManager emKey = Persistence.createEntityManagerFactory(linkRes).createEntityManager();
        //           Collection empsKey = em.createQuery("SELECT g FROM GsgWebViewGetkeyStatist g WHERE 1=1").
        Collection empsKey = emKey.createQuery("SELECT g FROM GsgWebViewGetkeyStatist g").getResultList();
        //                 setMaxResults(1).getResultList();
        Boolean keyExists = !empsKey.isEmpty();
        if (keyExists) {
            Iterator itKey = empsKey.iterator();
            GsgWebViewGetkeyStatist eKey = (GsgWebViewGetkeyStatist) itKey.next();
            NewID = eKey.getId();
        }
        emKey.close();
        e = new WebStatist();
        e.setIdPlat(idplat);
        e.setCount(1);
        e.setDt(dt);
        e.setIdVidActivn(idVidActivn);
        e.setIdStatist(NewID);
        emps.add(e);
    }
    em.persist(e);
    em.getTransaction().commit();
    em.close();
}

From source file:net.gvcc.jgoffice.system.factories.DBNavigatorBarFactory.java

public static DbNavigatorBar getInstance() {

    if (VaadinSession.getCurrent().getAttribute(SESSION_SCOPED_VALUE_ID1) == null) {
        try {//from   w  w  w .j  a  v a2  s.  c om
            VaadinSession.getCurrent().lock();
            VaadinSession.getCurrent().setAttribute(SESSION_SCOPED_VALUE_ID1, new DbNavigatorBar());

        } finally {
            VaadinSession.getCurrent().unlock();
        }
    }

    return (DbNavigatorBar) VaadinSession.getCurrent().getAttribute(SESSION_SCOPED_VALUE_ID1);
}

From source file:net.gvcc.jgoffice.system.factories.SearchBarFactory.java

public static SearchComponent getInstance() {

    if (VaadinSession.getCurrent().getAttribute(SESSION_SCOPED_VALUE_ID) == null) {
        try {/*w w  w .ja v  a  2 s.  c o  m*/
            VaadinSession.getCurrent().lock();
            VaadinSession.getCurrent().setAttribute(SESSION_SCOPED_VALUE_ID, new SearchComponent());

        } finally {
            VaadinSession.getCurrent().unlock();
        }
    }

    return (SearchComponent) VaadinSession.getCurrent().getAttribute(SESSION_SCOPED_VALUE_ID);
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java

License:Apache License

/**
 * @param u the user to set//from   w  w w  .  j  a v  a  2s.  co m
 */
public void setUser(VMUserServer u) {
    this.user = u;
    if (user != null) {
        user.update();
        if (SESSIONS.containsValue(user.getId())) {
            Notification.show(TRANSLATOR.translate("message.already.logged"),
                    TRANSLATOR.translate("message.already.logged.desc"), Notification.Type.ERROR_MESSAGE);
            this.user = null;
        } else {
            LOG.log(Level.FINE, "Adding session {1} for user: {0}",
                    new Object[] { user.toString(), VaadinSession.getCurrent().getSession().getId() });
            SESSIONS.put(VaadinSession.getCurrent().getSession().getId(), user.getId());
            try {
                user.write2DB();
            } catch (VMException ex) {
                LOG.log(Level.SEVERE, null, ex);
            }
            Locale l;
            if (user.getLocale() == null) {
                //Default locale
                l = Locale.ENGLISH;
                user.setLocale(l.getLanguage());
                try {
                    user.write2DB();
                } catch (VMException ex) {
                    LOG.log(Level.SEVERE, null, ex);
                }
            } else {
                l = new Locale(user.getLocale());
            }
            setLocale(l);
        }
    }
    updateScreen();
}