use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.
the class SocketPermissionTest method acceptServerSocketTest.
@Test
public void acceptServerSocketTest() throws Exception {
try (ServerSocket ss = new ServerSocket(0)) {
int port = ss.getLocalPort();
String addr = "localhost:" + port;
AccessControlContext acc = getAccessControlContext(new SocketPermission(addr, "listen,connect,resolve"), new SocketPermission("localhost:1024-", "accept"));
// Positive
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
InetAddress me = InetAddress.getLocalHost();
try (Socket client = new Socket(me, port)) {
ss.accept();
}
return null;
}, acc);
// Negative
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
InetAddress me = InetAddress.getLocalHost();
try (Socket client = new Socket(me, port)) {
ss.accept();
}
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 joinGroupMulticastTest.
@Test
public void joinGroupMulticastTest() throws Exception {
InetAddress group = InetAddress.getByName("229.227.226.221");
try (MulticastSocket s = new MulticastSocket(0)) {
int port = s.getLocalPort();
String addr = "localhost:" + port;
AccessControlContext acc = getAccessControlContext(new SocketPermission(addr, "listen,resolve"), new SocketPermission("229.227.226.221", "connect,accept"));
// Positive
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
s.joinGroup(group);
s.leaveGroup(group);
return null;
}, acc);
// Negative
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
s.joinGroup(group);
s.leaveGroup(group);
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 sendDatagramPacketTest.
@Test
public void sendDatagramPacketTest() throws Exception {
byte[] msg = "Hello".getBytes(UTF_8);
InetAddress group = InetAddress.getByName("229.227.226.221");
try (DatagramSocket ds = new DatagramSocket(0)) {
int port = ds.getLocalPort();
String addr = "localhost:" + port;
//test for SocketPermission "229.227.226.221", "connect,accept"
AccessControlContext acc = getAccessControlContext(new SocketPermission(addr, "listen,resolve"), new SocketPermission("229.227.226.221", "connect,accept"));
// Positive
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
DatagramPacket hi = new DatagramPacket(msg, msg.length, group, port);
ds.send(hi);
return null;
}, acc);
// Negative
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
DatagramPacket hi = new DatagramPacket(msg, msg.length, group, port);
ds.send(hi);
fail("Expected SecurityException");
return null;
}, RESTRICTED_ACC);
} catch (SecurityException expected) {
}
}
}
use of java.net.SocketPermission in project wildfly by wildfly.
the class SPNEGOLoginModuleTestCase method deployment.
/**
* Creates {@link WebArchive}.
*
* @return
*/
@Deployment(name = "WEB", testable = false)
public static WebArchive deployment() {
LOGGER.debug("Web deployment");
final WebArchive war = createWebApp(WEBAPP_NAME, "web-spnego-authn.xml", "SPNEGO");
war.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(// Permissions for PropagateIdentityServlet to get delegation credentials DelegationCredentialContext.getDelegCredential()
new RuntimePermission("org.jboss.security.negotiation.getDelegCredential"), // Permissions for PropagateIdentityServlet to read properties
new PropertyPermission(GSSTestConstants.PROPERTY_PORT, "read"), new PropertyPermission(GSSTestConstants.PROPERTY_PRINCIPAL, "read"), new PropertyPermission(GSSTestConstants.PROPERTY_PASSWORD, "read"), // Permissions for GSSTestClient to connect to GSSTestServer
new SocketPermission(TestSuiteEnvironment.getServerAddress(), "resolve,connect"), // Permissions for GSSTestClient to initiate gss context
new ServicePermission(GSSTestConstants.PRINCIPAL, "initiate"), new ServicePermission("krbtgt/JBOSS.ORG@JBOSS.ORG", "initiate")), "permissions.xml");
return war;
}
use of java.net.SocketPermission in project robovm by robovm.
the class HttpURLConnectionImpl method getPermission.
@Override
public final Permission getPermission() throws IOException {
String hostName = getURL().getHost();
int hostPort = Util.getEffectivePort(getURL());
if (usingProxy()) {
InetSocketAddress proxyAddress = (InetSocketAddress) client.getProxy().address();
hostName = proxyAddress.getHostName();
hostPort = proxyAddress.getPort();
}
return new SocketPermission(hostName + ":" + hostPort, "connect, resolve");
}
Aggregations