Java Code Examples for java.net.URLPermission

The following are top voted examples for showing how to use java.net.URLPermission. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jdk8u-jdk   File: URLPermissionTest.java   Source Code and License 6 votes vote down vote up
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;
    }
}
 
Example 2
Project: openjdk-jdk10   File: URLTest.java   Source Code and License 6 votes vote down vote up
static void test2() throws IOException {
    System.out.println("\n--- Test 2 ---");

    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Policy.setPolicy(new CustomPolicy(
            new URLPermission("http://127.0.0.1:"+httpPort+"/*", "GET:X-Foo"),
            new URLPermission("https://127.0.0.1:"+httpsPort+"/*", "POST:X-Fob")));
    }

    String url1 = "http://127.0.0.1:"+httpPort+"/foo.html";
    String url2 = "https://127.0.0.1:"+httpsPort+"/foo.html";
    String url3 = "http://127.0.0.1:"+httpPort+"/bar.html";
    String url4 = "https://127.0.0.1:"+httpsPort+"/bar.html";

    // simple positive test. Should succeed
    test(url1, "GET", "X-Foo");
    test(url2, "POST", "X-Fob");
    test(url3, "GET", "X-Foo");
    test(url4, "POST", "X-Fob");
}
 
Example 3
Project: openjdk-jdk10   File: URLTest.java   Source Code and License 6 votes vote down vote up
static void test3() throws IOException {
    System.out.println("\n--- Test 3 ---");

    boolean expectException = false;
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        expectException = true;
        Policy.setPolicy(new CustomPolicy(
            new URLPermission("http://127.0.0.1:"+httpPort+"/a/b/-", "DELETE,GET:X-Foo,Y-Foo"),
            new URLPermission("https://127.0.0.1:"+httpsPort+"/a/c/-", "POST:*")));
    }

    String url1 = "http://127.0.0.1:"+httpPort+"/foo.html";
    String url2 = "https://127.0.0.1:"+httpsPort+"/a/c/d/e/foo.html";
    String url3 = "http://127.0.0.1:"+httpPort+"/a/b/c";
    String url4 = "https://127.0.0.1:"+httpsPort+"/a/b/c";

    test(url1, "GET", "X-Foo", expectException);
    test(url2, "POST", "X-Zxc");
    test(url3, "DELETE", "Y-Foo");
    test(url4, "POST", "Y-Foo", expectException);
}
 
Example 4
Project: openjdk-jdk10   File: URLPermissionTest.java   Source Code and License 6 votes vote down vote up
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;
    }
}
 
Example 5
Project: openjdk9   File: URLPermissionTest.java   Source Code and License 6 votes vote down vote up
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;
    }
}
 
Example 6
Project: jdk8u_jdk   File: URLPermissionTest.java   Source Code and License 6 votes vote down vote up
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;
    }
}
 
Example 7
Project: lookaside_java-1.8.0-openjdk   File: URLPermissionTest.java   Source Code and License 6 votes vote down vote up
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;
    }
}
 
Example 8
Project: rapidminer-studio   File: PluginSandboxPolicy.java   Source Code and License 6 votes vote down vote up
/**
 * Adds a couple of common permissions for both unsigned extensions as well as Groovy scripts.
 *
 * @param permissions
 *            the permissions object which will get the permissions added to it
 */
private static void addCommonPermissions(Permissions permissions) {
	permissions.add(new AudioPermission("play"));
	permissions.add(new AWTPermission("listenToAllAWTEvents"));
	permissions.add(new AWTPermission("setWindowAlwaysOnTop"));
	permissions.add(new AWTPermission("watchMousePointer"));
	permissions.add(new LoggingPermission("control", ""));
	permissions.add(new SocketPermission("*", "connect, listen, accept, resolve"));
	permissions.add(new URLPermission("http://-", "*:*"));
	permissions.add(new URLPermission("https://-", "*:*"));

	// because random Java library calls use sun classes which may or may not do an acess check,
	// we have to grant access to all of them
	// this is a very unfortunate permission and I would love to not have it
	// so if at any point in the future this won't be necessary any longer, remove it!!!
	permissions.add(new RuntimePermission("accessClassInPackage.sun.*"));

	permissions.add(new RuntimePermission("accessDeclaredMembers"));
	permissions.add(new RuntimePermission("getenv.*"));
	permissions.add(new RuntimePermission("getFileSystemAttributes"));
	permissions.add(new RuntimePermission("readFileDescriptor"));
	permissions.add(new RuntimePermission("writeFileDescriptor"));
	permissions.add(new RuntimePermission("queuePrintJob"));
	permissions.add(new NetPermission("specifyStreamHandler"));
}
 
