• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java URLPermission类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中java.net.URLPermission的典型用法代码示例。如果您正苦于以下问题:Java URLPermission类的具体用法?Java URLPermission怎么用?Java URLPermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



URLPermission类属于java.net包,在下文中一共展示了URLPermission类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: serializationTest

import java.net.URLPermission; //导入依赖的package包/类
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;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:URLPermissionTest.java


示例2: test2

import java.net.URLPermission; //导入依赖的package包/类
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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:URLTest.java


示例3: test3

import java.net.URLPermission; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:URLTest.java


示例4: addCommonPermissions

import java.net.URLPermission; //导入依赖的package包/类
/**
 * 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"));
}
 
开发者ID:rapidminer,项目名称:rapidminer-studio,代码行数:31,代码来源:PluginSandboxPolicy.java


示例5: URLtoSocketPermission

import java.net.URLPermission; //导入依赖的package包/类
/**
 *  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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:HttpURLConnection.java


示例6: execute

import java.net.URLPermission; //导入依赖的package包/类
@Override
boolean execute() {
    try {
        URLPermission p = new URLPermission(arg);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:URLPermissionTest.java


示例7: getPermission

import java.net.URLPermission; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:Utils.java


示例8: test1

import java.net.URLPermission; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:URLTest.java


示例9: LookupTestPolicy

import java.net.URLPermission; //导入依赖的package包/类
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"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:LookupTest.java


示例10: getPermission

import java.net.URLPermission; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:40,代码来源:Utils.java



注:本文中的java.net.URLPermission类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SAMUtils类代码示例发布时间:2022-05-22
下一篇:
Java MultipartUtils类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap