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);
}
}
use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.
the class AppletViewer method getApplets.
/**
* Return an enumeration of all the accessible
* applets on this page.
*/
@Override
public Enumeration getApplets() {
AppletSecurity security = (AppletSecurity) System.getSecurityManager();
Vector v = new Vector();
SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect");
for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) {
AppletPanel p = (AppletPanel) e.nextElement();
if (p.getDocumentBase().equals(panel.getDocumentBase())) {
SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect");
if (panelSp.implies(sp)) {
v.addElement(p.applet);
}
}
}
return v.elements();
}
use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.
the class AppletViewer method getApplet.
/**
* Get an applet by name.
*/
@Override
public Applet getApplet(String name) {
AppletSecurity security = (AppletSecurity) System.getSecurityManager();
name = name.toLowerCase();
SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect");
for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) {
AppletPanel p = (AppletPanel) e.nextElement();
String param = p.getParameter("name");
if (param != null) {
param = param.toLowerCase();
}
if (name.equals(param) && p.getDocumentBase().equals(panel.getDocumentBase())) {
SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect");
if (panelSp.implies(sp)) {
return p.applet;
}
}
}
return null;
}
use of java.net.SocketPermission in project rt.equinox.framework by eclipse.
the class SecurityAdminUnitTests method testNotLocationCondition02.
public void testNotLocationCondition02() {
Bundle test = installTestBundle(TEST_BUNDLE);
AccessControlContext acc = test.adapt(AccessControlContext.class);
ConditionalPermissionInfo condPermInfo = cpa.addConditionalPermissionInfo(getLocationConditions(test.getLocation(), true), SOCKET_INFOS);
testPermission(acc, new AllPermission(), false);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), false);
condPermInfo.delete();
testPermission(acc, new AllPermission(), true);
// $NON-NLS-1$ //$NON-NLS-2$
testPermission(acc, new SocketPermission("localhost", "accept"), true);
}
Aggregations