Remove hostname from NetworkAddress.format (x-plugins side)
This removes the old usage of NetworkAddress.formatAddress in favor of the updated version, which is just the method renamed to NetworkAddress.format (replacing the old version of that method). There is no impact to x-plugins beyond making the build work because all places were currently using that method variant already. Original commit: elastic/x-pack-elasticsearch@05f0dcfa90
This commit is contained in:
parent
52b6fc54b8
commit
daa875db11
|
@ -51,7 +51,7 @@ public class WatcherWithShieldIT extends ESRestTestCase {
|
||||||
public void startWatcher() throws Exception {
|
public void startWatcher() throws Exception {
|
||||||
try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) {
|
try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) {
|
||||||
InetSocketAddress address = cluster().httpAddresses()[0];
|
InetSocketAddress address = cluster().httpAddresses()[0];
|
||||||
HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.formatAddress(address.getAddress()), address.getPort(), "/_watcher/_start", null, null));
|
HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.format(address.getAddress()), address.getPort(), "/_watcher/_start", null, null));
|
||||||
String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecuredString(TEST_ADMIN_PASSWORD.toCharArray()));
|
String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecuredString(TEST_ADMIN_PASSWORD.toCharArray()));
|
||||||
request.addHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, token);
|
request.addHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, token);
|
||||||
client.execute(request);
|
client.execute(request);
|
||||||
|
@ -62,7 +62,7 @@ public class WatcherWithShieldIT extends ESRestTestCase {
|
||||||
public void stopWatcher() throws Exception {
|
public void stopWatcher() throws Exception {
|
||||||
try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) {
|
try(CloseableHttpClient client = HttpClients.createMinimal(new BasicHttpClientConnectionManager())) {
|
||||||
InetSocketAddress address = cluster().httpAddresses()[0];
|
InetSocketAddress address = cluster().httpAddresses()[0];
|
||||||
HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.formatAddress(address.getAddress()), address.getPort(), "/_watcher/_stop", null, null));
|
HttpPut request = new HttpPut(new URI("http", null, NetworkAddress.format(address.getAddress()), address.getPort(), "/_watcher/_stop", null, null));
|
||||||
String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecuredString(TEST_ADMIN_PASSWORD.toCharArray()));
|
String token = basicAuthHeaderValue(TEST_ADMIN_USERNAME, new SecuredString(TEST_ADMIN_PASSWORD.toCharArray()));
|
||||||
request.addHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, token);
|
request.addHeader(UsernamePasswordToken.BASIC_AUTH_HEADER, token);
|
||||||
client.execute(request);
|
client.execute(request);
|
||||||
|
|
|
@ -610,7 +610,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
|
||||||
msg.builder.field(Field.ORIGIN_TYPE, "rest");
|
msg.builder.field(Field.ORIGIN_TYPE, "rest");
|
||||||
SocketAddress address = request.getRemoteAddress();
|
SocketAddress address = request.getRemoteAddress();
|
||||||
if (address instanceof InetSocketAddress) {
|
if (address instanceof InetSocketAddress) {
|
||||||
msg.builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.formatAddress(((InetSocketAddress) request.getRemoteAddress())
|
msg.builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.format(((InetSocketAddress) request.getRemoteAddress())
|
||||||
.getAddress()));
|
.getAddress()));
|
||||||
} else {
|
} else {
|
||||||
msg.builder.field(Field.ORIGIN_ADDRESS, address);
|
msg.builder.field(Field.ORIGIN_ADDRESS, address);
|
||||||
|
@ -626,7 +626,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
|
||||||
Message msg = new Message().start();
|
Message msg = new Message().start();
|
||||||
common(layer, type, msg.builder);
|
common(layer, type, msg.builder);
|
||||||
|
|
||||||
msg.builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.formatAddress(originAddress));
|
msg.builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.format(originAddress));
|
||||||
msg.builder.field(Field.TRANSPORT_PROFILE, profile);
|
msg.builder.field(Field.TRANSPORT_PROFILE, profile);
|
||||||
msg.builder.field(Field.RULE, rule);
|
msg.builder.field(Field.RULE, rule);
|
||||||
|
|
||||||
|
@ -649,7 +649,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
|
||||||
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
|
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
|
||||||
if (restAddress != null) {
|
if (restAddress != null) {
|
||||||
builder.field(Field.ORIGIN_TYPE, "rest");
|
builder.field(Field.ORIGIN_TYPE, "rest");
|
||||||
builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.formatAddress(restAddress.getAddress()));
|
builder.field(Field.ORIGIN_ADDRESS, NetworkAddress.format(restAddress.getAddress()));
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
|
||||||
builder.field(Field.ORIGIN_TYPE, "transport");
|
builder.field(Field.ORIGIN_TYPE, "transport");
|
||||||
if (address instanceof InetSocketTransportAddress) {
|
if (address instanceof InetSocketTransportAddress) {
|
||||||
builder.field(Field.ORIGIN_ADDRESS,
|
builder.field(Field.ORIGIN_ADDRESS,
|
||||||
NetworkAddress.formatAddress(((InetSocketTransportAddress) address).address().getAddress()));
|
NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress()));
|
||||||
} else {
|
} else {
|
||||||
builder.field(Field.ORIGIN_ADDRESS, address);
|
builder.field(Field.ORIGIN_ADDRESS, address);
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,14 +339,14 @@ public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTr
|
||||||
public void connectionGranted(InetAddress inetAddress, String profile, ShieldIpFilterRule rule) {
|
public void connectionGranted(InetAddress inetAddress, String profile, ShieldIpFilterRule rule) {
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("{}[ip_filter] [connection_granted]\torigin_address=[{}], transport_profile=[{}], rule=[{}]", prefix,
|
logger.trace("{}[ip_filter] [connection_granted]\torigin_address=[{}], transport_profile=[{}], rule=[{}]", prefix,
|
||||||
NetworkAddress.formatAddress(inetAddress), profile, rule);
|
NetworkAddress.format(inetAddress), profile, rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connectionDenied(InetAddress inetAddress, String profile, ShieldIpFilterRule rule) {
|
public void connectionDenied(InetAddress inetAddress, String profile, ShieldIpFilterRule rule) {
|
||||||
logger.error("{}[ip_filter] [connection_denied]\torigin_address=[{}], transport_profile=[{}], rule=[{}]", prefix,
|
logger.error("{}[ip_filter] [connection_denied]\torigin_address=[{}], transport_profile=[{}], rule=[{}]", prefix,
|
||||||
NetworkAddress.formatAddress(inetAddress), profile, rule);
|
NetworkAddress.format(inetAddress), profile, rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -377,7 +377,7 @@ public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTr
|
||||||
String formattedAddress;
|
String formattedAddress;
|
||||||
SocketAddress socketAddress = request.getRemoteAddress();
|
SocketAddress socketAddress = request.getRemoteAddress();
|
||||||
if (socketAddress instanceof InetSocketAddress) {
|
if (socketAddress instanceof InetSocketAddress) {
|
||||||
formattedAddress = NetworkAddress.formatAddress(((InetSocketAddress) socketAddress).getAddress());
|
formattedAddress = NetworkAddress.format(((InetSocketAddress) socketAddress).getAddress());
|
||||||
} else {
|
} else {
|
||||||
formattedAddress = socketAddress.toString();
|
formattedAddress = socketAddress.toString();
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTr
|
||||||
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
|
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
|
||||||
if (restAddress != null) {
|
if (restAddress != null) {
|
||||||
builder.append("origin_type=[rest], origin_address=[").
|
builder.append("origin_type=[rest], origin_address=[").
|
||||||
append(NetworkAddress.formatAddress(restAddress.getAddress())).
|
append(NetworkAddress.format(restAddress.getAddress())).
|
||||||
append("]");
|
append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ public class LoggingAuditTrail extends AbstractLifecycleComponent<LoggingAuditTr
|
||||||
builder.append("origin_type=[transport], ");
|
builder.append("origin_type=[transport], ");
|
||||||
if (address instanceof InetSocketTransportAddress) {
|
if (address instanceof InetSocketTransportAddress) {
|
||||||
builder.append("origin_address=[").
|
builder.append("origin_address=[").
|
||||||
append(NetworkAddress.formatAddress(((InetSocketTransportAddress) address).address().getAddress())).
|
append(NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress())).
|
||||||
append("]");
|
append("]");
|
||||||
} else {
|
} else {
|
||||||
builder.append("origin_address=[").append(address).append("]");
|
builder.append("origin_address=[").append(address).append("]");
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class ShieldIpFilterRule implements IpFilterRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert transportAddress instanceof InetSocketTransportAddress;
|
assert transportAddress instanceof InetSocketTransportAddress;
|
||||||
ruleSpec.append(NetworkAddress.formatAddress(((InetSocketTransportAddress) transportAddress).address().getAddress()));
|
ruleSpec.append(NetworkAddress.format(((InetSocketTransportAddress) transportAddress).address().getAddress()));
|
||||||
}
|
}
|
||||||
return ruleSpec.toString();
|
return ruleSpec.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase {
|
||||||
Settings.Builder builder = Settings.builder()
|
Settings.Builder builder = Settings.builder()
|
||||||
.put(settings)
|
.put(settings)
|
||||||
.put(XPackPlugin.featureEnabledSetting(Security.NAME), useShield)
|
.put(XPackPlugin.featureEnabledSetting(Security.NAME), useShield)
|
||||||
.put(remoteSettings(NetworkAddress.formatAddress(inet.address().getAddress()), inet.address().getPort(), cluster2Name))
|
.put(remoteSettings(NetworkAddress.format(inet.address().getAddress()), inet.address().getPort(), cluster2Name))
|
||||||
.put("xpack.security.audit.index.client." + Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD);
|
.put("xpack.security.audit.index.client." + Security.USER_SETTING.getKey(), DEFAULT_USER_NAME + ":" + DEFAULT_PASSWORD);
|
||||||
|
|
||||||
if (useSSL) {
|
if (useSSL) {
|
||||||
|
@ -264,7 +264,7 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
assertAuditMessage(hit, "rest", "anonymous_access_denied");
|
assertAuditMessage(hit, "rest", "anonymous_access_denied");
|
||||||
Map<String, Object> sourceMap = hit.sourceAsMap();
|
Map<String, Object> sourceMap = hit.sourceAsMap();
|
||||||
assertThat(NetworkAddress.formatAddress(InetAddress.getLoopbackAddress()), equalTo(sourceMap.get("origin_address")));
|
assertThat(NetworkAddress.format(InetAddress.getLoopbackAddress()), equalTo(sourceMap.get("origin_address")));
|
||||||
assertThat("_uri", equalTo(sourceMap.get("uri")));
|
assertThat("_uri", equalTo(sourceMap.get("uri")));
|
||||||
assertThat(sourceMap.get("origin_type"), is("rest"));
|
assertThat(sourceMap.get("origin_type"), is("rest"));
|
||||||
assertThat(sourceMap.get("request_body"), notNullValue());
|
assertThat(sourceMap.get("request_body"), notNullValue());
|
||||||
|
|
|
@ -173,12 +173,12 @@ public class LoggingAuditTrailTests extends ESTestCase {
|
||||||
case WARN:
|
case WARN:
|
||||||
case INFO:
|
case INFO:
|
||||||
assertMsg(logger, Level.WARN, prefix + "[rest] [anonymous_access_denied]\torigin_address=[" +
|
assertMsg(logger, Level.WARN, prefix + "[rest] [anonymous_access_denied]\torigin_address=[" +
|
||||||
NetworkAddress.formatAddress(address) + "], uri=[_uri]");
|
NetworkAddress.format(address) + "], uri=[_uri]");
|
||||||
break;
|
break;
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
case TRACE:
|
case TRACE:
|
||||||
assertMsg(logger, Level.DEBUG, prefix + "[rest] [anonymous_access_denied]\torigin_address=[" +
|
assertMsg(logger, Level.DEBUG, prefix + "[rest] [anonymous_access_denied]\torigin_address=[" +
|
||||||
NetworkAddress.formatAddress(address) + "], uri=[_uri], request_body=[" + expectedMessage + "]");
|
NetworkAddress.format(address) + "], uri=[_uri], request_body=[" + expectedMessage + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,12 +265,12 @@ public class LoggingAuditTrailTests extends ESTestCase {
|
||||||
case WARN:
|
case WARN:
|
||||||
case INFO:
|
case INFO:
|
||||||
assertMsg(logger, Level.ERROR, prefix + "[rest] [authentication_failed]\torigin_address=[" +
|
assertMsg(logger, Level.ERROR, prefix + "[rest] [authentication_failed]\torigin_address=[" +
|
||||||
NetworkAddress.formatAddress(address) + "], principal=[_principal], uri=[_uri]");
|
NetworkAddress.format(address) + "], principal=[_principal], uri=[_uri]");
|
||||||
break;
|
break;
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
case TRACE:
|
case TRACE:
|
||||||
assertMsg(logger, Level.DEBUG, prefix + "[rest] [authentication_failed]\torigin_address=[" +
|
assertMsg(logger, Level.DEBUG, prefix + "[rest] [authentication_failed]\torigin_address=[" +
|
||||||
NetworkAddress.formatAddress(address) + "], principal=[_principal], uri=[_uri], request_body=[" +
|
NetworkAddress.format(address) + "], principal=[_principal], uri=[_uri], request_body=[" +
|
||||||
expectedMessage + "]");
|
expectedMessage + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,12 +292,12 @@ public class LoggingAuditTrailTests extends ESTestCase {
|
||||||
case WARN:
|
case WARN:
|
||||||
case INFO:
|
case INFO:
|
||||||
assertMsg(logger, Level.ERROR, prefix + "[rest] [authentication_failed]\torigin_address=[" +
|
assertMsg(logger, Level.ERROR, prefix + "[rest] [authentication_failed]\torigin_address=[" +
|
||||||
NetworkAddress.formatAddress(address) + "], uri=[_uri]");
|
NetworkAddress.format(address) + "], uri=[_uri]");
|
||||||
break;
|
break;
|
||||||
case DEBUG:
|
case DEBUG:
|
||||||
case TRACE:
|
case TRACE:
|
||||||
assertMsg(logger, Level.DEBUG, prefix + "[rest] [authentication_failed]\torigin_address=[" +
|
assertMsg(logger, Level.DEBUG, prefix + "[rest] [authentication_failed]\torigin_address=[" +
|
||||||
NetworkAddress.formatAddress(address) + "], uri=[_uri], request_body=[" + expectedMessage + "]");
|
NetworkAddress.format(address) + "], uri=[_uri], request_body=[" + expectedMessage + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
|
||||||
break;
|
break;
|
||||||
case TRACE:
|
case TRACE:
|
||||||
assertMsg(logger, Level.TRACE, prefix + "[rest] [authentication_failed]\trealm=[_realm], origin_address=[" +
|
assertMsg(logger, Level.TRACE, prefix + "[rest] [authentication_failed]\trealm=[_realm], origin_address=[" +
|
||||||
NetworkAddress.formatAddress(address) + "], principal=[_principal], uri=[_uri], request_body=[" +
|
NetworkAddress.format(address) + "], principal=[_principal], uri=[_uri], request_body=[" +
|
||||||
expectedMessage + "]");
|
expectedMessage + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,7 +600,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
|
||||||
case ERROR:
|
case ERROR:
|
||||||
assertMsg(logger, Level.ERROR, String.format(Locale.ROOT, prefix +
|
assertMsg(logger, Level.ERROR, String.format(Locale.ROOT, prefix +
|
||||||
"[ip_filter] [connection_denied]\torigin_address=[%s], transport_profile=[%s], rule=[deny %s]",
|
"[ip_filter] [connection_denied]\torigin_address=[%s], transport_profile=[%s], rule=[deny %s]",
|
||||||
NetworkAddress.formatAddress(inetAddress), "default", "_all"));
|
NetworkAddress.format(inetAddress), "default", "_all"));
|
||||||
break;
|
break;
|
||||||
case WARN:
|
case WARN:
|
||||||
case INFO:
|
case INFO:
|
||||||
|
@ -628,7 +628,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
|
||||||
case TRACE:
|
case TRACE:
|
||||||
assertMsg(logger, Level.TRACE, String.format(Locale.ROOT, prefix + "[ip_filter] " +
|
assertMsg(logger, Level.TRACE, String.format(Locale.ROOT, prefix + "[ip_filter] " +
|
||||||
"[connection_granted]\torigin_address=[%s], transport_profile=[default], rule=[allow default:accept_all]",
|
"[connection_granted]\torigin_address=[%s], transport_profile=[default], rule=[allow default:accept_all]",
|
||||||
NetworkAddress.formatAddress(inetAddress)));
|
NetworkAddress.format(inetAddress)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -692,7 +692,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
|
||||||
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
|
InetSocketAddress restAddress = RemoteHostHeader.restRemoteAddress(threadContext);
|
||||||
if (restAddress != null) {
|
if (restAddress != null) {
|
||||||
assertThat(text, equalTo("origin_type=[rest], origin_address=[" +
|
assertThat(text, equalTo("origin_type=[rest], origin_address=[" +
|
||||||
NetworkAddress.formatAddress(restAddress.getAddress()) + "]"));
|
NetworkAddress.format(restAddress.getAddress()) + "]"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TransportAddress address = message.remoteAddress();
|
TransportAddress address = message.remoteAddress();
|
||||||
|
@ -704,7 +704,7 @@ public class LoggingAuditTrailTests extends ESTestCase {
|
||||||
|
|
||||||
if (address instanceof InetSocketTransportAddress) {
|
if (address instanceof InetSocketTransportAddress) {
|
||||||
assertThat(text, equalTo("origin_type=[transport], origin_address=[" +
|
assertThat(text, equalTo("origin_type=[transport], origin_address=[" +
|
||||||
NetworkAddress.formatAddress(((InetSocketTransportAddress) address).address().getAddress()) + "]"));
|
NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress()) + "]"));
|
||||||
} else {
|
} else {
|
||||||
assertThat(text, equalTo("origin_type=[transport], origin_address=[" + address + "]"));
|
assertThat(text, equalTo("origin_type=[transport], origin_address=[" + address + "]"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class ServerTransportFilterIntegrationTests extends ShieldIntegTestCase {
|
||||||
TransportAddress transportAddress = transport.boundAddress().publishAddress();
|
TransportAddress transportAddress = transport.boundAddress().publishAddress();
|
||||||
assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class));
|
assertThat(transportAddress, instanceOf(InetSocketTransportAddress.class));
|
||||||
InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address();
|
InetSocketAddress inetSocketAddress = ((InetSocketTransportAddress) transportAddress).address();
|
||||||
String unicastHost = NetworkAddress.formatAddress(inetSocketAddress);
|
String unicastHost = NetworkAddress.format(inetSocketAddress);
|
||||||
|
|
||||||
// test that starting up a node works
|
// test that starting up a node works
|
||||||
Settings nodeSettings = settingsBuilder()
|
Settings nodeSettings = settingsBuilder()
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class IPFilterTests extends ESTestCase {
|
||||||
public void testThatBoundAddressIsNeverRejected() throws Exception {
|
public void testThatBoundAddressIsNeverRejected() throws Exception {
|
||||||
List<String> addressStrings = new ArrayList<>();
|
List<String> addressStrings = new ArrayList<>();
|
||||||
for (TransportAddress address : transport.boundAddress().boundAddresses()) {
|
for (TransportAddress address : transport.boundAddress().boundAddresses()) {
|
||||||
addressStrings.add(NetworkAddress.formatAddress(((InetSocketTransportAddress) address).address().getAddress()));
|
addressStrings.add(NetworkAddress.format(((InetSocketTransportAddress) address).address().getAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
|
Loading…
Reference in New Issue