java.net.URLPermission源码实例Demo

java.net.NetPermission#java.net.URLPermission源码实例Demo

下面列出了java.net.NetPermission#java.net.URLPermission 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: URLPermissionTest.java
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;
    }
}
 
源代码2 项目: rapidminer-studio   文件: PluginSandboxPolicy.java
/**
 * 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("showWindowWithoutWarningBanner"));
	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"));
}
 
源代码3 项目: jdk8u60   文件: URLPermissionTest.java
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;
    }
}
 
源代码4 项目: openjdk-jdk8u   文件: URLPermissionTest.java
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;
    }
}
 
源代码5 项目: jdk8u-jdk   文件: URLPermissionTest.java
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;
    }
}
 
源代码6 项目: openjdk-jdk9   文件: URLTest.java
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");
}
 
源代码7 项目: openjdk-jdk9   文件: URLPermissionTest.java
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;
    }
}
 
源代码8 项目: hottub   文件: URLPermissionTest.java
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;
    }
}
 
源代码9 项目: dragonwell8_jdk   文件: URLPermissionTest.java
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
源代码10 项目: dragonwell8_jdk   文件: URLPermissionTest.java
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
源代码11 项目: dragonwell8_jdk   文件: URLPermissionTest.java
@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;
}
 
源代码12 项目: jdk8u_jdk   文件: URLPermissionTest.java
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
源代码13 项目: openjdk-8   文件: HttpURLConnection.java
/**
 *  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;
}
 
源代码14 项目: openjdk-8-source   文件: URLPermissionTest.java
@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;
}
 
源代码15 项目: jdk8u_jdk   文件: URLPermissionTest.java
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;
}
 
源代码16 项目: TencentKona-8   文件: URLPermissionTest.java
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
源代码17 项目: TencentKona-8   文件: URLPermissionTest.java
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;
}
 
源代码18 项目: TencentKona-8   文件: URLPermissionTest.java
@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;
}
 
源代码19 项目: TencentKona-8   文件: URLPermissionTest.java
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
源代码20 项目: openjdk-8-source   文件: URLPermissionTest.java
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
源代码21 项目: jdk8u60   文件: HttpURLConnection.java
/**
 *  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;
}
 
源代码22 项目: jdk8u_jdk   文件: URLPermissionTest.java
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
源代码23 项目: jdk8u60   文件: URLPermissionTest.java
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return false;
    } catch (IllegalArgumentException e) {
        return true;
    }
}
 
源代码24 项目: jdk8u-jdk   文件: HttpURLConnection.java
/**
 *  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;
}
 
源代码25 项目: jdk8u_jdk   文件: URLPermissionTest.java
@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;
}
 
源代码26 项目: jdk8u60   文件: URLPermissionTest.java
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
源代码27 项目: jdk8u-jdk   文件: URLPermissionTest.java
@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;
}
 
源代码28 项目: openjdk-jdk8u   文件: URLPermissionTest.java
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
源代码29 项目: openjdk-8-source   文件: URLPermissionTest.java
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}
 
源代码30 项目: jdk8u-jdk   文件: URLPermissionTest.java
@Override
  boolean execute() {
    URLPermission p1 = new URLPermission(arg1);
    URLPermission p2 = new URLPermission(arg2);
    boolean result = p1.equals(p2);

    return result == expected;
}