Search in sources :

Example 61 with SocketPermission

use of java.net.SocketPermission in project rt.equinox.framework by eclipse.

the class SecurityAdminUnitTests method testLocationPermission03.

public void testLocationPermission03() {
    Bundle test = installTestBundle(TEST_BUNDLE);
    AccessControlContext acc = test.adapt(AccessControlContext.class);
    pa.setDefaultPermissions(READONLY_INFOS);
    pa.setPermissions(test.getLocation(), READWRITE_INFOS);
    ConditionalPermissionInfo condPermInfo = cpa.addConditionalPermissionInfo(ALLLOCATION_CONDS, SOCKET_INFOS);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), true);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), true);
    testPermission(acc, new AllPermission(), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), false);
    pa.setPermissions(test.getLocation(), null);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), false);
    testPermission(acc, new AllPermission(), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), true);
    condPermInfo.delete();
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), true);
    testPermission(acc, new AllPermission(), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), false);
    pa.setDefaultPermissions(null);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), true);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), true);
    testPermission(acc, new AllPermission(), true);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), true);
}
Also used : SocketPermission(java.net.SocketPermission) FilePermission(java.io.FilePermission)

Example 62 with SocketPermission

use of java.net.SocketPermission in project rt.equinox.framework by eclipse.

the class SecurityAdminUnitTests method testDefaultPermissions02.

public void testDefaultPermissions02() {
    Bundle test = installTestBundle(TEST_BUNDLE);
    AccessControlContext acc = test.adapt(AccessControlContext.class);
    pa.setDefaultPermissions(READONLY_INFOS);
    pa.setPermissions(test.getLocation(), SOCKET_INFOS);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), false);
    testPermission(acc, new AllPermission(), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), true);
    pa.setPermissions(test.getLocation(), null);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), true);
    testPermission(acc, new AllPermission(), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), false);
    pa.setDefaultPermissions(null);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), true);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), true);
    testPermission(acc, new AllPermission(), true);
}
Also used : SocketPermission(java.net.SocketPermission) FilePermission(java.io.FilePermission)

Example 63 with SocketPermission

use of java.net.SocketPermission in project rt.equinox.framework by eclipse.

the class SecurityAdminUnitTests method testMultipleLocationConditions01.

public void testMultipleLocationConditions01() {
    Bundle test = installTestBundle(TEST_BUNDLE);
    AccessControlContext acc = test.adapt(AccessControlContext.class);
    // $NON-NLS-1$
    ConditionalPermissionInfo condPermInfo1 = cpa.addConditionalPermissionInfo(getLocationConditions("xxx", false), SOCKET_INFOS);
    ConditionalPermissionInfo condPermInfo2 = cpa.addConditionalPermissionInfo(ALLLOCATION_CONDS, READONLY_INFOS);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), true);
    condPermInfo1.delete();
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), true);
    condPermInfo2.delete();
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new SocketPermission("localhost", "accept"), true);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "write"), true);
    // $NON-NLS-1$ //$NON-NLS-2$
    testPermission(acc, new FilePermission("test", "read"), true);
}
Also used : SocketPermission(java.net.SocketPermission) FilePermission(java.io.FilePermission)

Example 64 with SocketPermission

use of java.net.SocketPermission in project Bytecoder by mirkosertic.

the class EmptyInputStream method URLtoSocketPermission.

/**
 *  if the caller has a URLPermission for connecting to the
 *  given URL, then return a SocketPermission which permits
 *  access to that destination. Return null otherwise. The permission
 *  is cached in a field (which can only be changed by redirects)
 */
SocketPermission URLtoSocketPermission(URL url) throws IOException {
    if (socketPermission != null) {
        return socketPermission;
    }
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        return null;
    }
    // the permission, which we might grant
    SocketPermission newPerm = new SocketPermission(getHostAndPort(url), "connect");
    String actions = getRequestMethod() + ":" + getUserSetHeaders().getHeaderNamesInList();
    String urlstring = url.getProtocol() + "://" + url.getAuthority() + url.getPath();
    URLPermission p = new URLPermission(urlstring, actions);
    try {
        sm.checkPermission(p);
        socketPermission = newPerm;
        return socketPermission;
    } catch (SecurityException e) {
    // fall thru
    }
    return null;
}
Also used : SocketPermission(java.net.SocketPermission) URLPermission(java.net.URLPermission)

Example 65 with SocketPermission

use of java.net.SocketPermission in project Bytecoder by mirkosertic.

the class FtpURLConnection method getPermission.

/**
 * Gets the {@code Permission} associated with the host and port.
 *
 * @return  The {@code Permission} object.
 */
@Override
public Permission getPermission() {
    if (permission == null) {
        int urlport = url.getPort();
        urlport = urlport < 0 ? FtpClient.defaultPort() : urlport;
        String urlhost = this.host + ":" + urlport;
        permission = new SocketPermission(urlhost, "connect");
    }
    return permission;
}
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