11/*
2- * Copyright (c) 2000, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2000, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2929import java .io .OutputStream ;
3030import java .io .BufferedOutputStream ;
3131import java .nio .charset .StandardCharsets ;
32- import java .security .AccessController ;
3332import java .util .Iterator ;
3433
3534import jdk .internal .util .StaticProperty ;
@@ -75,30 +74,10 @@ private static boolean useV4(Proxy proxy) {
7574 return DefaultProxySelector .socksProxyVersion () == 4 ;
7675 }
7776
78- @ SuppressWarnings ("removal" )
79- private synchronized void privilegedConnect (final String host ,
80- final int port ,
81- final int timeout )
82- throws IOException
83- {
84- try {
85- AccessController .doPrivileged (
86- new java .security .PrivilegedExceptionAction <>() {
87- public Void run () throws IOException {
88- superConnectServer (host , port , timeout );
89- cmdIn = getInputStream ();
90- cmdOut = getOutputStream ();
91- return null ;
92- }
93- });
94- } catch (java .security .PrivilegedActionException pae ) {
95- throw (IOException ) pae .getException ();
96- }
97- }
98-
99- private void superConnectServer (String host , int port ,
100- int timeout ) throws IOException {
77+ private synchronized void doConnect (final String host , final int port , final int timeout ) throws IOException {
10178 delegate .connect (new InetSocketAddress (host , port ), timeout );
79+ cmdIn = getInputStream ();
80+ cmdOut = getOutputStream ();
10281 }
10382
10483 private static int remainingMillis (long deadlineMillis ) throws IOException {
@@ -151,15 +130,8 @@ private boolean authenticate(byte method, InputStream in,
151130 String userName ;
152131 String password = null ;
153132 final InetAddress addr = InetAddress .getByName (server );
154- @ SuppressWarnings ("removal" )
155- PasswordAuthentication pw =
156- java .security .AccessController .doPrivileged (
157- new java .security .PrivilegedAction <>() {
158- public PasswordAuthentication run () {
159- return Authenticator .requestPasswordAuthentication (
160- server , addr , serverPort , "SOCKS5" , "SOCKS authentication" , null );
161- }
162- });
133+ PasswordAuthentication pw = Authenticator .requestPasswordAuthentication (
134+ server , addr , serverPort , "SOCKS5" , "SOCKS authentication" , null );
163135 if (pw != null ) {
164136 userName = pw .getUserName ();
165137 password = new String (pw .getPassword ());
@@ -250,8 +222,6 @@ protected void connect(InetAddress address, int port) throws IOException {
250222 * @param endpoint the {@code SocketAddress} to connect to.
251223 * @param timeout the timeout value in milliseconds
252224 * @throws IOException if the connection can't be established.
253- * @throws SecurityException if there is a security manager and it
254- * doesn't allow the connection
255225 * @throws IllegalArgumentException if endpoint is null or a
256226 * SocketAddress subclass not supported by this socket
257227 */
@@ -266,29 +236,14 @@ protected void connect(SocketAddress endpoint, int timeout) throws IOException {
266236 deadlineMillis = finish < 0 ? Long .MAX_VALUE : finish ;
267237 }
268238
269- @ SuppressWarnings ("removal" )
270- SecurityManager security = System .getSecurityManager ();
271239 if (!(endpoint instanceof InetSocketAddress epoint ))
272240 throw new IllegalArgumentException ("Unsupported address type" );
273- if (security != null ) {
274- if (epoint .isUnresolved ())
275- security .checkConnect (epoint .getHostName (),
276- epoint .getPort ());
277- else
278- security .checkConnect (epoint .getAddress ().getHostAddress (),
279- epoint .getPort ());
280- }
241+
281242 if (server == null ) {
282243 // This is the general case
283244 // server is not null only when the socket was created with a
284245 // specified proxy in which case it does bypass the ProxySelector
285- @ SuppressWarnings ("removal" )
286- ProxySelector sel = java .security .AccessController .doPrivileged (
287- new java .security .PrivilegedAction <>() {
288- public ProxySelector run () {
289- return ProxySelector .getDefault ();
290- }
291- });
246+ ProxySelector sel = ProxySelector .getDefault ();
292247 if (sel == null ) {
293248 /*
294249 * No default proxySelector --> direct connection
@@ -337,7 +292,7 @@ public ProxySelector run() {
337292
338293 // Connects to the SOCKS server
339294 try {
340- privilegedConnect (server , serverPort , remainingMillis (deadlineMillis ));
295+ doConnect (server , serverPort , remainingMillis (deadlineMillis ));
341296 // Worked, let's get outta here
342297 break ;
343298 } catch (IOException e ) {
@@ -361,13 +316,13 @@ public ProxySelector run() {
361316 } else {
362317 // Connects to the SOCKS server
363318 try {
364- privilegedConnect (server , serverPort , remainingMillis (deadlineMillis ));
319+ doConnect (server , serverPort , remainingMillis (deadlineMillis ));
365320 } catch (IOException e ) {
366321 throw new SocketException (e .getMessage (), e );
367322 }
368323 }
369324
370- // cmdIn & cmdOut were initialized during the privilegedConnect() call
325+ // ` cmdIn` & ` cmdOut` were initialized during the `doConnect()` call
371326 BufferedOutputStream out = new BufferedOutputStream (cmdOut , 512 );
372327 InputStream in = cmdIn ;
373328
0 commit comments