本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getRemoteHost方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getRemoteHost方法的具体用法?Java HttpServletRequest.getRemoteHost怎么用?Java HttpServletRequest.getRemoteHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getRemoteHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithDefaultValues
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Test
public void testIncomingRequestIsSecuredButProtocolHeaderSaysItIsNotWithDefaultValues() throws Exception {
// PREPARE
FilterDef filterDef = new FilterDef();
filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("192.168.0.10");
request.setSecure(true);
request.setScheme("https");
request.setHeader("x-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);
String actualRemoteAddr = actualRequest.getRemoteAddr();
assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
String actualRemoteHost = actualRequest.getRemoteHost();
assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
示例2: 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);
}
示例3: testInvokeAllProxiesAreTrustedAndRemoteAddrMatchRegexp
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Test
public void testInvokeAllProxiesAreTrustedAndRemoteAddrMatchRegexp() throws Exception {
// PREPARE
FilterDef filterDef = new FilterDef();
filterDef.addInitParameter("internalProxies", "127\\.0\\.0\\.1|192\\.168\\..*|another-internal-proxy");
filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
request.addHeader("x-forwarded-for", "140.211.11.130");
request.addHeader("x-forwarded-for", "proxy1");
request.addHeader("x-forwarded-for", "proxy2");
// TEST
HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();
// VERIFY
String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1, proxy2", actualXForwardedBy);
String actualRemoteAddr = actualRequest.getRemoteAddr();
assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
String actualRemoteHost = actualRequest.getRemoteHost();
assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
示例4: testInvokeAllProxiesAreInternal
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Test
public void testInvokeAllProxiesAreInternal() throws Exception {
// PREPARE
FilterDef filterDef = new FilterDef();
filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
request.addHeader("x-forwarded-for", "140.211.11.130, 192.168.0.10, 192.168.0.11");
// TEST
HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();
// VERIFY
String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
assertNull("all proxies are internal, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
assertNull("all proxies are internal, x-forwarded-by must be null", actualXForwardedBy);
String actualRemoteAddr = actualRequest.getRemoteAddr();
assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
String actualRemoteHost = actualRequest.getRemoteHost();
assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
示例5: XForwardedRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public XForwardedRequest(HttpServletRequest request) {
super(request);
this.localPort = request.getLocalPort();
this.remoteAddr = request.getRemoteAddr();
this.remoteHost = request.getRemoteHost();
this.scheme = request.getScheme();
this.secure = request.isSecure();
this.serverPort = request.getServerPort();
headers = new HashMap<String, List<String>>();
for (Enumeration<String> headerNames = request.getHeaderNames(); headerNames.hasMoreElements();) {
String header = headerNames.nextElement();
headers.put(header, Collections.list(request.getHeaders(header)));
}
}
示例6: testInvokeAllowedRemoteAddrWithNullRemoteIpHeader
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Test
public void testInvokeAllowedRemoteAddrWithNullRemoteIpHeader() throws Exception {
// PREPARE
FilterDef filterDef = new FilterDef();
filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
// TEST
HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();
// VERIFY
String actualXForwardedFor = request.getHeader("x-forwarded-for");
assertNull("x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = request.getHeader("x-forwarded-by");
assertNull("x-forwarded-by must be null", actualXForwardedBy);
String actualRemoteAddr = actualRequest.getRemoteAddr();
assertEquals("remoteAddr", "192.168.0.10", actualRemoteAddr);
String actualRemoteHost = actualRequest.getRemoteHost();
assertEquals("remoteHost", "remote-host-original-value", actualRemoteHost);
}
示例7: testInvokeNotAllowedRemoteAddr
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Test
public void testInvokeNotAllowedRemoteAddr() throws Exception {
// PREPARE
FilterDef filterDef = new FilterDef();
filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("not-allowed-internal-proxy");
request.setRemoteHost("not-allowed-internal-proxy-host");
request.setHeader("x-forwarded-for", "140.211.11.130, proxy1, proxy2");
// TEST
HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();
// VERIFY
String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
assertEquals("x-forwarded-for must be unchanged", "140.211.11.130, proxy1, proxy2", actualXForwardedFor);
String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
assertNull("x-forwarded-by must be null", actualXForwardedBy);
String actualRemoteAddr = actualRequest.getRemoteAddr();
assertEquals("remoteAddr", "not-allowed-internal-proxy", actualRemoteAddr);
String actualRemoteHost = actualRequest.getRemoteHost();
assertEquals("remoteHost", "not-allowed-internal-proxy-host", actualRemoteHost);
}
示例8: testInvokeAllProxiesAreTrustedOrInternal
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Test
public void testInvokeAllProxiesAreTrustedOrInternal() throws Exception {
// PREPARE
FilterDef filterDef = new FilterDef();
filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
request.setHeader("x-forwarded-for", "140.211.11.130, proxy1, proxy2, 192.168.0.10, 192.168.0.11");
// TEST
HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();
// VERIFY
String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1, proxy2", actualXForwardedBy);
String actualRemoteAddr = actualRequest.getRemoteAddr();
assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
String actualRemoteHost = actualRequest.getRemoteHost();
assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
示例9: getRealRootPath
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String getRealRootPath(HttpServletRequest request)
throws IOException {
String remoteHostName = request.getRemoteHost();
if ("127.0.0.1".equals(remoteHostName)) {
remoteHostName = "localhost";
} else {
remoteHostName = InetLookup.resolveHost(remoteHostName);
int idx = remoteHostName.indexOf('.');
if (idx > 0) {
remoteHostName = remoteHostName.substring(0, idx);
}
}
return new File(Constants.ROOT_PATH, remoteHostName).getCanonicalPath();
}
示例10: testInvokeAllProxiesAreTrusted
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Test
public void testInvokeAllProxiesAreTrusted() throws Exception {
// PREPARE
RemoteIpFilter remoteIpFilter = new RemoteIpFilter();
FilterDef filterDef = new FilterDef();
filterDef.addInitParameter("internalProxies", "192\\.168\\.0\\.10|192\\.168\\.0\\.11");
filterDef.addInitParameter("trustedProxies", "proxy1|proxy2|proxy3");
filterDef.addInitParameter("remoteIpHeader", "x-forwarded-for");
filterDef.addInitParameter("proxiesHeader", "x-forwarded-by");
filterDef.setFilter(remoteIpFilter);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("192.168.0.10");
request.setRemoteHost("remote-host-original-value");
request.setHeader("x-forwarded-for", "140.211.11.130, proxy1, proxy2");
// TEST
HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();
// VERIFY
String actualXForwardedFor = actualRequest.getHeader("x-forwarded-for");
assertNull("all proxies are trusted, x-forwarded-for must be null", actualXForwardedFor);
String actualXForwardedBy = actualRequest.getHeader("x-forwarded-by");
assertEquals("all proxies are trusted, they must appear in x-forwarded-by", "proxy1, proxy2", actualXForwardedBy);
String actualRemoteAddr = actualRequest.getRemoteAddr();
assertEquals("remoteAddr", "140.211.11.130", actualRemoteAddr);
String actualRemoteHost = actualRequest.getRemoteHost();
assertEquals("remoteHost", "140.211.11.130", actualRemoteHost);
}
示例11: getRemoteHost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String getRemoteHost(HttpServletRequest request) {
if (request != null) {
return request.getRemoteHost();
}
return null;
}
示例12: updatePlatformLocal
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Deprecated
@RequestMapping ( value = UPDATE_PLATFORM , produces = MediaType.APPLICATION_JSON_VALUE )
public ObjectNode updatePlatformLocal (
@RequestParam ( value = "extractDir" , required = true ) String extractToken,
@RequestParam ( value = "chownUserid" , required = false ) String chownUserid,
@RequestParam ( value = "timeoutSeconds" , required = false , defaultValue = "120" ) int timeoutSeconds,
@RequestParam ( value = "deleteExisting" , required = false ) String deleteExisting,
@RequestParam ( value = "auditUser" , required = false ) String auditUser,
@RequestParam ( value = "distFile" , required = true ) MultipartFile multiPartFile,
HttpServletRequest request ) {
String extractDir = extractToken;
if ( extractDir.startsWith( Application.FileToken.STAGING.value ) ) {
// STAGING_TOKEN is used as csap install folder might be different;
// full paths are not passed when syncing elements between hosts.
extractDir = extractDir.replaceAll( Application.FileToken.STAGING.value, csapApp.stagingFolderAsString() );
}
String desc = multiPartFile.toString();
if ( multiPartFile != null ) {
desc = multiPartFile.getOriginalFilename() + " size: " + multiPartFile.getSize();
}
logger.info(
"File System being updated using: {}\t extractToken: {}\t extractDir: {}\n\t chownUserid: {} \t timeoutSeconds: {}\t deleteExisting: {}",
desc, extractToken, extractDir, chownUserid, timeoutSeconds, deleteExisting );
ObjectNode jsonObjectResponse = jacksonMapper.createObjectNode();
jsonObjectResponse.put( "host", Application.getHOST_NAME() );
ArrayNode coreArray = jsonObjectResponse.putArray( "coreResults" );
// MUST be the first line otherwise remote parsing will fail in
// Transfermanager
StringBuilder plainTextResponse = new StringBuilder( CSAP.AGENT_CONTEXT + "@"
+ Application.getHOST_NAME() + ":" );
String servletRemoteHost = request.getRemoteHost();
if ( !csapApp.isHostAuthenticatedMember( servletRemoteHost ) ) {
logger.error( "Security WARNING: bypass auth from {}", servletRemoteHost );
plainTextResponse.append( "**" + CSAP.CONFIG_PARSE_ERROR + " Host "
+ Application.getHOST_NAME()
+ " received request from a host not in its cluster lifecycle: "
+ servletRemoteHost );
coreArray.add( "**" + CSAP.CONFIG_PARSE_ERROR + " Host "
+ Application.getHOST_NAME()
+ " received request from a host not in its cluster lifecycle: "
+ servletRemoteHost );
if ( !Application.isRunningOnDesktop() ) {
return jsonObjectResponse;
}
} else {
jsonObjectResponse = agentApi.platformUpdate( auditUser, "Dummy", extractToken, chownUserid, timeoutSeconds, deleteExisting,
auditUser, multiPartFile, request );
}
return jsonObjectResponse;
}
示例13: createSession
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
*/
public Session createSession(SessionContext sessionContext) throws AuthorizationException {
/*
if (!WebUtils.isHttp(sessionContext)) {
String msg = "SessionContext must be an HTTP compatible implementation.";
throw new IllegalArgumentException(msg);
}
*/
HttpServletRequest request = sessionContext.getServletRequest();
HttpSession httpSession = request.getSession();
//SHIRO-240: DO NOT use the 'globalSessionTimeout' value here on the acquired session.
//see: https://issues.apache.org/jira/browse/SHIRO-240
String host = request.getRemoteHost();
return createSession(httpSession, host);
}
示例14: getRemoteIP
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* @Title: getRemoteIP @Description: 获取到远程客户端的ip @param @param
* request @param @return @return String 返回类型 @throws
*/
public static String getRemoteIP(HttpServletRequest request) {
String ip = request.getRemoteHost();
return ip;
}
示例15: process
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
if (exchange.getIn().getBody() instanceof HttpServletRequest) {
// This is a result of a passthrough operation in the resource provider.
HttpServletRequest httpRequest = (HttpServletRequest) exchange.getIn().getBody();
exchange.getIn().removeHeaders("*" );
exchange.getIn().setBody(httpRequest.getInputStream());
exchange.getIn().setHeader(Exchange.HTTP_METHOD, httpRequest.getMethod());
if (httpRequest.getQueryString() != null) {
//log.info("QueryString = "+httpRequest.getQueryString());
List<NameValuePair> params = URLEncodedUtils.parse(new URI("http://dummy?" + httpRequest.getQueryString()), "UTF-8");
ListIterator paramlist = params.listIterator();
while (paramlist.hasNext()) {
// Remove format. This causes errors in the server (internally we work in JSON only)
// KGM 3/1/2018
NameValuePair param = (NameValuePair) paramlist.next();
// log.info("QS Name ="+param.getName()+" Value="+param.getValue());
if (param.getName().equals("_format")) paramlist.remove();
}
String queryString = URLEncodedUtils.format(params, "UTF-8");
//log.info("New QS="+queryString);
exchange.getIn().setHeader(Exchange.HTTP_QUERY, queryString);
} else {
exchange.getIn().setHeader(Exchange.HTTP_QUERY, null);
}
exchange.getIn().setHeader(Exchange.HTTP_PATH, httpRequest.getPathInfo());
if (httpRequest.getRemoteAddr() !=null && !httpRequest.getRemoteAddr().isEmpty()) {
exchange.getIn().setHeader("X-Forwarded-For", httpRequest.getRemoteAddr());
}
if (httpRequest.getRemoteHost() !=null && !httpRequest.getRemoteHost().isEmpty()) {
exchange.getIn().setHeader("X-Forwarded-Host", httpRequest.getRemoteHost());
}
}
exchange.getIn().setHeader(Exchange.ACCEPT_CONTENT_TYPE, "application/json");
if (exchange.getIn().getHeader("X-Request-ID") == null || exchange.getIn().getHeader("X-Request-ID").toString().isEmpty()) {
exchange.getIn().setHeader("X-Request-ID",exchange.getExchangeId());
}
}