Example 9
Project: infobip-open-jdk-8   File: URLPermissionTest.java   Source Code and License 6 votes vote down vote up
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;
    }
}
 
Example 10
Project: jdk8u-dev-jdk   File: URLPermissionTest.java   Source Code and License 6 votes vote down vote up
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;
    }
}
 
Example 11
Project: OLD-OpenJDK8   File: URLPermissionTest.java   Source Code and License 6 votes vote down vote up
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;
    }
}
 
Example 12
Project: OpenJSharp   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 13
Project: jdk8u-jdk   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 14
Project: jdk8u-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 15
Project: jdk8u-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
Example 16
Project: jdk8u-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
boolean execute() {
    URLPermission p1 = new URLPermission (arg1, "GET:*");
    URLPermission p2 = new URLPermission (arg2, "GET:*");
    boolean result = p1.implies(p2);
    if (result != expected) {
        System.out.println("p1 = " + p1);
        System.out.println("p2 = " + p2);
    }
    return result == expected;
}
 
Example 17
Project: jdk8u-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    String url1 = "http://www.foo.com/-";
    String url2 = "http://www.foo.com/a/b";
    URLPermission p1 = new URLPermission(url1, arg1);
    URLPermission p2 = new URLPermission(url2, arg2);
    boolean result = p1.implies(p2);

    return result == expected;
}
 
Example 18
Project: jdk8u-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
Example 19
Project: openjdk-jdk10   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 20
Project: openjdk-jdk10   File: Utils.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the security permission required for the given details.
 * If method is CONNECT, then uri must be of form "scheme://host:port"
 */
public static URLPermission getPermission(URI uri,
                                          String method,
                                          Map<String, List<String>> headers) {
    StringBuilder sb = new StringBuilder();

    String urlstring, actionstring;

    if (method.equals("CONNECT")) {
        urlstring = uri.toString();
        actionstring = "CONNECT";
    } else {
        sb.append(uri.getScheme())
                .append("://")
                .append(uri.getAuthority())
                .append(uri.getPath());
        urlstring = sb.toString();

        sb = new StringBuilder();
        sb.append(method);
        if (headers != null && !headers.isEmpty()) {
            sb.append(':');
            Set<String> keys = headers.keySet();
            boolean first = true;
            for (String key : keys) {
                if (!first) {
                    sb.append(',');
                }
                sb.append(key);
                first = false;
            }
        }
        actionstring = sb.toString();
    }
    return new URLPermission(urlstring, actionstring);
}
 
Example 21
Project: openjdk-jdk10   File: URLTest.java   Source Code and License 5 votes vote down vote up
static void test1() throws IOException {
    System.out.println("\n--- Test 1 ---");

    boolean expectException = false;
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        expectException = true;
        Policy.setPolicy(new CustomPolicy(
            new URLPermission("http://127.0.0.1:"+httpPort+"/foo.html", "GET:X-Foo,Z-Bar"),
            new URLPermission("https://127.0.0.1:"+httpsPort+"/foo.html", "POST:X-Fob,T-Bar")));
    }

    String url1 = "http://127.0.0.1:"+httpPort+"/foo.html";
    String url2 = "https://127.0.0.1:"+httpsPort+"/foo.html";
    String url3 = "http://127.0.0.1:"+httpPort+"/bar.html";
    String url4 = "https://127.0.0.1:"+httpsPort+"/bar.html";

    // simple positive test. Should succeed
    test(url1, "GET", "X-Foo");
    test(url1, "GET", "Z-Bar", "X-Foo");
    test(url1, "GET", "X-Foo", "Z-Bar");
    test(url1, "GET", "Z-Bar");
    test(url2, "POST", "X-Fob");

    // reverse the methods, should fail
    test(url1, "POST", "X-Foo", expectException);
    test(url2, "GET", "X-Fob", expectException);

    // different URLs, should fail
    test(url3, "GET", "X-Foo", expectException);
    test(url4, "POST", "X-Fob", expectException);
}
 
