Skip to content

Commit 4bd65e5

Browse files
committed
instrument sun HttpURLConnection
1 parent 5f33653 commit 4bd65e5

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

libs/entitlement/bridge/src/main/java/org/elasticsearch/entitlement/bridge/EntitlementChecker.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,28 @@ public interface EntitlementChecker {
388388

389389
void check$sun_net_www_protocol_ftp_FtpURLConnection$getOutputStream(Class<?> callerClass, java.net.URLConnection that);
390390

391+
void check$sun_net_www_protocol_http_HttpURLConnection$$openConnectionCheckRedirects(Class<?> callerClass, java.net.URLConnection c);
392+
393+
void check$sun_net_www_protocol_http_HttpURLConnection$connect(Class<?> callerClass, java.net.HttpURLConnection that);
394+
395+
void check$sun_net_www_protocol_http_HttpURLConnection$getOutputStream(Class<?> callerClass, java.net.HttpURLConnection that);
396+
397+
void check$sun_net_www_protocol_http_HttpURLConnection$getInputStream(Class<?> callerClass, java.net.HttpURLConnection that);
398+
399+
void check$sun_net_www_protocol_http_HttpURLConnection$getErrorStream(Class<?> callerClass, java.net.HttpURLConnection that);
400+
401+
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderField(
402+
Class<?> callerClass,
403+
java.net.HttpURLConnection that,
404+
String name
405+
);
406+
407+
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderFields(Class<?> callerClass, java.net.HttpURLConnection that);
408+
409+
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderField(Class<?> callerClass, java.net.HttpURLConnection that, int n);
410+
411+
void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderFieldKey(Class<?> callerClass, java.net.HttpURLConnection that, int n);
412+
391413
// Network miscellanea
392414

393415
// HttpClient#send and sendAsync are abstract, so we instrument their internal implementations

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/URLConnectionNetworkActions.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,47 @@ static void baseHttpURLConnectionGetResponseMessage() throws Exception {
259259
static void baseHttpURLConnectionGetHeaderFieldDate() throws Exception {
260260
withPlainNetworkConnection(conn -> conn.getHeaderFieldDate("date", 0));
261261
}
262+
263+
@EntitlementTest(expectedAccess = PLUGINS)
264+
static void sunHttpURLConnectionConnect() throws Exception {
265+
withJdkHttpConnection(HttpURLConnection::connect);
266+
}
267+
268+
@EntitlementTest(expectedAccess = PLUGINS)
269+
static void sunHttpURLConnectionGetOutputStream() throws Exception {
270+
withJdkHttpConnection(httpURLConnection -> {
271+
httpURLConnection.setDoOutput(true);
272+
httpURLConnection.getOutputStream();
273+
});
274+
}
275+
276+
@EntitlementTest(expectedAccess = PLUGINS)
277+
static void sunHttpURLConnectionGetInputStream() throws Exception {
278+
withJdkHttpConnection(HttpURLConnection::getInputStream);
279+
}
280+
281+
@EntitlementTest(expectedAccess = PLUGINS)
282+
static void sunHttpURLConnectionGetErrorStream() throws Exception {
283+
withJdkHttpConnection(HttpURLConnection::getErrorStream);
284+
}
285+
286+
@EntitlementTest(expectedAccess = PLUGINS)
287+
static void sunHttpURLConnectionGetHeaderFieldWithName() throws Exception {
288+
withJdkHttpConnection(conn -> conn.getHeaderField("date"));
289+
}
290+
291+
@EntitlementTest(expectedAccess = PLUGINS)
292+
static void sunHttpURLConnectionGetHeaderFields() throws Exception {
293+
withJdkHttpConnection(HttpURLConnection::getHeaderFields);
294+
}
295+
296+
@EntitlementTest(expectedAccess = PLUGINS)
297+
static void sunHttpURLConnectionGetHeaderFieldWithIndex() throws Exception {
298+
withJdkHttpConnection(conn -> conn.getHeaderField(0));
299+
}
300+
301+
@EntitlementTest(expectedAccess = PLUGINS)
302+
static void sunHttpURLConnectionGetHeaderFieldKey() throws Exception {
303+
withJdkHttpConnection(conn -> conn.getHeaderFieldKey(0));
304+
}
262305
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,66 @@ private static boolean isNetworkUrlConnection(java.net.URLConnection urlConnecti
870870
policyManager.checkOutboundNetworkAccess(callerClass);
871871
}
872872

873+
@Override
874+
public void check$sun_net_www_protocol_http_HttpURLConnection$$openConnectionCheckRedirects(
875+
Class<?> callerClass,
876+
java.net.URLConnection c
877+
) {
878+
policyManager.checkOutboundNetworkAccess(callerClass);
879+
}
880+
881+
@Override
882+
public void check$sun_net_www_protocol_http_HttpURLConnection$connect(Class<?> callerClass, java.net.HttpURLConnection that) {
883+
policyManager.checkOutboundNetworkAccess(callerClass);
884+
}
885+
886+
@Override
887+
public void check$sun_net_www_protocol_http_HttpURLConnection$getOutputStream(Class<?> callerClass, java.net.HttpURLConnection that) {
888+
policyManager.checkOutboundNetworkAccess(callerClass);
889+
}
890+
891+
@Override
892+
public void check$sun_net_www_protocol_http_HttpURLConnection$getInputStream(Class<?> callerClass, java.net.HttpURLConnection that) {
893+
policyManager.checkOutboundNetworkAccess(callerClass);
894+
}
895+
896+
@Override
897+
public void check$sun_net_www_protocol_http_HttpURLConnection$getErrorStream(Class<?> callerClass, java.net.HttpURLConnection that) {
898+
policyManager.checkOutboundNetworkAccess(callerClass);
899+
}
900+
901+
@Override
902+
public void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderField(
903+
Class<?> callerClass,
904+
java.net.HttpURLConnection that,
905+
String name
906+
) {
907+
policyManager.checkOutboundNetworkAccess(callerClass);
908+
}
909+
910+
@Override
911+
public void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderFields(Class<?> callerClass, java.net.HttpURLConnection that) {
912+
policyManager.checkOutboundNetworkAccess(callerClass);
913+
}
914+
915+
@Override
916+
public void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderField(
917+
Class<?> callerClass,
918+
java.net.HttpURLConnection that,
919+
int n
920+
) {
921+
policyManager.checkOutboundNetworkAccess(callerClass);
922+
}
923+
924+
@Override
925+
public void check$sun_net_www_protocol_http_HttpURLConnection$getHeaderFieldKey(
926+
Class<?> callerClass,
927+
java.net.HttpURLConnection that,
928+
int n
929+
) {
930+
policyManager.checkOutboundNetworkAccess(callerClass);
931+
}
932+
873933
@Override
874934
public void check$jdk_internal_net_http_HttpClientImpl$send(
875935
Class<?> callerClass,

0 commit comments

Comments
 (0)