Example usage for com.vaadin.server VaadinService getCurrentRequest

List of usage examples for com.vaadin.server VaadinService getCurrentRequest

Introduction

In this page you can find the example usage for com.vaadin.server VaadinService getCurrentRequest.

Prototype

public static VaadinRequest getCurrentRequest() 

Source Link

Document

Gets the currently processed Vaadin request.

Usage

From source file:annis.gui.tutorial.TutorialPanel.java

License:Apache License

public TutorialPanel() {
    setSizeFull();/*from w w  w . j  a  v  a2s.  c o  m*/

    String localBasePath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
    URI appURI = UI.getCurrent().getPage().getLocation();
    URI tutorialURI;

    String relativeFile = "/VAADIN/tutorial/index.html";

    try {
        String oldPath = VaadinService.getCurrentRequest().getContextPath();
        if (oldPath == null) {
            oldPath = "";
        }
        if (oldPath.endsWith("/")) {
            oldPath = oldPath.substring(0, oldPath.length() - 1);
        }
        tutorialURI = new URI(appURI.getScheme(), appURI.getUserInfo(), appURI.getHost(), appURI.getPort(),
                oldPath + relativeFile, null, null);
        embedded = new NavigateableSinglePage(new File(localBasePath + relativeFile), tutorialURI);
        embedded.setSizeFull();
        addComponent(embedded);

    } catch (URISyntaxException ex) {
        log.error("Invalid tutorial URI", ex);
    }

}

From source file:annis.libgui.Helper.java

License:Apache License

public static String getContext() {
    if (VaadinService.getCurrentRequest() != null) {
        return VaadinService.getCurrentRequest().getContextPath();
    } else {/*from w  w w  . java  2 s .  c  om*/
        return (String) VaadinSession.getCurrent().getAttribute(AnnisBaseUI.CONTEXT_PATH);
    }

}

From source file:biz.eelis.translation.TranslationSiteUI.java

License:Apache License

@Override
protected Site constructSite(final VaadinRequest request) {

    final ContentProvider contentProvider = this;

    final LocalizationProvider localizationProvider = new LocalizationProviderBundleImpl(
            new String[] { "translation-site-localization", "bare-site-localization" });
    BareSiteFields.initialize(localizationProvider, getLocale());
    TranslationSiteFields.initialize(localizationProvider, getLocale());

    final SiteContext siteContext = new SiteContext();
    final EntityManager entityManager = entityManagerFactory.createEntityManager();
    siteContext.putObject(EntityManager.class, entityManager);

    Company company = CompanyDao.getCompany(entityManager,
            ((VaadinServletRequest) VaadinService.getCurrentRequest()).getHttpServletRequest().getServerName());
    if (company == null) {
        // If no exact host match exists then try to find global company marked with *.
        company = CompanyDao.getCompany(entityManager, "*");
    }// w w  w. ja v  a  2  s.co m
    siteContext.putObject(Company.class, company);

    final SecurityProviderSessionImpl securityProvider = new SecurityProviderSessionImpl(
            Arrays.asList("administrator", "translator", "user"));

    return new Site(SiteMode.PRODUCTION, contentProvider, localizationProvider, securityProvider, siteContext);
}

From source file:com.antonjohansson.vaadin.recaptcha.Recaptcha.java

License:Apache License

private void checkResponse(String response) {
    if (verified.isPresent()) {
        throw new IllegalStateException("The response is already checked");
    }//from ww  w . j  a  va  2s  . c  o m

    String remoteAddress = VaadinService.getCurrentRequest().getRemoteAddr();
    RecaptchaVerifier verifier = new RecaptchaVerifier(secretKey, response, verifyURL, remoteAddress);
    boolean verified = verifier.isVerified();
    this.verified = Optional.of(verified);

    if (verified) {
        checkPassedListeners.forEach(CheckPassedListener::onCheckPassed);
    }
}

From source file:com.cerebro.gorgone.landingpage.Login.java

public Login() {
    InputStream iniFile = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/shiro.ini");
    if (iniFile == null) {
        logger.error("Il file Shiro.ini non esiste");
        return;//from   ww  w  . j a v a 2  s.c o m
    } else {
        logger.info("File Shiro.ini presente");
    }
    Ini ini = new Ini();
    ini.load(iniFile);
    Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory(ini);
    org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    email.focus();
    errorMessage.setVisible(false);
    this.addComponents(email, password, errorMessage, rememberMe, loginB);

    loginB.addClickListener((Button.ClickEvent e) -> {
        logger.info("Tentativo di connessione");
        Subject currentUser = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(email.getValue(), password.getValue());
        token.setRememberMe(rememberMe.getValue());
        try {
            currentUser.login(token);
            Session session = currentUser.getSession();
            User user = new User();
            user.loadUser();
            //session.setAttribute("User", user);
            getUI().setContent(new Game());
            VaadinService.reinitializeSession(VaadinService.getCurrentRequest());
        } catch (Exception ex) {
            logger.error(ex.toString());
            email.setValue("");
            password.setValue("");
            errorMessage.setVisible(true);
        }
    });
}

From source file:com.cerebro.provevaadin.Start.java