Example 22
Project: openjdk-jdk10   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 23
Project: openjdk-jdk10   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
Example 24
Project: openjdk-jdk10   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
boolean execute() {
    URLPermission p1 = new URLPermission (arg1, "GET:*");
    URLPermission p2 = new URLPermission (arg2, "GET:*");
    boolean result = p1.implies(p2);
    if (result != expected) {
        System.out.println("p1 = " + p1);
        System.out.println("p2 = " + p2);
    }
    return result == expected;
}
 
Example 25
Project: openjdk-jdk10   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(url1, arg1);
    URLPermission p2 = new URLPermission(url2, arg2);
    boolean result = p1.implies(p2);

    return result == expected;
}
 
Example 26
Project: openjdk-jdk10   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
Example 27
Project: openjdk-jdk10   File: LookupTest.java   Source Code and License 5 votes vote down vote up
LookupTestPolicy() throws Exception {
    perms.add(new NetPermission("setProxySelector"));
    perms.add(new SocketPermission("localhost:1024-", "resolve,accept"));
    perms.add(new URLPermission("http://allowedAndFound.com:" + port + "/-", "*:*"));
    perms.add(new URLPermission("http://allowedButNotfound.com:" + port + "/-", "*:*"));
    perms.add(new FilePermission("<<ALL FILES>>", "read,write,delete"));
    //perms.add(new PropertyPermission("java.io.tmpdir", "read"));
}
 
Example 28
Project: openjdk9   File: Utils.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the security permission required for the given details.
 * If method is CONNECT, then uri must be of form "scheme://host:port"
 */
static URLPermission getPermission(URI uri,
                                   String method,
                                   Map<String, List<String>> headers) {
    StringBuilder sb = new StringBuilder();

    String urlstring, actionstring;

    if (method.equals("CONNECT")) {
        urlstring = uri.toString();
        actionstring = "CONNECT";
    } else {
        sb.append(uri.getScheme())
                .append("://")
                .append(uri.getAuthority())
                .append(uri.getPath());
        urlstring = sb.toString();

        sb = new StringBuilder();
        sb.append(method);
        if (headers != null && !headers.isEmpty()) {
            sb.append(':');
            Set<String> keys = headers.keySet();
            boolean first = true;
            for (String key : keys) {
                if (!first) {
                    sb.append(',');
                }
                sb.append(key);
                first = false;
            }
        }
        actionstring = sb.toString();
    }
    return new URLPermission(urlstring, actionstring);
}
 
Example 29
Project: openjdk9   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 30
Project: openjdk9   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 31
Project: openjdk9   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
Example 32
Project: openjdk9   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
boolean execute() {
    URLPermission p1 = new URLPermission (arg1, "GET:*");
    URLPermission p2 = new URLPermission (arg2, "GET:*");
    boolean result = p1.implies(p2);
    if (result != expected) {
        System.out.println("p1 = " + p1);
        System.out.println("p2 = " + p2);
    }
    return result == expected;
}
 
Example 33
Project: openjdk9   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    String url1 = "http://www.foo.com/-";
    String url2 = "http://www.foo.com/a/b";
    URLPermission p1 = new URLPermission(url1, arg1);
    URLPermission p2 = new URLPermission(url2, arg2);
    boolean result = p1.implies(p2);

    return result == expected;
}
 
