Skip to content

Commit 6bebb64

Browse files
committed
Implement SslHandler retrival logic for transport-reactor-netty4 plugin
Signed-off-by: Andriy Redko <[email protected]>
1 parent 63eeb0d commit 6bebb64

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.http.reactor.netty4;
10+
11+
import java.util.Optional;
12+
13+
import io.netty.channel.Channel;
14+
import io.netty.channel.ChannelHandler;
15+
import reactor.netty.NettyPipeline;
16+
import reactor.netty.http.server.HttpServerRequest;
17+
18+
final class ReactorNetty4BaseHttpChannel {
19+
private ReactorNetty4BaseHttpChannel() {}
20+
21+
@SuppressWarnings("unchecked")
22+
static <T> Optional<T> get(HttpServerRequest request, String name, Class<T> clazz) {
23+
if ("ssl_http".equalsIgnoreCase(name)) {
24+
final ChannelHandler[] channels = new ChannelHandler[1];
25+
request.withConnection(connection -> {
26+
final Channel channel = connection.channel();
27+
if (channel.parent() != null) {
28+
channels[0] = channel.parent().pipeline().get(NettyPipeline.SslHandler);
29+
} else {
30+
channels[0] = channel.pipeline().get(NettyPipeline.SslHandler);
31+
}
32+
});
33+
if (channels[0] != null && clazz.isInstance(channels[0].getClass()) == true) {
34+
return Optional.of((T) channels[0]);
35+
}
36+
}
37+
return Optional.empty();
38+
}
39+
}

plugins/transport-reactor-netty4/src/main/java/org/opensearch/http/reactor/netty4/ReactorNetty4HttpServerTransport.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import io.netty.handler.codec.http.HttpResponseStatus;
5454
import io.netty.handler.ssl.ApplicationProtocolConfig;
5555
import io.netty.handler.ssl.ApplicationProtocolNames;
56+
import io.netty.handler.ssl.ClientAuth;
5657
import io.netty.handler.ssl.SslContext;
5758
import io.netty.handler.ssl.SslContextBuilder;
5859
import io.netty.handler.ssl.SupportedCipherSuiteFilter;
@@ -317,6 +318,8 @@ private HttpServer configure(final HttpServer server) throws Exception {
317318
parameters.flatMap(SecureHttpTransportParameters::trustManagerFactory).ifPresent(sslContextBuilder::trustManager);
318319
parameters.map(SecureHttpTransportParameters::cipherSuites)
319320
.ifPresent(ciphers -> sslContextBuilder.ciphers(ciphers, SupportedCipherSuiteFilter.INSTANCE));
321+
parameters.flatMap(SecureHttpTransportParameters::clientAuth)
322+
.ifPresent(clientAuth -> sslContextBuilder.clientAuth(ClientAuth.valueOf(clientAuth)));
320323

321324
final SslContext sslContext = sslContextBuilder.protocols(
322325
parameters.map(SecureHttpTransportParameters::protocols).orElseGet(() -> Arrays.asList(SslUtils.DEFAULT_SSL_PROTOCOLS))

plugins/transport-reactor-netty4/src/main/java/org/opensearch/http/reactor/netty4/ReactorNetty4NonStreamingHttpChannel.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.opensearch.transport.reactor.netty4.Netty4Utils;
1616

1717
import java.net.InetSocketAddress;
18+
import java.util.Optional;
1819
import java.util.concurrent.atomic.AtomicBoolean;
1920

2021
import io.netty.handler.codec.http.FullHttpResponse;
@@ -75,6 +76,11 @@ public InetSocketAddress getLocalAddress() {
7576
return (InetSocketAddress) response.hostAddress();
7677
}
7778

79+
@Override
80+
public <T> Optional<T> get(String name, Class<T> clazz) {
81+
return ReactorNetty4BaseHttpChannel.get(request, name, clazz);
82+
}
83+
7884
FullHttpResponse createResponse(HttpResponse response) {
7985
return (FullHttpResponse) response;
8086
}

plugins/transport-reactor-netty4/src/main/java/org/opensearch/http/reactor/netty4/ReactorNetty4StreamingHttpChannel.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.net.InetSocketAddress;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.Optional;
2223

2324
import io.netty.buffer.Unpooled;
2425
import io.netty.handler.codec.http.DefaultHttpContent;
@@ -123,6 +124,11 @@ public void subscribe(Subscriber<? super HttpChunk> subscriber) {
123124
receiver.subscribe(subscriber);
124125
}
125126

127+
@Override
128+
public <T> Optional<T> get(String name, Class<T> clazz) {
129+
return ReactorNetty4BaseHttpChannel.get(request, name, clazz);
130+
}
131+
126132
private static HttpContent createContent(HttpResponse response) {
127133
final FullHttpResponse fullHttpResponse = (FullHttpResponse) response;
128134
return new DefaultHttpContent(fullHttpResponse.content());

0 commit comments

Comments
 (0)