當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletRequest.getRemoteAddr方法代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletRequest.getRemoteAddr方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletRequest.getRemoteAddr方法的具體用法?Java HttpServletRequest.getRemoteAddr怎麽用?Java HttpServletRequest.getRemoteAddr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.http.HttpServletRequest的用法示例。


在下文中一共展示了HttpServletRequest.getRemoteAddr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRemoteIp

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * Pulls the remote IP from the current HttpServletRequest, or grabs the value
 * for the specified alternative attribute (say, for proxied requests).  Falls
 * back to providing the "normal" remote address if no value can be retrieved
 * from the specified alternative header value.
 * @param context the context
 * @return the remote ip
 */
private String getRemoteIp(@NotNull final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    String userAddress = request.getRemoteAddr();
    logger.debug("Remote Address = {}", userAddress);

    if (StringUtils.isNotBlank(this.alternativeRemoteHostAttribute)) {

        userAddress = request.getHeader(this.alternativeRemoteHostAttribute);
        logger.debug("Header Attribute [{}] = [{}]", this.alternativeRemoteHostAttribute, userAddress);

        if (StringUtils.isBlank(userAddress)) {
            userAddress = request.getRemoteAddr();
            logger.warn("No value could be retrieved from the header [{}]. Falling back to [{}].",
                    this.alternativeRemoteHostAttribute, userAddress);
        }
    }
    return userAddress;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:27,代碼來源:BaseSpnegoKnownClientSystemsFilterAction.java

示例2: getIpAddr

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * 獲取ip工具類,除了getRemoteAddr,其他ip均可偽造
 * @param request
 * @return
 */
public static String getIpAddr(HttpServletRequest request) {
	String ip = request.getHeader("Cdn-Src-Ip");    // 網宿cdn的真實ip
	if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("HTTP_CLIENT_IP");   // 藍訊cdn的真實ip
	}
	if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("X-Forwarded-For");  // 獲取代理ip
	}
	if (ip == null || ip.length() == 0 || " unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("Proxy-Client-IP"); // 獲取代理ip
	}
	if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("WL-Proxy-Client-IP"); // 獲取代理ip
	}
	if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
		ip = request.getRemoteAddr(); // 獲取真實ip
	}
	return ip;
}
 
開發者ID:javay,項目名稱:zheng-lite,代碼行數:25,代碼來源:RequestUtil.java

示例3: address

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@RequestMapping(value = "/address", method = POST, consumes = APPLICATION_JSON_UTF8_VALUE,
        produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<AddressResponse> address(@Valid @RequestBody AddressRequest addressRequest,
                                               @Valid @Size(max = Constants.UUID_CHAR_MAX_SIZE) @RequestHeader(value="Authorization") String authorizationHeader,
                                               @Context HttpServletRequest httpServletRequest)
        throws BaseException {
    // Get token
    String emailConfirmationToken = getEmailConfirmationToken(authorizationHeader);

    // Get IP address from request
    String ipAddress = httpServletRequest.getHeader("X-Real-IP");
    if (ipAddress == null)
        ipAddress = httpServletRequest.getRemoteAddr();
    LOG.info("/address called from {} with token {}, address {}, refundBTC {} refundETH {}",
            ipAddress,
            emailConfirmationToken,
            addressRequest.getAddress(),
            addressRequest.getRefundBTC(),
            addressRequest.getRefundETH());

    return setWalletAddress(addressRequest, emailConfirmationToken);
}
 
開發者ID:modum-io,項目名稱:tokenapp-backend,代碼行數:23,代碼來源:AddressController.java

示例4: getRemoteIpAddress

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
private String getRemoteIpAddress(HttpServletRequest request) {
    String ip = request.getHeader(requestHeaderProperties.getCustomRemoteIp());
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("X-Forwarded-For");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_CLIENT_IP");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("HTTP_X_FORWARDED_FOR");
    }
    if (null == ip || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    return ip;
}
 
開發者ID:superkoh,項目名稱:k-framework,代碼行數:23,代碼來源:CommonInterceptor.java

示例5: getClientIp

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public static String getClientIp(HttpServletRequest request)
{
	String ip = request.getHeader("X-Real-IP");
	if(ip != null && ip.length() > 0 && !"null".equalsIgnoreCase(ip) && !"unKnown".equalsIgnoreCase(ip))
	{
		return ip;
	}
	ip = request.getHeader("X-Forwarded-For");
	if(ip != null && ip.length() > 0 && !"null".equalsIgnoreCase(ip) && !"unKnown".equalsIgnoreCase(ip))
	{
		// 多次反向代理後會有多個ip值,第一個ip才是真實ip
		int index = ip.indexOf(",");
		if(index != -1)
		{
			return ip.substring(0, index);
		}
		else
		{
			return ip;
		}
	}
	return request.getRemoteAddr();
}
 
開發者ID:skeychen,項目名稱:dswork,代碼行數:24,代碼來源:AuthController.java

示例6: toIpAddr

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * 返回用戶的IP地址
 */
public static String toIpAddr(HttpServletRequest request) {
	String ip = request.getHeader("x-forwarded-for");
	if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
		ip = request.getHeader("Proxy-Client-IP");
	}
	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;
}
 
