Search in sources :

Example 1 with URLPermission

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

the class URLPermissionTest method serializationTest.

static void serializationTest(String name, String actions) throws Exception {
    URLPermission out = new URLPermission(name, actions);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream o = new ObjectOutputStream(baos);
    o.writeObject(out);
    ByteArrayInputStream bain = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream i = new ObjectInputStream(bain);
    URLPermission in = (URLPermission) i.readObject();
    if (!in.equals(out)) {
        System.out.println("FAIL");
        System.out.println("in = " + in);
        System.out.println("out = " + out);
        failed = true;
    }
}
Also used : URLPermission(java.net.URLPermission)

Example 2 with URLPermission

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

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 3 with URLPermission

use of java.net.URLPermission 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)

Aggregations

URLPermission (java.net.URLPermission)3 SocketPermission (java.net.SocketPermission)2