diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkDocTests.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkDocTests.java index b9a1cda58b1..136194d2d1f 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkDocTests.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkDocTests.java @@ -36,7 +36,7 @@ public class MonitoringBulkDocTests extends ESTestCase { output.setVersion(outputVersion); doc.writeTo(output); - StreamInput streamInput = StreamInput.wrap(output.bytes()); + StreamInput streamInput = output.bytes().streamInput(); streamInput.setVersion(randomVersion(random())); MonitoringBulkDoc doc2 = new MonitoringBulkDoc(streamInput); diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java index e4520126cd1..93f4d391ec2 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java @@ -181,7 +181,7 @@ public class MonitoringBulkRequestTests extends ESTestCase { out.setVersion(randomVersion(random())); request.writeTo(out); - StreamInput in = StreamInput.wrap(out.bytes()); + StreamInput in = out.bytes().streamInput(); in.setVersion(out.getVersion()); MonitoringBulkRequest request2 = new MonitoringBulkRequest(); request2.readFrom(in); diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkResponseTests.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkResponseTests.java index 8ebebe7cf54..6920ad22a89 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkResponseTests.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkResponseTests.java @@ -57,7 +57,7 @@ public class MonitoringBulkResponseTests extends ESTestCase { output.setVersion(outputVersion); response.writeTo(output); - StreamInput streamInput = StreamInput.wrap(output.bytes()); + StreamInput streamInput = output.bytes().streamInput(); streamInput.setVersion(randomVersion(random())); MonitoringBulkResponse response2 = new MonitoringBulkResponse(); response2.readFrom(streamInput); diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/exporter/MonitoringDocTests.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/exporter/MonitoringDocTests.java index ca79844fd0a..b9f6e99efe4 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/exporter/MonitoringDocTests.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/exporter/MonitoringDocTests.java @@ -45,7 +45,7 @@ public class MonitoringDocTests extends ESTestCase { output.setVersion(outputVersion); monitoringDoc.writeTo(output); - StreamInput streamInput = StreamInput.wrap(output.bytes()); + StreamInput streamInput = output.bytes().streamInput(); streamInput.setVersion(randomVersion(random())); MonitoringDoc monitoringDoc2 = new MonitoringDoc(streamInput); diff --git a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/transport/ServerTransportFilter.java b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/transport/ServerTransportFilter.java index c4e3b461c07..ebc923e6ad8 100644 --- a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/transport/ServerTransportFilter.java +++ b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/transport/ServerTransportFilter.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.security.transport; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.transport.TcpTransportChannel; import org.elasticsearch.xpack.security.authc.Authentication; import org.elasticsearch.xpack.security.action.SecurityActionMapper; import org.elasticsearch.xpack.security.authc.AuthenticationService; @@ -16,7 +17,6 @@ import org.elasticsearch.xpack.security.authz.AuthorizationService; import org.elasticsearch.transport.DelegatingTransportChannel; import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportRequest; -import org.elasticsearch.transport.netty.NettyTransportChannel; import org.jboss.netty.channel.Channel; import org.jboss.netty.handler.ssl.SslHandler; @@ -81,8 +81,9 @@ public interface ServerTransportFilter { unwrappedChannel = ((DelegatingTransportChannel) unwrappedChannel).getChannel(); } - if (extractClientCert && (unwrappedChannel instanceof NettyTransportChannel)) { - Channel channel = ((NettyTransportChannel) unwrappedChannel).getChannel(); + if (extractClientCert && (unwrappedChannel instanceof TcpTransportChannel) + && ((TcpTransportChannel) unwrappedChannel).getChannel() instanceof Channel) { + Channel channel = (Channel) ((TcpTransportChannel) unwrappedChannel).getChannel(); SslHandler sslHandler = channel.getPipeline().get(SslHandler.class); assert sslHandler != null; diff --git a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/transport/netty/SecurityNettyTransport.java b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/transport/netty/SecurityNettyTransport.java index 76cfb443b43..9b924372ffd 100644 --- a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/transport/netty/SecurityNettyTransport.java +++ b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/transport/netty/SecurityNettyTransport.java @@ -21,6 +21,7 @@ import org.elasticsearch.xpack.security.transport.SSLClientAuth; import org.elasticsearch.xpack.security.transport.filter.IPFilter; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.netty.NettyTransport; +import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; @@ -32,6 +33,7 @@ import org.jboss.netty.handler.ssl.SslHandler; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLParameters; import java.net.InetSocketAddress; +import java.util.Collections; import java.util.List; import static org.elasticsearch.xpack.security.Security.featureEnabledSetting; @@ -111,30 +113,23 @@ public class SecurityNettyTransport extends NettyTransport { } @Override - protected void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { - if (!lifecycle.started()) { - return; - } - - Throwable t = e.getCause(); - if (isNotSslRecordException(t)) { + protected void onException(Channel channel, Throwable e) { + if (isNotSslRecordException(e)) { if (logger.isTraceEnabled()) { - logger.trace("received plaintext traffic on a encrypted channel, closing connection {}", t, ctx.getChannel()); + logger.trace("received plaintext traffic on a encrypted channel, closing connection {}", e, channel); } else { - logger.warn("received plaintext traffic on a encrypted channel, closing connection {}", ctx.getChannel()); + logger.warn("received plaintext traffic on a encrypted channel, closing connection {}", channel); } - ctx.getChannel().close(); - disconnectFromNodeChannel(ctx.getChannel(), e.getCause()); - } else if (isCloseDuringHandshakeException(t)) { + disconnectFromNodeChannel(channel, e); + } else if (isCloseDuringHandshakeException(e)) { if (logger.isTraceEnabled()) { - logger.trace("connection {} closed during handshake", t, ctx.getChannel()); + logger.trace("connection {} closed during handshake", e, channel); } else { - logger.warn("connection {} closed during handshake", ctx.getChannel()); + logger.warn("connection {} closed during handshake", channel); } - ctx.getChannel().close(); - disconnectFromNodeChannel(ctx.getChannel(), e.getCause()); + disconnectFromNodeChannel(channel, e); } else { - super.exceptionCaught(ctx, e); + super.onException(channel, e); } } diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/http/netty/NettyHttpMockUtil.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/http/netty/NettyHttpMockUtil.java index b061af1fc6b..7e079a511b9 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/http/netty/NettyHttpMockUtil.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/http/netty/NettyHttpMockUtil.java @@ -5,7 +5,7 @@ */ package org.elasticsearch.http.netty; -import org.elasticsearch.common.netty.OpenChannelsHandler; +import org.elasticsearch.transport.netty.OpenChannelsHandler; import static org.mockito.Mockito.mock; diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/transport/netty/NettyMockUtil.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/transport/netty/NettyMockUtil.java index 57bd8e7fbb3..747c4d74fee 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/transport/netty/NettyMockUtil.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/transport/netty/NettyMockUtil.java @@ -5,8 +5,6 @@ */ package org.elasticsearch.transport.netty; -import org.elasticsearch.common.netty.OpenChannelsHandler; - import static org.mockito.Mockito.mock; /** Allows setting a mock into NettyTransport */ diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/authc/InternalAuthenticationServiceTests.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/authc/InternalAuthenticationServiceTests.java index 0925f5dc05f..f76d99ff4c4 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/authc/InternalAuthenticationServiceTests.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/authc/InternalAuthenticationServiceTests.java @@ -332,7 +332,7 @@ public class InternalAuthenticationServiceTests extends ESTestCase { BytesStreamOutput output = new BytesStreamOutput(); threadContext1.writeTo(output); - StreamInput input = StreamInput.wrap(output.bytes()); + StreamInput input = output.bytes().streamInput(); threadContext1 = new ThreadContext(Settings.EMPTY); threadContext1.readHeaders(input); @@ -379,7 +379,7 @@ public class InternalAuthenticationServiceTests extends ESTestCase { BytesStreamOutput output = new BytesStreamOutput(); threadContext1.writeTo(output); - StreamInput input = StreamInput.wrap(output.bytes()); + StreamInput input = output.bytes().streamInput(); threadContext1 = new ThreadContext(Settings.EMPTY); threadContext1.readHeaders(input); diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterTests.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterTests.java index 3c9d7bfe588..376f7456d55 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterTests.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/transport/ServerTransportFilterTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.security.transport; import org.elasticsearch.ElasticsearchSecurityException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.xpack.security.authc.Authentication; import org.elasticsearch.xpack.security.action.SecurityActionMapper; import org.elasticsearch.xpack.security.authc.AuthenticationService; @@ -15,7 +16,6 @@ import org.elasticsearch.xpack.security.authz.AuthorizationService; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.transport.TransportSettings; -import org.elasticsearch.transport.netty.NettyTransportChannel; import org.junit.Before; import static org.elasticsearch.xpack.security.support.Exceptions.authenticationError; @@ -34,13 +34,13 @@ public class ServerTransportFilterTests extends ESTestCase { private AuthenticationService authcService; private AuthorizationService authzService; private ServerTransportFilter filter; - private NettyTransportChannel channel; + private TransportChannel channel; @Before public void init() throws Exception { authcService = mock(AuthenticationService.class); authzService = mock(AuthorizationService.class); - channel = mock(NettyTransportChannel.class); + channel = mock(TransportChannel.class); when(channel.getProfileName()).thenReturn(TransportSettings.DEFAULT_PROFILE); filter = new ServerTransportFilter.NodeProfile(authcService, authzService, new SecurityActionMapper(), new ThreadContext(Settings.EMPTY), false); diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/user/UserTests.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/user/UserTests.java index c2c5448f42b..8fe4af64fb7 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/user/UserTests.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/user/UserTests.java @@ -31,7 +31,7 @@ public class UserTests extends ESTestCase { BytesStreamOutput output = new BytesStreamOutput(); User.writeTo(user, output); - User readFrom = User.readFrom(ByteBufferStreamInput.wrap(output.bytes())); + User readFrom = User.readFrom(output.bytes().streamInput()); assertThat(readFrom, not(sameInstance(user))); assertThat(readFrom.principal(), is(user.principal())); @@ -47,7 +47,7 @@ public class UserTests extends ESTestCase { BytesStreamOutput output = new BytesStreamOutput(); User.writeTo(user, output); - User readFrom = User.readFrom(ByteBufferStreamInput.wrap(output.bytes())); + User readFrom = User.readFrom(output.bytes().streamInput()); assertThat(readFrom, not(sameInstance(user))); assertThat(readFrom.principal(), is(user.principal())); @@ -63,7 +63,7 @@ public class UserTests extends ESTestCase { BytesStreamOutput output = new BytesStreamOutput(); User.writeTo(SystemUser.INSTANCE, output); - User readFrom = User.readFrom(ByteBufferStreamInput.wrap(output.bytes())); + User readFrom = User.readFrom(output.bytes().streamInput()); assertThat(readFrom, is(sameInstance(SystemUser.INSTANCE))); assertThat(readFrom.runAs(), is(nullValue())); @@ -73,7 +73,7 @@ public class UserTests extends ESTestCase { BytesStreamOutput output = new BytesStreamOutput(); User.writeTo(XPackUser.INSTANCE, output); - User readFrom = User.readFrom(ByteBufferStreamInput.wrap(output.bytes())); + User readFrom = User.readFrom(output.bytes().streamInput()); assertThat(readFrom, is(sameInstance(XPackUser.INSTANCE))); assertThat(readFrom.runAs(), is(nullValue())); @@ -84,7 +84,7 @@ public class UserTests extends ESTestCase { output.writeBoolean(true); output.writeString(randomAsciiOfLengthBetween(4, 30)); try { - User.readFrom(ByteBufferStreamInput.wrap(output.bytes())); + User.readFrom(output.bytes().streamInput()); fail("system user had wrong name"); } catch (IllegalStateException e) { // expected @@ -114,13 +114,13 @@ public class UserTests extends ESTestCase { public void testReservedUserSerialization() throws Exception { BytesStreamOutput output = new BytesStreamOutput(); User.writeTo(ElasticUser.INSTANCE, output); - User readFrom = User.readFrom(ByteBufferStreamInput.wrap(output.bytes())); + User readFrom = User.readFrom(output.bytes().streamInput()); assertThat(readFrom, is(sameInstance(ElasticUser.INSTANCE))); output = new BytesStreamOutput(); User.writeTo(KibanaUser.INSTANCE, output); - readFrom = User.readFrom(ByteBufferStreamInput.wrap(output.bytes())); + readFrom = User.readFrom(output.bytes().streamInput()); assertThat(readFrom, is(sameInstance(KibanaUser.INSTANCE))); }