Skip to content

Commit

Permalink
Implement SecurityRequest gaps
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Sep 29, 2023
1 parent 6580e7f commit 8c44278
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestRequest.Method;

import io.netty.handler.ssl.SslHandler;

public class SecurityRequestFactory {

public static SecurityRequest from() {
Expand All @@ -38,9 +40,17 @@ public Map<String, List<String>> getHeaders() {

@Override
public SSLEngine getSSLEngine() {
// TODO: this doesn't seem properly handled
if (underlyingRequest == null || underlyingRequest.getHttpChannel() == null || !(underlyingRequest.getHttpChannel() instanceof Netty4HttpChannel)) {
return null;
}

throw new UnsupportedOperationException("Unimplemented method 'getSSLEngine'");
final Netty4HttpChannel httpChannel = (Netty4HttpChannel) underlyingRequest.getHttpChannel();
SslHandler sslhandler = (SslHandler) httpChannel.getNettyChannel().pipeline().get("ssl_http");
if (sslhandler == null && httpChannel.inboundPipeline() != null) {
sslhandler = (SslHandler) httpChannel.inboundPipeline().get("ssl_http");
}

return sslhandler != null ? sslhandler.engine() : null;
}

@Override
Expand Down Expand Up @@ -80,8 +90,7 @@ public Optional<RestRequest> asRestRequest() {

@Override
public Map<String, String> params() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'params'");
return underlyingRequest.params();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public static SSLInfo getSSLInfo(
PrincipalExtractor principalExtractor
) throws SSLPeerUnverifiedException {
final SSLEngine engine = request.getSSLEngine();
if (engine == null) {
return null;
}

final SSLSession session = engine.getSession();

X509Certificate[] x509Certs = null;
Expand Down

0 comments on commit 8c44278

Please sign in to comment.