Example 34
Project: openjdk9   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
Example 35
Project: jdk8u_jdk   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 36
Project: jdk8u_jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 37
Project: jdk8u_jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
Example 38
Project: jdk8u_jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
boolean execute() {
    URLPermission p1 = new URLPermission (arg1, "GET:*");
    URLPermission p2 = new URLPermission (arg2, "GET:*");
    boolean result = p1.implies(p2);
    if (result != expected) {
        System.out.println("p1 = " + p1);
        System.out.println("p2 = " + p2);
    }
    return result == expected;
}
 
Example 39
Project: jdk8u_jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    String url1 = "http://www.foo.com/-";
    String url2 = "http://www.foo.com/a/b";
    URLPermission p1 = new URLPermission(url1, arg1);
    URLPermission p2 = new URLPermission(url2, arg2);
    boolean result = p1.implies(p2);

    return result == expected;
}
 
Example 40
Project: jdk8u_jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
Example 41
Project: lookaside_java-1.8.0-openjdk   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 42
Project: lookaside_java-1.8.0-openjdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 43
Project: lookaside_java-1.8.0-openjdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
Example 44
Project: lookaside_java-1.8.0-openjdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
boolean execute() {
    URLPermission p1 = new URLPermission (arg1, "GET:*");
    URLPermission p2 = new URLPermission (arg2, "GET:*");
    boolean result = p1.implies(p2);
    if (result != expected) {
        System.out.println("p1 = " + p1);
        System.out.println("p2 = " + p2);
    }
    return result == expected;
}
 
Example 45
Project: lookaside_java-1.8.0-openjdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    String url1 = "http://www.foo.com/-";
    String url2 = "http://www.foo.com/a/b";
    URLPermission p1 = new URLPermission(url1, arg1);
    URLPermission p2 = new URLPermission(url2, arg2);
    boolean result = p1.implies(p2);

    return result == expected;
}
 
Example 46
Project: lookaside_java-1.8.0-openjdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
Example 47
Project: infobip-open-jdk-8   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 48
Project: infobip-open-jdk-8   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 49
Project: infobip-open-jdk-8   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
Example 50
Project: infobip-open-jdk-8   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
boolean execute() {
    URLPermission p1 = new URLPermission (arg1, "GET:*");
    URLPermission p2 = new URLPermission (arg2, "GET:*");
    boolean result = p1.implies(p2);
    if (result != expected) {
        System.out.println("p1 = " + p1);
        System.out.println("p2 = " + p2);
    }
    return result == expected;
}
 
Example 51
Project: infobip-open-jdk-8   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    String url1 = "http://www.foo.com/-";
    String url2 = "http://www.foo.com/a/b";
    URLPermission p1 = new URLPermission(url1, arg1);
    URLPermission p2 = new URLPermission(url2, arg2);
    boolean result = p1.implies(p2);

    return result == expected;
}
 
Example 52
Project: infobip-open-jdk-8   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
Example 53
Project: jdk8u-dev-jdk   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 54
Project: jdk8u-dev-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 55
Project: jdk8u-dev-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
Example 56
Project: jdk8u-dev-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
boolean execute() {
    URLPermission p1 = new URLPermission (arg1, "GET:*");
    URLPermission p2 = new URLPermission (arg2, "GET:*");
    boolean result = p1.implies(p2);
    if (result != expected) {
        System.out.println("p1 = " + p1);
        System.out.println("p2 = " + p2);
    }
    return result == expected;
}
 
Example 57
Project: jdk8u-dev-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    String url1 = "http://www.foo.com/-";
    String url2 = "http://www.foo.com/a/b";
    URLPermission p1 = new URLPermission(url1, arg1);
    URLPermission p2 = new URLPermission(url2, arg2);
    boolean result = p1.implies(p2);

    return result == expected;
}
 
Example 58
Project: jdk8u-dev-jdk   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
Example 59
Project: OLD-OpenJDK8   File: HttpURLConnection.java   Source Code and License 5 votes vote down vote up
/**
 *  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;
}
 
Example 60
Project: OLD-OpenJDK8   File: URLPermissionTest.java   Source Code and License 5 votes vote down vote up
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}