Example usage for com.vaadin.server VaadinServletRequest getRemoteAddr

List of usage examples for com.vaadin.server VaadinServletRequest getRemoteAddr

Introduction

In this page you can find the example usage for com.vaadin.server VaadinServletRequest getRemoteAddr.

Prototype

public String getRemoteAddr();

Source Link

Document

Returns the IP address from which the request came.

Usage

From source file:org.lucidj.vaadinui.BaseVaadinUI.java

License:Apache License

private void init_desktop(VaadinRequest vaadinRequest) {
    Responsive.makeResponsive(this);
    setLocale(vaadinRequest.getLocale());

    if (vaadinRequest instanceof VaadinServletRequest) {
        VaadinServletRequest vsr = (VaadinServletRequest) vaadinRequest;
        InetAddress remote_addr = null;

        // TODO: USE AUTOMATIC KEY AUTHENTICATION FOR SINGLE MODE
        try {//from  w  w  w  .jav  a2  s  . c  om
            remote_addr = InetAddress.getByName(vsr.getRemoteAddr());
        } catch (UnknownHostException ignore) {
        }
        ;

        // Login tokens may be used only when browsing from the same machine
        if (remote_addr != null && remote_addr.isLoopbackAddress()
                && Login.isValidLoginToken(vsr.getParameter("token"))) {
            // Autologin into System when browsing from localhost
            log.warn("Automatic login from localhost using login token");
            security.createSystemSubject();

            // Erase the token from URL
            getPage().getJavaScript().execute("window.lucidj_vaadin_helper.clearUrl ()");
        }
    }

    if (!security.getSubject().isAuthenticated()) {
        setContent(new Login(security, new Login.LoginListener() {
            @Override
            public void loginSuccessful() {
                show_desktop();
            }
        }));
    } else {
        show_desktop();
    }
}