開發者ID:Awesky,項目名稱:awe-awesomesky,代碼行數:17,代碼來源:CommonUtils.java

示例7: anyMethod

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@AfterThrowing(pointcut = "deptController() && anyMethod() " +
        "&& args(department, request)", throwing = "e")
public void handleAfterCreateDepartment(JoinPoint joinPoint,
                                        Department department, HttpServletRequest request, Throwable e) {
    int action = Integer.parseInt((((MethodSignature)joinPoint.getSignature())
            .getMethod()).getAnnotation(RequestMapping.class).name());
    AuditInfo auditRecord = new AuditInfo(department.getId(), null, request.getRemoteAddr(), department.toString(), action, e.getMessage());
    auditService.createRecord(auditRecord);
}
 
開發者ID:Witerium,項目名稱:stuffEngine,代碼行數:10,代碼來源:AuditHandler.java

示例8: constructCredentialsFromRequest

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Override
protected Credential constructCredentialsFromRequest(final RequestContext context) {
    final HttpServletRequest request = WebUtils.getHttpServletRequest(context);
    final String remoteAddress = request.getRemoteAddr();

    if (StringUtils.hasText(remoteAddress)) {
        return new RemoteAddressCredential(remoteAddress);
    }

    logger.debug("No remote address found.");
    return null;
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:13,代碼來源:RemoteAddressNonInteractiveCredentialsAction.java

示例9: testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithCustomValues

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Test
public void testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithCustomValues() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");
    filterDef.addInitParameter("remoteIpHeader", "x-my-forwarded-for");
    filterDef.addInitParameter("httpServerPort", "8080");

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.0.10");
    request.setSecure(true);
    request.setScheme("https");
    request.setHeader("x-my-forwarded-for", "140.211.11.130");
    request.setHeader("x-forwarded-proto", "http");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    boolean actualSecure = actualRequest.isSecure();
    assertFalse("request must be unsecured as header x-forwarded-proto said it is http", actualSecure);

    String actualScheme = actualRequest.getScheme();
    assertEquals("scheme must be http as header x-forwarded-proto said it is http", "http", actualScheme);

    int actualServerPort = actualRequest.getServerPort();
    assertEquals("wrong http server port", 8080, actualServerPort);

    String actualRemoteAddr = actualRequest.getRemoteAddr();
    assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);

    String actualRemoteHost = actualRequest.getRemoteHost();
    assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:35,代碼來源:TestRemoteIpFilter.java

示例10: getIpAddr

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
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");
    }
    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;
}
 
開發者ID:Yunfeng,項目名稱:weixinpay,代碼行數:14,代碼來源:HomeController.java

示例11: getIpAddr

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public 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");      
	   }      
	   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;      
}
 
開發者ID:topicquests,項目名稱:backside-servlet-ks,代碼行數:14,代碼來源:BaseHandler.java

示例12: getId

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
/**
 * The ID that will identify the limit: the user login or the user IP address.
 */
private String getId(HttpServletRequest httpServletRequest) {
    String login = SecurityUtils.getCurrentUserLogin();
    if (login != null) {
        return login;
    } else {
        return httpServletRequest.getRemoteAddr();
    }
}
 
