Search in sources :

Example 46 with SocketPermission

use of java.net.SocketPermission in project wildfly by wildfly.

the class PasswordMaskingInContainerTestCase method deploy.

@Deployment
public static WebArchive deploy() {
    WebArchive war = ShrinkWrap.create(WebArchive.class, "passwordMasking" + ".war");
    war.addClass(PasswordMaskingTestServlet.class);
    war.setWebXML(PasswordMaskingInContainerTestCase.class.getPackage(), "web.xml");
    war.addAsManifestResource(createPermissionsXmlAsset(new SocketPermission("*:9092", "connect,resolve")), "permissions.xml");
    return war;
}
Also used : WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) SocketPermission(java.net.SocketPermission) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 47 with SocketPermission

use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.

the class MailToURLConnection method getPermission.

@Override
public Permission getPermission() throws IOException {
    if (permission == null) {
        connect();
        String host = client.getMailHost() + ":" + 25;
        permission = new SocketPermission(host, "connect");
    }
    return permission;
}
Also used : SocketPermission(java.net.SocketPermission)

Example 48 with SocketPermission

use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.

the class MyBasicPermission method trySockPC.

static void trySockPC() throws Exception {
    try {
        SocketPermission p0 = new SocketPermission("example.com", "connect");
        PermissionCollection pc = p0.newPermissionCollection();
        // this should lock out future adds
        pc.setReadOnly();
        //
        SocketPermission p1 = new SocketPermission("example.net", "connect");
        pc.add(p1);
        throw new Exception("Failed...SocketPermission added to readonly SocketPermissionCollection.");
    } catch (SecurityException se) {
        System.out.println("SocketPermissionCollection passed");
    }
}
Also used : SocketPermission(java.net.SocketPermission)

Example 49 with SocketPermission

use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.

the class EmptyInputStream method followRedirect.

/* Tells us whether to follow a redirect.  If so, it
     * closes the connection (break any keep-alive) and
     * resets the url, re-connects, and resets the request
     * property.
     */
private boolean followRedirect() throws IOException {
    if (!getInstanceFollowRedirects()) {
        return false;
    }
    final int stat = getResponseCode();
    if (stat < 300 || stat > 307 || stat == 306 || stat == HTTP_NOT_MODIFIED) {
        return false;
    }
    final String loc = getHeaderField("Location");
    if (loc == null) {
        /* this should be present - if not, we have no choice
             * but to go forward w/ the response we got
             */
        return false;
    }
    URL locUrl;
    try {
        locUrl = new URL(loc);
        if (!url.getProtocol().equalsIgnoreCase(locUrl.getProtocol())) {
            return false;
        }
    } catch (MalformedURLException mue) {
        // treat loc as a relative URI to conform to popular browsers
        locUrl = new URL(url, loc);
    }
    final URL locUrl0 = locUrl;
    // force recalculation
    socketPermission = null;
    SocketPermission p = URLtoSocketPermission(locUrl);
    if (p != null) {
        try {
            return AccessController.doPrivilegedWithCombiner(new PrivilegedExceptionAction<Boolean>() {

                public Boolean run() throws IOException {
                    return followRedirect0(loc, stat, locUrl0);
                }
            }, null, p);
        } catch (PrivilegedActionException e) {
            throw (IOException) e.getException();
        }
    } else {
        // run without additional permission
        return followRedirect0(loc, stat, locUrl);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) PrivilegedActionException(java.security.PrivilegedActionException) SocketPermission(java.net.SocketPermission) URL(java.net.URL)

Example 50 with SocketPermission

use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.

the class FtpURLConnection method getPermission.

/**
     * Gets the <code>Permission</code> associated with the host & port.
     *
     * @return  The <code>Permission</code> 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