35 import java.nio.channels.ServerSocketChannel; |
35 import java.nio.channels.ServerSocketChannel; |
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 |
|
41 import sun.net.TrustedSocketImpl; |
40 import sun.nio.ch.NioSocketImpl; |
42 import sun.nio.ch.NioSocketImpl; |
41 |
43 |
42 /** |
44 /** |
43 * This class implements server sockets. A server socket waits for |
45 * This class implements server sockets. A server socket waits for |
44 * requests to come in over the network. It performs some operation |
46 * requests to come in over the network. It performs some operation |
548 if (si == null) { |
550 if (si == null) { |
549 // create a SocketImpl and accept the connection |
551 // create a SocketImpl and accept the connection |
550 si = Socket.createImpl(); |
552 si = Socket.createImpl(); |
551 impl.accept(si); |
553 impl.accept(si); |
552 try { |
554 try { |
553 // a custom impl has accepted the connection with a NIO SocketImpl |
555 // a custom impl has accepted the connection with a trusted SocketImpl |
554 if (!(impl instanceof NioSocketImpl) && (si instanceof NioSocketImpl)) { |
556 if (!(impl instanceof TrustedSocketImpl) && (si instanceof TrustedSocketImpl)) { |
555 ((NioSocketImpl) si).postCustomAccept(); |
557 ((TrustedSocketImpl) si).postCustomAccept(); |
556 } |
558 } |
557 } finally { |
559 } finally { |
558 securityCheckAccept(si); // closes si if permission check fails |
560 securityCheckAccept(si); // closes si if permission check fails |
559 } |
561 } |
560 |
562 |
565 } |
567 } |
566 |
568 |
567 if (si instanceof DelegatingSocketImpl) |
569 if (si instanceof DelegatingSocketImpl) |
568 si = ((DelegatingSocketImpl) si).delegate(); |
570 si = ((DelegatingSocketImpl) si).delegate(); |
569 |
571 |
570 // ServerSocket or Socket is using NIO SocketImpl |
572 // ServerSocket or Socket is using a trusted SocketImpl |
571 if (impl instanceof NioSocketImpl || si instanceof NioSocketImpl) { |
573 if (impl instanceof TrustedSocketImpl || si instanceof TrustedSocketImpl) { |
572 // accept connection via new SocketImpl |
574 // accept connection with new SocketImpl |
573 NioSocketImpl nsi = new NioSocketImpl(false); |
575 var nsi = (impl instanceof TrustedSocketImpl) |
|
576 ? ((TrustedSocketImpl) impl).newInstance(false) |
|
577 : ((TrustedSocketImpl) si).newInstance(false); |
574 impl.accept(nsi); |
578 impl.accept(nsi); |
575 securityCheckAccept(nsi); // closes si if permission check fails |
579 securityCheckAccept(nsi); // closes nsi if permission check fails |
576 |
580 |
577 // copy state to the existing SocketImpl and update socket state |
581 // copy state to the existing SocketImpl and update socket state |
578 nsi.copyTo(si); |
582 nsi.copyTo(si); |
579 s.postAccept(); |
|
580 return; |
|
581 } |
|
582 |
|
583 // ServerSocket or Socket is using PlainSocketImpl |
|
584 if (impl instanceof PlainSocketImpl || si instanceof PlainSocketImpl) { |
|
585 // accept connection via new SocketImpl |
|
586 PlainSocketImpl psi = new PlainSocketImpl(); |
|
587 impl.accept(psi); |
|
588 securityCheckAccept(psi); // closes si if permission check fails |
|
589 |
|
590 // copy state to the existing SocketImpl and update socket state |
|
591 psi.copyTo(si); |
|
592 s.postAccept(); |
583 s.postAccept(); |
593 return; |
584 return; |
594 } |
585 } |
595 |
586 |
596 // ServerSocket and Socket bound to custom SocketImpls |
587 // ServerSocket and Socket bound to custom SocketImpls |