Example usage for javax.servlet.http HttpServletRequest getRemoteAddr

List of usage examples for javax.servlet.http HttpServletRequest getRemoteAddr

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getRemoteAddr.

Prototype

public String getRemoteAddr();

Source Link

Document

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.

Usage

From source file:com.taobao.diamond.server.interceptor.ACLControlInterceptor.java

private String getRemoteIP(HttpServletRequest request) {
    String remoteIP = request.getRemoteAddr();
    if (remoteIP == null || remoteIP.equals("127.0.0.1")) {
        remoteIP = request.getHeader("X-Real-IP");
    }//from w ww  .ja v  a2 s .c o  m
    return remoteIP;
}

From source file:org.swarmcom.jsynapse.controller.client.api.v1.AuthenticationRestApi.java

@RequestMapping(value = "/login", method = POST)
public @ResponseBody AuthenticationResult login(@RequestBody final AuthenticationSubmission login,
        HttpServletRequest request) {
    login.setRemoteAddr(request.getRemoteAddr());
    return authenticationService.login(login);
}

From source file:fi.helsinki.opintoni.web.rest.privateapi.TestResource.java

@RequestMapping(value = "/whatismyip", method = RequestMethod.GET)
@Timed//from ww w.j ava 2 s .  c  om
public ResponseEntity<String> whatIsMyIp(HttpServletRequest httpServletRequest) {
    return new ResponseEntity<>(httpServletRequest.getRemoteAddr(), HttpStatus.OK);
}

From source file:org.swarmcom.jsynapse.controller.client.api.v1.AuthenticationRestApi.java

@RequestMapping(value = "/register", method = POST)
public @ResponseBody AuthenticationResult register(@RequestBody final AuthenticationSubmission registration,
        HttpServletRequest request) {
    registration.setRemoteAddr(request.getRemoteAddr());
    return authenticationService.register(registration);
}

From source file:fr.paris.lutece.util.http.SecurityUtil.java

/**
 * Get the IP of the user from a request. If the user is behind an apache
 * server, return the ip of the user instead of the ip of the server.
 * @param request The request//from   w w w .  ja v  a2  s  . com
 * @return The IP of the user that made the request
 */
public static String getRealIp(HttpServletRequest request) {
    String strIPAddress = request.getHeader(CONSTANT_HTTP_HEADER_X_FORWARDED_FOR);

    if (strIPAddress != null) {
        String strIpForwarded = null;

        while (!strIPAddress.matches(PATTERN_IP_ADDRESS) && strIPAddress.contains(CONSTANT_COMMA)) {
            strIpForwarded = strIPAddress.substring(0, strIPAddress.indexOf(CONSTANT_COMMA));
            strIPAddress = strIPAddress.substring(strIPAddress.indexOf(CONSTANT_COMMA))
                    .replaceFirst(CONSTANT_COMMA, StringUtils.EMPTY).trim();

            if ((strIpForwarded != null) && strIpForwarded.matches(PATTERN_IP_ADDRESS)) {
                strIPAddress = strIpForwarded;
            }
        }

        if (!strIPAddress.matches(PATTERN_IP_ADDRESS)) {
            strIPAddress = request.getRemoteAddr();
        }
    } else {
        strIPAddress = request.getRemoteAddr();
    }

    return strIPAddress;
}

From source file:nu.yona.server.DOSProtectionService.java

private String getKey(URI uri, HttpServletRequest request) {
    String key = request.getRemoteAddr() + "@" + uri.getPath();
    String query = uri.getQuery();
    if (query != null) {
        key += query;//from w w w.  j a v a2 s. com
    }
    return key;
}

From source file:com.sshdemo.common.security.web.authentication.rememberme.JPATokenBasedRememberMeService.java

protected String getUserIPAddress(HttpServletRequest request) {
    return request.getRemoteAddr();
}

From source file:com.core.util.wx.PayUtils.java

public static String getIpAddr(HttpServletRequest request) {
    String ip = request.getHeader("x-forwarded-for");
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }//from   ww  w.  j ava2  s .  c  om
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip;
}

From source file:com.wmanual.web.controller.ManualMyController.java

@RequestMapping("/selfinfo")
public String selfinfo(HttpServletRequest request) throws Exception {
    logger.info("[{}] visit wmanual for {} page", request.getRemoteAddr(), "selfinfo");
    return "my/selfinfo";
}

From source file:com.wmanual.web.controller.ManualMyController.java

@RequestMapping("/favorites")
public String favorites(HttpServletRequest request) throws Exception {
    logger.info("[{}] visit wmanual for {} page", request.getRemoteAddr(), "favorites");
    return "my/favorites";
}