List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:com.skysql.manager.ui.UsersSettings.java
License:Open Source License
public void windowClose(CloseEvent e) { // reload current UserInfo after possible adds and removes userInfo = new UserInfo(null); VaadinSession.getCurrent().setAttribute(UserInfo.class, userInfo); }
From source file:com.skysql.manager.validators.NodeNameValidator.java
License:Open Source License
public void validate(Object value) throws InvalidValueException { if (!isValid(value)) { throw new InvalidValueException("Name is invalid"); } else {/* ww w.j ava 2 s. c o m*/ OverviewPanel overviewPanel = VaadinSession.getCurrent().getAttribute(OverviewPanel.class); for (NodeInfo node : overviewPanel.getNodes()) { if (node.getName().equals(value) && !node.getName().equals(ourName)) { throw new InvalidValueException("Name already exists"); } } } }
From source file:com.skysql.manager.validators.SystemNameValidator.java
License:Open Source License
public void validate(Object value) throws InvalidValueException { if (!isValid(value)) { throw new InvalidValueException("Name is invalid"); } else {//from w w w. j av a 2s . co m SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class); if (!systemInfo.isNameUnique((String) value) && !value.equals(ourName)) { throw new InvalidValueException("Name already exists"); } } }
From source file:com.snowy.data.java
public String genToken(String username, String password) { if (login(username, password)) { String unameToke = username; for (int i = username.length(); i < 40; i++) { unameToke += "0"; }/* w ww.j a v a 2s.c o m*/ unameToke += "00000"; //uname 45 //ip = 15 111.111.111.111 String tok = ""; String address = Page.getCurrent().getWebBrowser().getAddress(); String addLat = ""; if (address.indexOf('.') != -1) { for (String i : address.split("\\.")) { if (i.length() < 3) { for (int x = i.length(); x < 3; x++) { i = "0" + i; } addLat += i; } else { addLat += i; } addLat += "."; } addLat = addLat.substring(0, addLat.length() - 1); } else { addLat = address; } int zz = 0; int bb = 0; for (int b = 0; b < 60; b++) { if (b % 4 == 0) { tok += addLat.charAt(bb); bb++; } else { tok += unameToke.charAt(zz); zz++; } } tok += System.currentTimeMillis() / 1000L; String hash = org.apache.commons.codec.digest.DigestUtils.sha256Hex(tok); hash += org.apache.commons.codec.digest.DigestUtils.sha256Hex(hash) + hash; VaadinSession.getCurrent().setAttribute("token", hash); try { //return hash; PreparedStatement ps = con .prepareStatement("update users set token = ?, active =1 where Username =?"); ps.setString(1, VaadinSession.getCurrent().getCsrfToken()); //ps.setString(1, "balls"); //ps.setString(2, "true"); ps.setString(2, username); ps.executeUpdate(); //ps.close(); //rs.close(); } catch (SQLException ex) { Logger.getLogger(data.class.getName()).log(Level.SEVERE, null, ex); } return hash; } else { return "false"; } }
From source file:com.snowy.data.java
public String getUsernameFromToken() { String s = ""; try {//from www . ja va 2 s.c om PreparedStatement ss = con.prepareStatement("select Username from users where token = ?"); ss.setString(1, VaadinSession.getCurrent().getCsrfToken()); ResultSet rs = ss.executeQuery(); rs.last(); if (rs.getRow() > 0) { s = rs.getString("Username"); } //ss.close(); //rs.close(); } catch (SQLException ex) { Logger.getLogger(data.class.getName()).log(Level.SEVERE, null, ex); } return s; }
From source file:com.snowy.MyVaadinUI.java
@Override protected void init(VaadinRequest request) { //d = new data(template); if (Page.getCurrent().getWebBrowser().isTooOldToFunctionProperly()) { Page.getCurrent().setLocation("https://www.google.com/chrome/browser/"); }//ww w.j a v a 2s . co m //VaadinService.getCurrent(). Page.getCurrent().setTitle("Connect 4"); d = new data(); //this.access(()->{ //n.addView("postLogin", new PostLoginView()); //Navigator n = this.getNavigator(); //n.addProvider(); //}); /* final TextField name = new TextField(); name.setCaption("Type your name here:"); Button button = new Button("Click Me"); button.addClickListener( e -> { layout.addComponent(new Label("Thanks " + name.getValue() + ", it works!")); }); */ JavaScript.getCurrent().addFunction("closeMyApplication", new JavaScriptFunction() { @Override public void call(JsonArray arguments) { //Logger.getLogger(MyVaadinUI.class.getName()).info(VaadinSession.getCurrent().getCsrfToken()); d.logout(VaadinSession.getCurrent().getCsrfToken()); //new data().setInActive(VaadinSession.getCurrent().getCsrfToken()); //VaadinSession.getCurrent().close(); } }); Page.getCurrent().getJavaScript().execute( "window.onbeforeunload = function (e) { var e = e || window.event; closeMyApplication(); return; };"); VaadinService.getCurrent().addSessionDestroyListener(e -> { //Logger.getLogger(MyVaadinUI.class.getName()).info(e.getSession().getCsrfToken()); d.logout(e.getSession().getCsrfToken()); }); //Navigator n = new Navigator(this,this); //n.addView("Main", new PostLoginView()); // this.setNavigator(n); //layout.setComponentAlignment(MainL, Alignment.TOP_CENTER); this.setPollInterval(1000); this.addPollListener((UIEvents.PollEvent e) -> { if (e.getUI().getContent().toString().contains("PostLoginView")) { PostLoginView plv = (PostLoginView) e.getUI().getContent(); d.resetActiveIfNot(); plv.getChatWindow().getUsersList().retrieveActiveUsers(); plv.getChatWindow().updateChats(); plv.getGameWindow().updateRequests(); plv.getGameWindow().updateGames(); plv.getGameWindow().checkForNewGames(); //Logger.getLogger(MyVaadinUI.class.getName()).log(Level.INFO,plv.getChatWindow().getUsersList().getValue().toString()); } }); Navigator navigator = new Navigator(this, this); navigator.addProvider(viewProvider); navigator.addViewChangeListener(new ViewChangeListener() { @Override public boolean beforeViewChange(ViewChangeListener.ViewChangeEvent event) { if (Page.getCurrent().getLocation().getPath().equals("/") || VaadinSession.getCurrent().getAttribute("token") != null) { return true; } else { //Notification.show(,Notification.Type.ERROR_MESSAGE); return false; } } @Override public void afterViewChange(ViewChangeListener.ViewChangeEvent event) { } }); /*UI.getCurrent().setErrorHandler(new DefaultErrorHandler(){ @Override public void error(com.vaadin.server.ErrorEvent event) { UI.getCurrent().setContent(new Label("error")); } });*/ //VaadinService.createCriticalNotificationJSON("","", "", ""); //navigator.setErrorView(navigator.getCurrentView()); //layout.setComponentAlignment(link, Alignment.MIDDLE_CENTER); //setContent(new Login()); }
From source file:com.snowy.PostLoginView.java
@PostConstruct void init() {//from w w w. j a va2 s. com //Logger.getLogger(PostLoginView.class.getName()).info(d); d = ((MyVaadinUI) UI.getCurrent()).getDataObject(); //Logger.getLogger(PostLoginView.class.getName()).info(d); g = new GameWindow(d); c = new ChatWindow(d); HorizontalLayout hl = new HorizontalLayout(); setMargin(true); /*this.getUI().addPollListener(new UIEvents.PollListener(){ @Override public void poll(UIEvents.PollEvent event) { c.getUsersList().retrieveActiveUsers(); } });*/ this.setSizeFull(); Button b = new Button("Logout"); b.addClickListener(e -> { d.logout(VaadinSession.getCurrent().getCsrfToken()); VaadinSession.getCurrent().close(); Page.getCurrent().setLocation("/"); }); Button ccc = new Button("Unpause polling"); ccc.setEnabled(false); Button cc = new Button("Pause polling"); cc.addClickListener(e -> { if (ccc.isEnabled() == false) { UI.getCurrent().setPollInterval(1000000000); cc.setEnabled(false); ccc.setEnabled(true); } }); ccc.addClickListener(e -> { if (cc.isEnabled() == false) { UI.getCurrent().setPollInterval(1000); cc.setEnabled(true); ccc.setEnabled(false); } }); hl.setSizeFull(); hl.setSpacing(true); //whdjwandjawd //this.addComponent(cc); //this.addComponent(ccc); this.addComponent(b); //this.setHeightUndefined(); this.setSpacing(true); this.setComponentAlignment(b, Alignment.TOP_RIGHT); //this.addComponent(c); //this.addComponent(ul); hl.addComponent(g); hl.addComponent(c); //this.addComponent(c); hl.setExpandRatio(c, 1); hl.setExpandRatio(g, 3); g.setSizeFull(); c.setSizeFull(); this.addComponent(hl); //this.setExpandRatio(g, 2); this.setExpandRatio(hl, 1); }
From source file:com.sonoport.MyUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { if (sessionState == null) { // This initialises the Spring Context from ContextConfiguration.java ApplicationContextLocator.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(this); }// w w w . j av a 2 s. c o m if (sessionState.isReplaceSession()) { // We've just been redirected back on session expiry sessionState.setVaadinSession(VaadinSession.getCurrent()); sessionState.setReplaceSession(false); } if (sessionState.staleSessionCheck(VaadinSession.getCurrent(), request)) { return; } getPage().setTitle("My UI"); this.setContent(layout); layout.setSizeFull(); Label testLabel = new Label("I'm a label"); layout.addComponent(testLabel); List<User> userList = this.userService.listAll(); LOG.info("ALL USERS : " + userList.toString()); }
From source file:com.terralcode.gestion.frontend.view.widgets.incomingAppointments.IncomingAppointments.java
private void loadAppointments() { Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); end.add(Calendar.YEAR, 1);/* w w w .ja va2s .c o m*/ //Un administrador puede ver todas las citas. Un comercial, slo las propias. User user = (User) VaadinSession.getCurrent().getAttribute(User.class.getName()); if (user.getRoleUser().equals("admin")) { appointmentList = appointmentService.find(start, end); } else if (user.getRoleUser().equals("trade")) { Trade trade = tradeService.findTradeByUser(user); if (trade != null) { appointmentList = appointmentService.findByTrade(trade, start, end); } } //Slo mostraremos las citas en estado PROGRAMADO List<Appointment> filteredAppointmentList = appointmentList.stream() .filter(p -> p.getStatus().getCode().equals("PRG")).collect(Collectors.toList()); filteredAppointmentList.sort(new Comparator() { @Override public int compare(Object o1, Object o2) { return (((Appointment) o1).getProgramDateStart()) .compareTo(((Appointment) o2).getProgramDateStart()); } }); setAppointments(filteredAppointmentList); }
From source file:com.toptal.conf.SecurityUtils.java
License:Open Source License
/** * Actual Vaadin user./*from w w w . j av a 2 s . c om*/ * @param dao User dao. * @return User. */ private static Optional<User> actualUserVaadin(final UserDao dao) { Optional<User> result = Optional.empty(); if (VaadinSession.getCurrent() != null) { final User user = VaadinSession.getCurrent().getAttribute(User.class); if (user != null) { result = Optional.ofNullable(dao.findOne(user.getId())); } } return result; }