diff --git a/shield/src/main/java/org/elasticsearch/shield/audit/index/IndexAuditTrail.java b/shield/src/main/java/org/elasticsearch/shield/audit/index/IndexAuditTrail.java index 89b7c9477ea..a5cb1ee9ce7 100644 --- a/shield/src/main/java/org/elasticsearch/shield/audit/index/IndexAuditTrail.java +++ b/shield/src/main/java/org/elasticsearch/shield/audit/index/IndexAuditTrail.java @@ -239,8 +239,8 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail { */ public void start(boolean master) { if (state.compareAndSet(State.INITIALIZED, State.STARTING)) { - this.nodeHostName = NetworkUtils.getLocalHostName("n/a"); - this.nodeHostAddress = NetworkUtils.getLocalHostAddress("n/a"); + this.nodeHostName = NetworkUtils.getLocalHost().getHostName(); + this.nodeHostAddress = NetworkUtils.getLocalHost().getHostAddress(); if (client == null) { initializeClient(); @@ -559,7 +559,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail { // the call was originated locally on this node builder.field(Field.ORIGIN_TYPE, "local_node"); - builder.field(Field.ORIGIN_ADDRESS, NetworkUtils.getLocalHostAddress("_local")); + builder.field(Field.ORIGIN_ADDRESS, NetworkUtils.getLocalHost().getHostAddress()); return builder; } diff --git a/shield/src/main/java/org/elasticsearch/shield/audit/logfile/LoggingAuditTrail.java b/shield/src/main/java/org/elasticsearch/shield/audit/logfile/LoggingAuditTrail.java index 4da4c7b6edd..1f1450ada5b 100644 --- a/shield/src/main/java/org/elasticsearch/shield/audit/logfile/LoggingAuditTrail.java +++ b/shield/src/main/java/org/elasticsearch/shield/audit/logfile/LoggingAuditTrail.java @@ -265,7 +265,7 @@ public class LoggingAuditTrail implements AuditTrail { // the call was originated locally on this node return builder.append("origin_type=[local_node], origin_address=[") - .append(NetworkUtils.getLocalHostAddress("_local")) + .append(NetworkUtils.getLocalHost().getHostAddress()) .append("]") .toString(); } @@ -273,13 +273,13 @@ public class LoggingAuditTrail implements AuditTrail { static String resolvePrefix(Settings settings) { StringBuilder builder = new StringBuilder(); if (settings.getAsBoolean("shield.audit.logfile.prefix.emit_node_host_address", false)) { - String address = NetworkUtils.getLocalHostAddress(null); + String address = NetworkUtils.getLocalHost().getHostAddress(); if (address != null) { builder.append("[").append(address).append("] "); } } if (settings.getAsBoolean("shield.audit.logfile.prefix.emit_node_host_name", false)) { - String hostName = NetworkUtils.getLocalHostName(null); + String hostName = NetworkUtils.getLocalHost().getHostAddress(); if (hostName != null) { builder.append("[").append(hostName).append("] "); } diff --git a/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java b/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java index 9cbb7e68cc9..02d9c0b8b67 100644 --- a/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/audit/index/IndexAuditTrailTests.java @@ -587,8 +587,8 @@ public class IndexAuditTrailTests extends ShieldIntegTestCase { DateTime dateTime = ISODateTimeFormat.dateTimeParser().withZoneUTC().parseDateTime((String) hit.field("@timestamp").getValue()); assertThat(dateTime.isBefore(DateTime.now(DateTimeZone.UTC)), is(true)); - assertThat(NetworkUtils.getLocalHostName("n/a"), equalTo(hit.field("node_host_name").getValue())); - assertThat(NetworkUtils.getLocalHostAddress("n/a"), equalTo(hit.field("node_host_address").getValue())); + assertThat(NetworkUtils.getLocalHost().getHostName(), equalTo(hit.field("node_host_name").getValue())); + assertThat(NetworkUtils.getLocalHost().getHostAddress(), equalTo(hit.field("node_host_address").getValue())); assertEquals(layer, hit.field("layer").getValue()); assertEquals(type, hit.field("event_type").getValue()); diff --git a/shield/src/test/java/org/elasticsearch/shield/audit/logfile/LoggingAuditTrailTests.java b/shield/src/test/java/org/elasticsearch/shield/audit/logfile/LoggingAuditTrailTests.java index 7ad4c4603f2..d19064bbeb1 100644 --- a/shield/src/test/java/org/elasticsearch/shield/audit/logfile/LoggingAuditTrailTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/audit/logfile/LoggingAuditTrailTests.java @@ -490,7 +490,7 @@ public class LoggingAuditTrailTests extends ESTestCase { } TransportAddress address = message.remoteAddress(); if (address == null) { - assertThat(text, equalTo("origin_type=[local_node], origin_address=[" + NetworkUtils.getLocalHostAddress("_local") + "]")); + assertThat(text, equalTo("origin_type=[local_node], origin_address=[" + NetworkUtils.getLocalHost().getHostAddress() + "]")); return; } diff --git a/shield/src/test/java/org/elasticsearch/shield/transport/filter/IPFilterTests.java b/shield/src/test/java/org/elasticsearch/shield/transport/filter/IPFilterTests.java index e24437b2096..f84259eb7c5 100644 --- a/shield/src/test/java/org/elasticsearch/shield/transport/filter/IPFilterTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/transport/filter/IPFilterTests.java @@ -45,12 +45,12 @@ public class IPFilterTests extends ESTestCase { nodeSettingsService = mock(NodeSettingsService.class); httpTransport = mock(HttpServerTransport.class); - InetSocketTransportAddress httpAddress = new InetSocketTransportAddress(NetworkUtils.getLocalAddress(), 9200); + InetSocketTransportAddress httpAddress = new InetSocketTransportAddress(NetworkUtils.getLocalHost().getHostAddress(), 9200); when(httpTransport.boundAddress()).thenReturn(new BoundTransportAddress(httpAddress, httpAddress)); when(httpTransport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); transport = mock(Transport.class); - InetSocketTransportAddress address = new InetSocketTransportAddress(NetworkUtils.getLocalAddress(), 9300); + InetSocketTransportAddress address = new InetSocketTransportAddress(NetworkUtils.getLocalHost().getHostAddress(), 9300); when(transport.boundAddress()).thenReturn(new BoundTransportAddress(address, address)); when(transport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); } diff --git a/shield/src/test/java/org/elasticsearch/shield/transport/netty/IPFilterNettyUpstreamHandlerTests.java b/shield/src/test/java/org/elasticsearch/shield/transport/netty/IPFilterNettyUpstreamHandlerTests.java index d121cc63040..271afdb0a1c 100644 --- a/shield/src/test/java/org/elasticsearch/shield/transport/netty/IPFilterNettyUpstreamHandlerTests.java +++ b/shield/src/test/java/org/elasticsearch/shield/transport/netty/IPFilterNettyUpstreamHandlerTests.java @@ -46,7 +46,7 @@ public class IPFilterNettyUpstreamHandlerTests extends ESTestCase { boolean isHttpEnabled = randomBoolean(); Transport transport = mock(Transport.class); - InetSocketTransportAddress address = new InetSocketTransportAddress(NetworkUtils.getLocalAddress(), 9300); + InetSocketTransportAddress address = new InetSocketTransportAddress(NetworkUtils.getLocalHost().getHostAddress(), 9300); when(transport.boundAddress()).thenReturn(new BoundTransportAddress(address, address)); when(transport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); @@ -55,7 +55,7 @@ public class IPFilterNettyUpstreamHandlerTests extends ESTestCase { if (isHttpEnabled) { HttpServerTransport httpTransport = mock(HttpServerTransport.class); - InetSocketTransportAddress httpAddress = new InetSocketTransportAddress(NetworkUtils.getLocalAddress(), 9200); + InetSocketTransportAddress httpAddress = new InetSocketTransportAddress(NetworkUtils.getLocalHost().getHostAddress(), 9200); when(httpTransport.boundAddress()).thenReturn(new BoundTransportAddress(httpAddress, httpAddress)); when(httpTransport.lifecycleState()).thenReturn(Lifecycle.State.STARTED); ipFilter.setHttpServerTransport(httpTransport);