36 import java.security.AccessController; |
36 import java.security.AccessController; |
37 import java.security.PrivilegedExceptionAction; |
37 import java.security.PrivilegedExceptionAction; |
38 import java.util.Set; |
38 import java.util.Set; |
39 import java.util.Collections; |
39 import java.util.Collections; |
40 |
40 |
41 import sun.net.TrustedSocketImpl; |
41 import sun.net.PlatformSocketImpl; |
42 import sun.nio.ch.NioSocketImpl; |
|
43 |
42 |
44 /** |
43 /** |
45 * This class implements server sockets. A server socket waits for |
44 * This class implements server sockets. A server socket waits for |
46 * requests to come in over the network. It performs some operation |
45 * requests to come in over the network. It performs some operation |
47 * based on that request, and then possibly returns a result to the requester. |
46 * based on that request, and then possibly returns a result to the requester. |
551 // create a SocketImpl and accept the connection |
550 // create a SocketImpl and accept the connection |
552 si = Socket.createImpl(); |
551 si = Socket.createImpl(); |
553 impl.accept(si); |
552 impl.accept(si); |
554 try { |
553 try { |
555 // a custom impl has accepted the connection with a trusted SocketImpl |
554 // a custom impl has accepted the connection with a trusted SocketImpl |
556 if (!(impl instanceof TrustedSocketImpl) && (si instanceof TrustedSocketImpl)) { |
555 if (!(impl instanceof PlatformSocketImpl) && (si instanceof PlatformSocketImpl)) { |
557 ((TrustedSocketImpl) si).postCustomAccept(); |
556 ((PlatformSocketImpl) si).postCustomAccept(); |
558 } |
557 } |
559 } finally { |
558 } finally { |
560 securityCheckAccept(si); // closes si if permission check fails |
559 securityCheckAccept(si); // closes si if permission check fails |
561 } |
560 } |
562 |
561 |
567 } |
566 } |
568 |
567 |
569 // Socket has a SOCKS or HTTP SocketImpl |
568 // Socket has a SOCKS or HTTP SocketImpl |
570 if (si instanceof DelegatingSocketImpl) { |
569 if (si instanceof DelegatingSocketImpl) { |
571 si = ((DelegatingSocketImpl) si).delegate(); |
570 si = ((DelegatingSocketImpl) si).delegate(); |
572 assert si instanceof TrustedSocketImpl; |
571 assert si instanceof PlatformSocketImpl; |
573 } |
572 } |
574 |
573 |
575 // ServerSocket or Socket is using a trusted SocketImpl |
574 // ServerSocket or Socket is using a trusted SocketImpl |
576 if (impl instanceof TrustedSocketImpl || si instanceof TrustedSocketImpl) { |
575 if (impl instanceof PlatformSocketImpl || si instanceof PlatformSocketImpl) { |
577 // accept connection with new SocketImpl |
576 // accept connection with new SocketImpl |
578 var nsi = (impl instanceof TrustedSocketImpl) |
577 var nsi = (impl instanceof PlatformSocketImpl) |
579 ? ((TrustedSocketImpl) impl).newInstance(false) |
578 ? ((PlatformSocketImpl) impl).newInstance(false) |
580 : ((TrustedSocketImpl) si).newInstance(false); |
579 : ((PlatformSocketImpl) si).newInstance(false); |
581 impl.accept(nsi); |
580 impl.accept(nsi); |
582 try { |
581 try { |
583 // a custom impl has accepted the connection with a trusted SocketImpl |
582 // a custom impl has accepted the connection with a trusted SocketImpl |
584 if (!(impl instanceof TrustedSocketImpl)) { |
583 if (!(impl instanceof PlatformSocketImpl)) { |
585 nsi.postCustomAccept(); |
584 nsi.postCustomAccept(); |
586 } |
585 } |
587 } finally { |
586 } finally { |
588 securityCheckAccept(nsi); // closes nsi if permission check fails |
587 securityCheckAccept(nsi); // closes nsi if permission check fails |
589 } |
588 } |