Follup PR fore elastic/elasticsearchelastic/elasticsearch#19096 (elastic/elasticsearch#2656)

This PR is a cleanup / follup for elastic/elasticsearchelastic/elasticsearch#19096

Original commit: elastic/x-pack-elasticsearch@052b9a85a7
This commit is contained in:
Simon Willnauer 2016-06-30 13:42:09 +02:00 committed by GitHub
parent 7c988b78e1
commit 30dd9ab09c
11 changed files with 33 additions and 39 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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 */

View File

@ -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);

View File

@ -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);

View File

@ -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)));
}