Search in sources :

Example 56 with SocketPermission

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) {
        }
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) DatagramSocket(java.net.DatagramSocket) SocketPermission(java.net.SocketPermission) DatagramPacket(java.net.DatagramPacket) InetAddress(java.net.InetAddress) Test(org.testng.annotations.Test)

Example 57 with SocketPermission

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);
    }
}
Also used : SocketPermission(java.net.SocketPermission)

Example 58 with SocketPermission

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();
}
Also used : SocketPermission(java.net.SocketPermission)

Example 59 with SocketPermission

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;
}
Also used : SocketPermission(java.net.SocketPermission)

Example 60 with SocketPermission

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);
}
Also used : SocketPermission(java.net.SocketPermission)

Aggregations

SocketPermission (java.net.SocketPermission)83 Deployment (org.jboss.arquillian.container.test.api.Deployment)27 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)27 FilePermission (java.io.FilePermission)17 PropertyPermission (java.util.PropertyPermission)13 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)13 AccessControlContext (java.security.AccessControlContext)9 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)9 Test (org.testng.annotations.Test)8 URL (java.net.URL)7 PrivilegedActionException (java.security.PrivilegedActionException)6 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)6 HttpRequest (org.jboss.as.test.integration.common.HttpRequest)6 MockTracer (io.opentracing.mock.MockTracer)5 IOException (java.io.IOException)5 DatagramSocket (java.net.DatagramSocket)5 SecurityPermission (java.security.SecurityPermission)5 InetAddress (java.net.InetAddress)4 InetSocketAddress (java.net.InetSocketAddress)4 MulticastSocket (java.net.MulticastSocket)4