List of usage examples for com.vaadin.server VaadinService getCurrentResponse
public static VaadinResponse getCurrentResponse()
From source file:annis.gui.CommonUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { super.init(request); getSession().addRequestHandler(new LoginServletRequestHandler(urlPrefix)); getSession().addRequestHandler(new ResourceRequestHandler(urlPrefix)); getSession().addRequestHandler(new BinaryRequestHandler(urlPrefix)); settings = new SettingsStorage(this); this.instanceConfig = getInstanceConfig(request); checkUrlShortenerRedirect(request, VaadinService.getCurrentResponse()); }
From source file:com.esofthead.mycollab.web.DesktopApplication.java
License:Open Source License
public void rememberPassword(String username, String password) { Cookie cookie = getCookieByName(DesktopApplication.NAME_COOKIE); String storeVal = username + "$" + PasswordEncryptHelper.encyptText(password); if (cookie == null) { cookie = new Cookie(DesktopApplication.NAME_COOKIE, storeVal); } else {// ww w . ja v a 2s .com cookie.setValue(storeVal); } cookie.setPath("/"); cookie.setMaxAge(60 * 60 * 24 * 7); VaadinService.getCurrentResponse().addCookie(cookie); }
From source file:com.esofthead.mycollab.web.DesktopApplication.java
License:Open Source License
public void unsetRememberPassword() { Cookie cookie = getCookieByName(DesktopApplication.NAME_COOKIE); if (cookie != null) { cookie.setValue(""); cookie.setPath("/"); cookie.setMaxAge(0);//from w w w . j a va 2 s .c o m VaadinService.getCurrentResponse().addCookie(cookie); } }
From source file:com.haulmont.cuba.web.DefaultApp.java
License:Apache License
protected void redirectAfterLogout(String loggedOutUrl) { if (!Strings.isNullOrEmpty(loggedOutUrl)) { AppUI currentUi = AppUI.getCurrent(); // it can be null if we handle request in a custom RequestHandler if (currentUi != null) { currentUi.setContent(null);/*ww w .j a va2 s . co m*/ currentUi.getPage().setLocation(loggedOutUrl); } else { VaadinResponse response = VaadinService.getCurrentResponse(); try { ((VaadinServletResponse) response).getHttpServletResponse().sendRedirect(loggedOutUrl); } catch (IOException e) { log.error("Error on send redirect to client", e); } } VaadinSession vaadinSession = VaadinSession.getCurrent(); for (UI ui : vaadinSession.getUIs()) { if (ui != currentUi) { ui.access(() -> { ui.setContent(null); ui.getPage().setLocation(loggedOutUrl); }); } } } }
From source file:com.lst.deploymentautomation.vaadin.core.LspsUI.java
License:Open Source License
@Override public void setLocale(Locale locale) { super.setLocale(locale); Cookie localeCookie = new Cookie("l-locale-cookie", locale.toString()); localeCookie.setMaxAge(60 * 60 * 24 * 365); VaadinService.getCurrentResponse().addCookie(localeCookie); //redraw the navigation and user menu if (appLayout != null) { appLayout.localeChanged(locale); }//from w ww. j ava 2 s .com }
From source file:com.parship.roperty.ui.persistence.service.RopertyUiSession.java
License:Apache License
private static void createCookie(String key, String value, int ttl) { Cookie cookie = new Cookie(key, value); cookie.setMaxAge(ttl);/*w ww.j av a 2 s . co m*/ cookie.setPath(VaadinService.getCurrentRequest().getContextPath()); VaadinService.getCurrentResponse().addCookie(cookie); }
From source file:com.selzlein.lojavirtual.vaadin.core.LspsUI.java
License:Open Source License
@Override public void setLocale(Locale locale) { super.setLocale(locale); Cookie localeCookie = new Cookie("l-locale-cookie", locale.toString()); localeCookie.setMaxAge(60 * 60 * 24 * 365); VaadinService.getCurrentResponse().addCookie(localeCookie); }
From source file:com.snowy.Login.java
@PostConstruct void init() {//from ww w . j a v a 2s . c o m d = ((MyVaadinUI) UI.getCurrent()).getDataObject(); //Logger.getLogger(Login.class.getName()).info(d); this.setSizeFull(); this.setSpacing(false); this.setMargin(true); Label MainL = new Label("<h1>Connect 4</h1?>", ContentMode.HTML); //layout.addComponent(MainL); MainL.setSizeUndefined(); VerticalLayout lay = new VerticalLayout(); lay.setMargin(false); lay.addComponent(MainL); lay.setComponentAlignment(MainL, Alignment.TOP_CENTER); HorizontalLayout hz = new HorizontalLayout(); hz.setMargin(false); hz.setSpacing(false); LoginForm lf = new LoginForm(); lf.addLoginListener((e) -> { String token = d.genToken(e.getLoginParameter("username"), e.getLoginParameter("password")); //String token="true"; if (!token.equals("false")) { Cookie c = new Cookie("token", token); VaadinService.getCurrentResponse().addCookie(c); //https://vaadin.com/wiki/-/wiki/Main/Setting+and+reading+Cookies //Notification.show(VaadinService.getCurrentRequest().getCookies()[1].getValue(),Notification.Type.ERROR_MESSAGE); //this.getNavigator().navigateTo("main"); //this.getUI().get this.getUI().getNavigator().navigateTo("main"); } else { Label l = new Label("<h4 style=\"color:red\">Invalid Username or Password</h4>", ContentMode.HTML); l.setId("created"); if (lay.getComponent(lay.getComponentIndex(lf) + 1).getId() == null) { //lay.addComponent(new Label(String.valueOf(lay.getComponentIndex(l)))); lay.addComponent(l, lay.getComponentIndex(lf) + 1); l.setSizeUndefined(); lay.setComponentAlignment(l, Alignment.TOP_CENTER); } } }); lay.addComponent(lf); Button newUser = new Button("New User"); newUser.addClickListener((e) -> { this.getUI().addWindow(new NewUserSubWindow(d)); }); //newUser.setWidth((float)5.5, Unit.EM); Button forgotPass = new Button("Forgot Password"); //temp forgotPass.addClickListener((e) -> { //Notification.show(, Notification.Type.ERROR_MESSAGE); }); forgotPass.setEnabled(false); forgotPass.setDescription("Feature Disabled, Contact Administrator for Assistance"); //forgotPass.setWidth((float) 8.5,Unit.EM); forgotPass.setStyleName(ValoTheme.BUTTON_LINK); newUser.setStyleName(ValoTheme.BUTTON_LINK); hz.addComponent(newUser); hz.addComponent(forgotPass); lay.addComponent(hz); lay.setComponentAlignment(lf, Alignment.TOP_CENTER); lay.setComponentAlignment(hz, Alignment.MIDDLE_CENTER); this.addComponent(lay); this.setComponentAlignment(lay, Alignment.MIDDLE_CENTER); }
From source file:de.metas.procurement.webui.service.impl.LoginRememberMeService.java
License:Open Source License
private void createRememberMeCookie(final User user) { try {/*from w ww .j a va 2 s .c om*/ final String rememberMeToken = createRememberMeToken(user); final Cookie rememberMeCookie = new Cookie(COOKIENAME_RememberMe, rememberMeToken); final int maxAge = (int) TimeUnit.SECONDS.convert(cookieMaxAgeDays, TimeUnit.DAYS); rememberMeCookie.setMaxAge(maxAge); final String path = "/"; // (VaadinService.getCurrentRequest().getContextPath()); rememberMeCookie.setPath(path); VaadinService.getCurrentResponse().addCookie(rememberMeCookie); logger.debug("Cookie added for {}: {} (maxAge={}, path={})", user, rememberMeToken, maxAge, path); } catch (final Exception e) { logger.warn("Failed creating cookie for user: {}. Skipped.", user, e); } }
From source file:de.metas.procurement.webui.service.impl.LoginRememberMeService.java
License:Open Source License
private void removeRememberMeCookie() { try {/*from w ww . j a va2 s.c o m*/ Cookie cookie = getRememberMeCookie(); if (cookie == null) { return; } cookie = new Cookie(COOKIENAME_RememberMe, null); cookie.setValue(null); cookie.setMaxAge(0); // by setting the cookie maxAge to 0 it will deleted immediately cookie.setPath("/"); VaadinService.getCurrentResponse().addCookie(cookie); logger.debug("Cookie removed"); } catch (final Exception e) { logger.warn("Failed removing the cookie", e); } }