27
27
28
28
import java .io .IOException ;
29
29
import java .io .UncheckedIOException ;
30
- import java .nio .channels .DatagramChannel ;
31
- import java .security .AccessController ;
32
- import java .security .PrivilegedExceptionAction ;
33
30
import java .util .Enumeration ;
34
31
import java .util .Objects ;
35
32
import java .util .Set ;
@@ -110,16 +107,6 @@ private synchronized void connectInternal(InetAddress address, int port) throws
110
107
checkAddress (address , "connect" );
111
108
if (isClosed ())
112
109
return ;
113
- @ SuppressWarnings ("removal" )
114
- SecurityManager security = System .getSecurityManager ();
115
- if (security != null ) {
116
- if (address .isMulticastAddress ()) {
117
- security .checkMulticast (address );
118
- } else {
119
- security .checkConnect (address .getHostAddress (), port );
120
- security .checkAccept (address .getHostAddress (), port );
121
- }
122
- }
123
110
124
111
if (port == 0 ) {
125
112
throw new SocketException ("Can't connect to port 0" );
@@ -181,11 +168,7 @@ public synchronized void bind(SocketAddress addr) throws SocketException {
181
168
InetAddress iaddr = epoint .getAddress ();
182
169
int port = epoint .getPort ();
183
170
checkAddress (iaddr , "bind" );
184
- @ SuppressWarnings ("removal" )
185
- SecurityManager sec = System .getSecurityManager ();
186
- if (sec != null ) {
187
- sec .checkListen (port );
188
- }
171
+
189
172
try {
190
173
getImpl ().bind (port , iaddr );
191
174
} catch (SocketException e ) {
@@ -289,22 +272,7 @@ public void send(DatagramPacket p) throws IOException {
289
272
}
290
273
if (packetPort < 0 || packetPort > 0xFFFF )
291
274
throw new IllegalArgumentException ("port out of range: " + packetPort );
292
- // check the address is ok with the security manager on every send.
293
- @ SuppressWarnings ("removal" )
294
- SecurityManager security = System .getSecurityManager ();
295
-
296
- // The reason you want to synchronize on datagram packet
297
- // is because you don't want an applet to change the address
298
- // while you are trying to send the packet for example
299
- // after the security check but before the send.
300
- if (security != null ) {
301
- if (packetAddress .isMulticastAddress ()) {
302
- security .checkMulticast (packetAddress );
303
- } else {
304
- security .checkConnect (packetAddress .getHostAddress (),
305
- packetPort );
306
- }
307
- }
275
+
308
276
if (packetPort == 0 ) {
309
277
throw new SocketException ("Can't send to port 0" );
310
278
}
@@ -333,41 +301,13 @@ public synchronized void receive(DatagramPacket p) throws IOException {
333
301
synchronized (p ) {
334
302
if (!isBound ())
335
303
bind (new InetSocketAddress (0 ));
336
- if (connectState == ST_NOT_CONNECTED ) {
337
- // check the address is ok with the security manager before every recv.
338
- @ SuppressWarnings ("removal" )
339
- SecurityManager security = System .getSecurityManager ();
340
- if (security != null ) {
341
- while (true ) {
342
- int peekPort = 0 ;
343
- // peek at the packet to see who it is from.
344
- DatagramPacket peekPacket = new DatagramPacket (new byte [1 ], 1 );
345
- peekPort = getImpl ().peekData (peekPacket );
346
- String peekAd = peekPacket .getAddress ().getHostAddress ();
347
- try {
348
- security .checkAccept (peekAd , peekPort );
349
- // security check succeeded - so now break
350
- // and recv the packet.
351
- break ;
352
- } catch (SecurityException se ) {
353
- // Throw away the offending packet by consuming
354
- // it in a tmp buffer.
355
- DatagramPacket tmp = new DatagramPacket (new byte [1 ], 1 );
356
- getImpl ().receive (tmp );
357
-
358
- // silently discard the offending packet
359
- // and continue: unknown/malicious
360
- // entities on nets should not make
361
- // runtime throw security exception and
362
- // disrupt the applet by sending random
363
- // datagram packets.
364
- continue ;
365
- }
366
- } // end of while
367
- }
368
- }
369
304
DatagramPacket tmp = null ;
305
+ // explicitFilter may be set to 'true' at connect() time and will
306
+ // be set to 'false' in disconnect() - or when there's no more
307
+ // pending packets to filter. If explicitFilter is true,
308
+ // it means we're connected.
370
309
if (explicitFilter ) {
310
+ assert connectState == ST_CONNECTED ;
371
311
// We have to do the filtering the old fashioned way since
372
312
// the native impl doesn't support connect or the connect
373
313
// via the impl failed, or .. "explicitFilter" may be set when
@@ -394,8 +334,7 @@ public synchronized void receive(DatagramPacket p) throws IOException {
394
334
}
395
335
}
396
336
}
397
- // If the security check succeeds, or the datagram is
398
- // connected then receive the packet
337
+ // receive the packet
399
338
getImpl ().receive (p );
400
339
if (explicitFilter && tmp == null ) {
401
340
// packet was not filtered, account for it here
@@ -423,11 +362,6 @@ public InetAddress getLocalAddress() {
423
362
if (in .isAnyLocalAddress ()) {
424
363
in = InetAddress .anyLocalAddress ();
425
364
}
426
- @ SuppressWarnings ("removal" )
427
- SecurityManager s = System .getSecurityManager ();
428
- if (s != null ) {
429
- s .checkConnect (in .getHostAddress (), -1 );
430
- }
431
365
} catch (Exception e ) {
432
366
in = InetAddress .anyLocalAddress (); // "0.0.0.0"
433
367
}
@@ -691,11 +625,6 @@ public void joinGroup(InetAddress mcastaddr) throws IOException {
691
625
}
692
626
693
627
checkAddress (mcastaddr , "joinGroup" );
694
- @ SuppressWarnings ("removal" )
695
- SecurityManager security = System .getSecurityManager ();
696
- if (security != null ) {
697
- security .checkMulticast (mcastaddr );
698
- }
699
628
700
629
if (!mcastaddr .isMulticastAddress ()) {
701
630
throw new SocketException ("Not a multicast address" );
@@ -722,11 +651,6 @@ public void leaveGroup(InetAddress mcastaddr) throws IOException {
722
651
}
723
652
724
653
checkAddress (mcastaddr , "leaveGroup" );
725
- @ SuppressWarnings ("removal" )
726
- SecurityManager security = System .getSecurityManager ();
727
- if (security != null ) {
728
- security .checkMulticast (mcastaddr );
729
- }
730
654
731
655
if (!mcastaddr .isMulticastAddress ()) {
732
656
throw new SocketException ("Not a multicast address" );
@@ -745,11 +669,6 @@ public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
745
669
throw new IllegalArgumentException ("Unsupported address type" );
746
670
747
671
checkAddress (addr .getAddress (), "joinGroup" );
748
- @ SuppressWarnings ("removal" )
749
- SecurityManager security = System .getSecurityManager ();
750
- if (security != null ) {
751
- security .checkMulticast (addr .getAddress ());
752
- }
753
672
754
673
if (!addr .getAddress ().isMulticastAddress ()) {
755
674
throw new SocketException ("Not a multicast address" );
@@ -768,11 +687,6 @@ public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
768
687
throw new IllegalArgumentException ("Unsupported address type" );
769
688
770
689
checkAddress (addr .getAddress (), "leaveGroup" );
771
- @ SuppressWarnings ("removal" )
772
- SecurityManager security = System .getSecurityManager ();
773
- if (security != null ) {
774
- security .checkMulticast (addr .getAddress ());
775
- }
776
690
777
691
if (!addr .getAddress ().isMulticastAddress ()) {
778
692
throw new SocketException ("Not a multicast address" );
@@ -893,22 +807,10 @@ public void send(DatagramPacket p, byte ttl)
893
807
synchronized (p ) {
894
808
InetAddress packetAddress = p .getAddress ();
895
809
checkAddress (packetAddress , "send" );
896
- if (connectState == NetMulticastSocket . ST_NOT_CONNECTED ) {
810
+ if (connectState == ST_NOT_CONNECTED ) {
897
811
if (packetAddress == null ) {
898
812
throw new IllegalArgumentException ("Address not set" );
899
813
}
900
- // Security manager makes sure that the multicast address
901
- // is allowed one and that the ttl used is less
902
- // than the allowed maxttl.
903
- SecurityManager security = System .getSecurityManager ();
904
- if (security != null ) {
905
- if (packetAddress .isMulticastAddress ()) {
906
- security .checkMulticast (packetAddress , ttl );
907
- } else {
908
- security .checkConnect (packetAddress .getHostAddress (),
909
- p .getPort ());
910
- }
911
- }
912
814
} else {
913
815
// we're connected
914
816
if (packetAddress == null ) {
0 commit comments