use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.
the class SocketPermissionTest method listenServerSocketTest.
@Test
public void listenServerSocketTest() throws Exception {
// the hardcoded port number doesn't really matter since we expect the
// security permission to be checked before the underlying operation.
int port = 8899;
String addr = "localhost:" + port;
AccessControlContext acc = getAccessControlContext(new SocketPermission(addr, "listen"));
// Positive
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
try (ServerSocket ss = new ServerSocket(port)) {
} catch (IOException intermittentlyExpected) {
}
return null;
}, acc);
// Negative
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
try (ServerSocket ss = new ServerSocket(port)) {
} catch (IOException intermittentlyExpected) {
}
fail("Expected SecurityException");
return null;
}, RESTRICTED_ACC);
} catch (SecurityException expected) {
}
}
use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.
the class SocketPermissionTest method listenMulticastSocketTest.
@Test
public void listenMulticastSocketTest() throws Exception {
// the hardcoded port number doesn't really matter since we expect the
// security permission to be checked before the underlying operation.
int port = 8899;
String addr = "localhost:" + port;
AccessControlContext acc = getAccessControlContext(new SocketPermission(addr, "listen"));
// Positive
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
try (MulticastSocket ms = new MulticastSocket(port)) {
} catch (IOException intermittentlyExpected) {
}
return null;
}, acc);
// Negative
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
try (MulticastSocket ms = new MulticastSocket(port)) {
} catch (IOException intermittentlyExpected) {
}
fail("Expected SecurityException");
return null;
}, RESTRICTED_ACC);
} catch (SecurityException expected) {
}
}
use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.
the class SocketPermissionTest method listenDatagramSocketTest.
@Test
public void listenDatagramSocketTest() throws Exception {
// the hardcoded port number doesn't really matter since we expect the
// security permission to be checked before the underlying operation.
int port = 8899;
String addr = "localhost:" + port;
AccessControlContext acc = getAccessControlContext(new SocketPermission(addr, "listen"));
// Positive
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
try (DatagramSocket ds = new DatagramSocket(port)) {
} catch (IOException intermittentlyExpected) {
}
return null;
}, acc);
// Negative
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
try (DatagramSocket ds = new DatagramSocket(port)) {
} catch (IOException intermittentlyExpected) {
}
fail("Expected SecurityException");
return null;
}, RESTRICTED_ACC);
} catch (SecurityException expected) {
}
}
use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.
the class SocketPermissionTest method connectDatagramSocketTest.
@Test
public void connectDatagramSocketTest() throws Exception {
byte[] msg = "Hello".getBytes(UTF_8);
InetAddress lh = InetAddress.getLocalHost();
try (DatagramSocket ds = new DatagramSocket(0)) {
int port = ds.getLocalPort();
String addr = lh.getHostAddress() + ":" + port;
AccessControlContext acc = getAccessControlContext(new SocketPermission(addr, "connect,resolve"));
// Positive
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
DatagramPacket dp = new DatagramPacket(msg, msg.length, lh, port);
ds.send(dp);
return null;
}, acc);
// Negative
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
DatagramPacket dp = new DatagramPacket(msg, msg.length, lh, port);
ds.send(dp);
fail("Expected SecurityException");
return null;
}, RESTRICTED_ACC);
} catch (SecurityException expected) {
}
}
}
use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.
the class Wildcard method main.
public static void main(String[] args) throws Exception {
SocketPermission star_All = new SocketPermission("*.blabla.bla", "listen,accept,connect");
SocketPermission www_All = new SocketPermission("bla.blabla.bla", "listen,accept,connect");
if (!star_All.implies(www_All)) {
throw new RuntimeException("Failed: " + star_All + " does not imply " + www_All);
}
}
Aggregations