本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
示例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;
}
示例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);
}
}