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


Java Policy.setPolicy方法代碼示例

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


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

示例1: setUp

import java.security.Policy; //導入方法依賴的package包/類
static void setUp(TestCase test) {
    switch (test) {
        case SECURE:
            if (policy == null && System.getSecurityManager() != null) {
                throw new IllegalStateException("SecurityManager already set");
            } else if (policy == null) {
                policy = new SimplePolicy(TestCase.SECURE, allowAll);
                Policy.setPolicy(policy);
                System.setSecurityManager(new SecurityManager());
            }
            if (System.getSecurityManager() == null) {
                throw new IllegalStateException("No SecurityManager.");
            }
            if (policy == null) {
                throw new IllegalStateException("policy not configured");
            }
            break;
        case UNSECURE:
            if (System.getSecurityManager() != null) {
                throw new IllegalStateException("SecurityManager already set");
            }
            break;
        default:
            new InternalError("No such testcase: " + test);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:UpdateConfigurationTest.java

示例2: setUp

import java.security.Policy; //導入方法依賴的package包/類
static void setUp(TestCase test) {
    switch (test) {
        case SECURE:
            if (policy == null && System.getSecurityManager() != null) {
                throw new IllegalStateException("SecurityManager already set");
            } else if (policy == null) {
                policy = new SimplePolicy(TestCase.SECURE, allowAll);
                Policy.setPolicy(policy);
                System.setSecurityManager(new SecurityManager());
            }
            if (System.getSecurityManager() == null) {
                throw new IllegalStateException("No SecurityManager.");
            }
            if (policy == null) {
                throw new IllegalStateException("policy not configured");
            }
            break;
        case UNSECURE:
            if (System.getSecurityManager() != null) {
                throw new IllegalStateException("SecurityManager already set");
            }
            break;
        default:
            throw new InternalError("No such testcase: " + test);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:ClassDeclaredFieldsTest.java

示例3: main

import java.security.Policy; //導入方法依賴的package包/類
/**
 * Runs all unit tests in the given test suite.
 * Actual behavior influenced by jsr166.* system properties.
 */
static void main(Test suite, String[] args) {
    if (useSecurityManager) {
        System.err.println("Setting a permissive security manager");
        Policy.setPolicy(permissivePolicy());
        System.setSecurityManager(new SecurityManager());
    }
    for (int i = 0; i < suiteRuns; i++) {
        TestResult result = newPithyTestRunner().doRun(suite);
        if (!result.wasSuccessful())
            System.exit(1);
        System.gc();
        System.runFinalization();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:JSR166TestCase.java

示例4: configure

import java.security.Policy; //導入方法依賴的package包/類
/**
 * Initializes SecurityManager for the environment
 * Can only happen once!
 * @param environment configuration for generating dynamic permissions
 * @param filterBadDefaults true if we should filter out bad java defaults in the system policy.
 */
static void configure(Environment environment, boolean filterBadDefaults) throws IOException, NoSuchAlgorithmException {

    // enable security policy: union of template and environment-based paths, and possibly plugin permissions
    Policy.setPolicy(new ESPolicy(createPermissions(environment), getPluginPermissions(environment), filterBadDefaults));

    // enable security manager
    System.setSecurityManager(new SecureSM(new String[] { "org.elasticsearch.bootstrap.", "org.elasticsearch.cli" }));

    // do some basic tests
    selfTest();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:Security.java

示例5: main

import java.security.Policy; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
    System.setProperty(CONFIG_FILE_KEY,
            new File(System.getProperty("test.src", "."),
                    "rootlogger.properties").getAbsolutePath());
    System.out.println(CONFIG_FILE_KEY + "="
            + System.getProperty(CONFIG_FILE_KEY));
    if (! new File(System.getProperty(CONFIG_FILE_KEY)).canRead()) {
        throw new RuntimeException("can't read config file: "
                + System.getProperty(CONFIG_FILE_KEY));
    }

    final String configFile = System.getProperty(CONFIG_FILE_KEY);

    test("no security");

    LogManager.getLogManager().readConfiguration();

    Policy.setPolicy(new SimplePolicy(configFile));
    System.setSecurityManager(new SecurityManager());

    test("security");

    LogManager.getLogManager().readConfiguration();

    final JavaAWTAccessStub access = new JavaAWTAccessStub();
    SharedSecrets.setJavaAWTAccess(access);

    test("security and no context");

    for (Context ctx : Context.values()) {

        LogManager.getLogManager().readConfiguration();

        access.setContext(ctx);

        test("security and context " + ctx);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:39,代碼來源:RootLevelInConfigFile.java

示例6: setUp

import java.security.Policy; //導入方法依賴的package包/類
static void setUp(TestCase test, Properties propertyFile) {
    switch (test) {
        case SECURE:
            if (policy == null && System.getSecurityManager() != null) {
                throw new IllegalStateException("SecurityManager already set");
            } else if (policy == null) {
                policy = new SimplePolicy(TestCase.SECURE, allowAll);
                Policy.setPolicy(policy);
                System.setSecurityManager(new SecurityManager());
            }
            if (System.getSecurityManager() == null) {
                throw new IllegalStateException("No SecurityManager.");
            }
            if (policy == null) {
                throw new IllegalStateException("policy not configured");
            }
            break;
        case UNSECURE:
            if (System.getSecurityManager() != null) {
                throw new IllegalStateException("SecurityManager already set");
            }
            break;
        default:
            new InternalError("No such testcase: " + test);
    }
    doPrivileged(() -> {
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            propertyFile.store(bytes, propertyFile.getProperty("test.name"));
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes.toByteArray());
            LogManager.getLogManager().readConfiguration(bais);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    });
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,代碼來源:FileHandlerPath.java

示例7: tearDown

import java.security.Policy; //導入方法依賴的package包/類
public void tearDown() {
    // turn off security manager and restore policy
    System.setSecurityManager(null);
    Policy.setPolicy(origPolicy);
    if (hasSM) {
        System.setSecurityManager(new SecurityManager());
    }
    System.out.println("\nNumber of tests passed: " + passed);
    System.out.println("Number of tests failed: " + failed + "\n");

    if (errMessage != null ) {
        throw new RuntimeException(errMessage);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:TestBase.java

示例8: testSecure

import java.security.Policy; //導入方法依賴的package包/類
/**
 * Test with security manager.
 * @param loggerName The logger to use.
 * @throws Exception if the test fails.
 */
public static void testSecure(String loggerName) throws Exception {
    if (System.getSecurityManager() != null) {
        throw new Error("Security manager is already set");
    }
    Policy.setPolicy(new SimplePolicy(TestCase.SECURE));
    System.setSecurityManager(new SecurityManager());
    test(loggerName);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:TestConfigurationListeners.java

示例9: testPermission

import java.security.Policy; //導入方法依賴的package包/類
/**
 * Test the LoggingPermission("control") is required.
 * @param loggerName The logger to use.
 */
public static void testPermission(String loggerName) {
    if (System.getSecurityManager() != null) {
        throw new Error("Security manager is already set");
    }
    Policy.setPolicy(new SimplePolicy(TestCase.PERMISSION));
    System.setSecurityManager(new SecurityManager());
    final ResourceBundle bundle = ResourceBundle.getBundle(LIST_BUNDLE_NAME);
    Logger foobar = Logger.getLogger(loggerName);
    try {
        foobar.setResourceBundle(bundle);
        throw new RuntimeException("Permission not checked!");
    } catch (AccessControlException x) {
        if (x.getPermission() instanceof LoggingPermission) {
            if ("control".equals(x.getPermission().getName())) {
                System.out.println("Got expected exception: " + x);
                return;
            }
        }
        throw new RuntimeException("Unexpected exception: "+x, x);
    }

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:27,代碼來源:TestSetResourceBundle.java

示例10: tearDown

import java.security.Policy; //導入方法依賴的package包/類
public void tearDown() {
    // turn off security manager and restore policy
    System.setSecurityManager(null);
    Policy.setPolicy(origPolicy);
    if (hasSM) {
        System.setSecurityManager(new SecurityManager());
    }
    System.out.println("\nNumber of tests passed: " + passed);
    System.out.println("Number of tests failed: " + failed + "\n");

    if (errMsg != null ) {
        throw new RuntimeException(errMsg);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:TestBase.java

示例11: setPolicy

import java.security.Policy; //導入方法依賴的package包/類
protected static void setPolicy(Policy p) {
    Policy.setPolicy(p);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:BaseTest.java

示例12: allProcessesWithPermission

import java.security.Policy; //導入方法依賴的package包/類
@Test
public void allProcessesWithPermission() {
    Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess")));
    ProcessHandle.allProcesses();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:PermissionTest.java

示例13: setSecurityManager

import java.security.Policy; //導入方法依賴的package包/類
static void setSecurityManager() {
    if (System.getSecurityManager() == null) {
        Policy.setPolicy(new SimplePolicy(allowControl, allowAll));
        System.setSecurityManager(new SecurityManager());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:CustomLoggerTest.java

示例14: childrenWithPermission

import java.security.Policy; //導入方法依賴的package包/類
@Test
public void childrenWithPermission() {
    Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess")));
    currentHndl.children();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:PermissionTest.java

示例15: parentWithPermission

import java.security.Policy; //導入方法依賴的package包/類
@Test
public void parentWithPermission() {
    Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess")));
    currentHndl.parent();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:PermissionTest.java


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