開發者ID:oktadeveloper,項目名稱:jhipster-microservices-example,代碼行數:12,代碼來源:RateLimitingFilter.java

示例13: login

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@GetMapping
public ModelAndView login(HttpServletRequest request) {
    log.info("Inside login method:: ");
    String ipAddress = request.getRemoteAddr();
    log.info("ipAddress from request: " + ipAddress);
    loginObj = new Login();
    loginObj.setClientIpAddress(ipAddress);
    return new ModelAndView("login", "loginObj", loginObj);
}
 
開發者ID:Mahidharmullapudi,項目名稱:timesheet-upload,代碼行數:10,代碼來源:LoginController.java

示例14: filterAroundHandling

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
@Around("init()")
public Object filterAroundHandling(ProceedingJoinPoint joinPoint) throws Throwable {
  log.debug("around handing");
  //action
  MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
  Method action = methodSignature.getMethod();
  //接收到請求,記錄請求內容
  ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
  HttpServletRequest request = attributes.getRequest();
  //流控
  String clientIp = request.getRemoteAddr();
  String sessionId = request.getSession().getId();
  String requestUri = request.getRequestURI();
  String requestMethod = request.getMethod();
  long requestTimestamp = System.currentTimeMillis();
  flowControlService.flowController(clientIp, sessionId, requestUri, requestMethod, requestTimestamp, action.getDeclaredAnnotation(FlowControl.class));
  //過濾參數
  Map<String, String[]> filterParam = filterParamService.filterParam(request.getParameterMap(), action.getDeclaredAnnotation(FilterParam.class));
  //觸發action, 完成參數校驗部分
  Object object = joinPoint.proceed();
  log.debug("local response: {}", object);
  //透傳
  PipeConfig pipeConfig = action.getAnnotation(PipeConfig.class);
  if (pipeConfig != null) {
    object = penetrationService.penetrate(request, action, methodSignature.getDeclaringType(), filterParam);
  }
  log.debug("penetration response: {}", object);
  return object;
}
 
開發者ID:chuangxian,項目名稱:lib-edge,代碼行數:30,代碼來源:BeforeControllerAdvice.java

示例15: preGetDocument

import javax.servlet.http.HttpServletRequest; //導入方法依賴的package包/類
public void preGetDocument() throws EngineException {
	HttpServletRequest request = (HttpServletRequest) inputData;
	
	HttpUtils.checkCV(request);

	String remoteAddr = request.getRemoteAddr();
	Engine.logContext.info("Remote-Addr: \"" + remoteAddr + "\"");
	context.remoteAddr = remoteAddr;
	Log4jHelper.mdcPut(mdcKeys.ClientIP, remoteAddr);

	String remoteHost = "-";
	context.remoteHost = remoteHost;
	if (EnginePropertiesManager.getProperty(PropertyName.NET_REVERSE_DNS).equalsIgnoreCase("true")) {
		remoteHost = request.getRemoteHost();
		if (remoteHost != null) {
			context.remoteHost = remoteHost;
			Log4jHelper.mdcPut(mdcKeys.ClientHostName, context.remoteHost);
			Engine.logContext.info("Remote-Host: \"" + remoteHost + "\"");
		}
	}
	
	String contextID = context.contextID;
	Engine.logContext.debug("Context ID: " + contextID);

	String requestURI = request.getRequestURI();
	Engine.logContext.debug("Request URI: " + requestURI);

	String servletPath = request.getServletPath();
	Engine.logContext.debug("Servlet path: " + servletPath);
	context.servletPath = servletPath;

	String queryString = request.getQueryString();
	Engine.logContext.info("Query string: " + queryString);

	String userAgent = request.getHeader(HeaderName.UserAgent.value());
	Engine.logContext.info("User-Agent: \"" + userAgent + "\"");
	context.userAgent = userAgent;

	try {
		HttpSessionListener.checkSession(request);
	} catch (TASException e) {
		HttpUtils.terminateSession(request.getSession());
		throw new RuntimeException(e);
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:46,代碼來源:ServletRequester.java


注:本文中的javax.servlet.http.HttpServletRequest.getRemoteAddr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。