當前位置: 首頁>>代碼示例>>Java>>正文


Java Policy.getInstance方法代碼示例

本文整理匯總了Java中java.security.Policy.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java Policy.getInstance方法的具體用法?Java Policy.getInstance怎麽用?Java Policy.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.Policy的用法示例。


在下文中一共展示了Policy.getInstance方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.security.Policy; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        // Check policy with no java.security.policy property set
        Policy p = Policy.getPolicy();
        checkPolicy(p);

        // Check policy with java.security.policy '=' option
        System.setProperty("java.security.policy", "Extra.policy");
        p.refresh();
        checkPolicy(p);

        // Check policy with java.security.policy override '==' option
        System.setProperty("java.security.policy", "=Extra.policy");
        p.refresh();
        checkPolicy(p);

        // Check Policy.getInstance
        URI policyURI = Paths.get(System.getProperty("test.src"),
                                  "Extra.policy").toUri();
        p = Policy.getInstance("JavaPolicy", new URIParameter(policyURI));
        checkPolicy(p);
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:DefaultPolicy.java

示例2: main

import java.security.Policy; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        Security.addProvider(new TestProvider());

        MySecureClassLoader scl = new MySecureClassLoader();

        File policyFile = new File(System.getProperty("test.src", "."),
                                   "DefineClass.policy");
        Policy p = Policy.getInstance("JavaPolicy",
                                      new URIParameter(policyFile.toURI()));
        Policy.setPolicy(p);

        System.setSecurityManager(new SecurityManager());
        ArrayList<Permission> perms1 = getPermissions(scl, p,
                                                      "http://localhost/",
                                                      "foo.Foo", FOO_CLASS,
                                                      null);
        checkPerms(perms1, GRANTED_PERMS);
        ArrayList<Permission> perms2 = getPermissions(scl, p,
                                                      "http://127.0.0.1/",
                                                      "bar.Bar", BAR_CLASS,
                                                      null);
        checkPerms(perms2, GRANTED_PERMS);
        assert(perms1.equals(perms2));

        // check that class signed by baz is granted an additional permission
        Certificate[] chain = new Certificate[] {getCert(BAZ_CERT)};
        ArrayList<Permission> perms3 = getPermissions(scl, p,
                                                      "http://localhost/",
                                                      "baz.Baz", BAZ_CLASS,
                                                      chain);
        List<Permission> perms = new ArrayList<>(Arrays.asList(GRANTED_PERMS));
        perms.add(new PropertyPermission("user.dir", "read"));
        checkPerms(perms3, perms.toArray(new Permission[0]));
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:DefineClass.java


注:本文中的java.security.Policy.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。