public Start() {

    InputStream iniFile = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/shiro.ini");
    if (iniFile == null) {
        logger.error("Il file Shiro.ini non esiste");
        return;//from   w w w.ja v a  2s  . co  m
    } else {
        logger.info("File presente");
    }
    Ini ini = new Ini();
    ini.load(iniFile);
    Factory<SecurityManager> factory = new IniSecurityManagerFactory(ini);
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    HorizontalLayout root = new HorizontalLayout();
    root.setWidth("800px");
    root.setHeight("600px");
    this.addComponent(root);
    this.setComponentAlignment(root, Alignment.MIDDLE_CENTER);

    FormLayout loginDiv = new FormLayout();
    root.addComponent(loginDiv);
    username.focus();
    errorMessage.setVisible(false);
    loginDiv.addComponents(username, password, rememberMe, login, errorMessage);

    login.addClickListener((Button.ClickEvent e) -> {
        logger.info("Pulsante: " + e.toString());
        Subject currentUser = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username.getValue(), password.getValue());
        token.setRememberMe(rememberMe.getValue());
        try {
            currentUser.login(token);
            if (currentUser.hasRole("firsttime")) {
                logger.info("Configurazione parametri del primo avvio");
                getUI().setContent(new FirstTime());
            } else {
                logger.info("Classe di gioco principale");
                getUI().setContent(new Game());
                VaadinService.reinitializeSession(VaadinService.getCurrentRequest());
            }
        } catch (Exception ex) {
            logger.error("Errore nel login: " + ex.getMessage());
            username.setValue("");
            password.setValue("");
            errorMessage.setVisible(true);
        }
    });

    FormLayout signInForm = new FormLayout();
    root.addComponent(signInForm);
    usernameSignIn.focus();
    sesso.addItems("Maschio", "Femmina");
    signInForm.addComponents(usernameSignIn, passwordSignIn, passwordConf, nome, cognome, sesso, eta, signIn);
    signIn.addClickListener((Button.ClickEvent event) -> {
        logger.info("Iscrizione al sito");
        User utente = new User();
        utente.setEmail(usernameSignIn.getValue());
        utente.setPassword(passwordSignIn.getValue());
        utente.setNomeUtente(nome.getValue());
        utente.setCognomeUtente(cognome.getValue());
        utente.setSessoUtente(sesso.getValue().toString());
        utente.setDataNascitaUtente(eta.getValue());
        SignIn signInWindow = new SignIn(utente);
        signInWindow.center();
        UI.getCurrent().addWindow(signInWindow);
    });

}

From source file:com.ejt.vaadin.loginform.LoginForm.java

License:Apache License

private void init() {
    if (initialized) {
        return;//w  ww.ja  va 2 s . c  om
    }

    LoginFormState state = getState();
    state.userNameFieldConnector = createUserNameField();
    state.passwordFieldConnector = createPasswordField();
    state.loginButtonConnector = createLoginButton();

    String contextPath = VaadinService.getCurrentRequest().getContextPath();
    if (contextPath.endsWith("/")) {
        contextPath = contextPath.substring(0, contextPath.length() - 1);
    }
    state.contextPath = contextPath;

    VaadinSession.getCurrent().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
                throws IOException {
            if (LoginFormConnector.LOGIN_URL.equals(request.getPathInfo())) {
                response.setContentType("text/html; charset=utf-8");
                response.setCacheTime(-1);
                PrintWriter writer = response.getWriter();
                writer.append("<html>Success</html>");
                return true;
            } else {
                return false;
            }
        }
    });

    registerRpc(new LoginFormRpc() {
        @Override
        public void submitCompleted() {
            login();
        }
    });

    initialized = true;

    setContent(createContent(getUserNameField(), getPasswordField(), getLoginButton()));
}

From source file:com.esofthead.mycollab.web.DesktopApplication.java

License:Open Source License

public Cookie getCookieByName(String name) {
    Cookie[] cookies = VaadinService.getCurrentRequest().getCookies();

    if (cookies != null) {
        // Iterate to find cookie by its name
        for (Cookie cookie : cookies) {
            if (name.equals(cookie.getName())) {
                return cookie;
            }/*ww w  .j  av  a 2s  .com*/
        }
    }

    return null;
}

From source file:com.hack23.cia.web.impl.ui.application.views.pageclicklistener.LogoutClickListener.java

License:Apache License

@Override
public void buttonClick(final ClickEvent event) {
    final ServiceResponse response = applicationManager.service(logoutRequest);

    if (ServiceResult.SUCCESS == response.getResult()) {
        UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
        UI.getCurrent().getSession().close();
        VaadinService.getCurrentRequest().getWrappedSession().invalidate();
    } else {//from   ww  w. ja  v  a 2 s.c  o m
        Notification.show(LOGOUT_FAILED, ERROR_MESSAGE, Notification.Type.WARNING_MESSAGE);
        LOGGER.info(LOG_MSG_LOGOUT_FAILURE, logoutRequest.getSessionId());
    }
}

From source file:com.haulmont.cuba.web.auth.IdpAuthProvider.java

License:Apache License

@Override
public void userSessionLoggedIn(UserSession session) {
    VaadinRequest currentRequest = VaadinService.getCurrentRequest();

    if (currentRequest != null) {
        Principal principal = currentRequest.getUserPrincipal();

        if (principal instanceof IdpSessionPrincipal) {
            IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession();
            session.setAttribute(IdpService.IDP_USER_SESSION_ATTRIBUTE, idpSession.getId());
        }//from  ww  w.  j  a v a  2 s .  co m
    }
}