本文整理匯總了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);
}
}
示例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);
}
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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);
}
});
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例11: setPolicy
import java.security.Policy; //導入方法依賴的package包/類
protected static void setPolicy(Policy p) {
Policy.setPolicy(p);
}
示例12: allProcessesWithPermission
import java.security.Policy; //導入方法依賴的package包/類
@Test
public void allProcessesWithPermission() {
Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess")));
ProcessHandle.allProcesses();
}
示例13: setSecurityManager
import java.security.Policy; //導入方法依賴的package包/類
static void setSecurityManager() {
if (System.getSecurityManager() == null) {
Policy.setPolicy(new SimplePolicy(allowControl, allowAll));
System.setSecurityManager(new SecurityManager());
}
}
示例14: childrenWithPermission
import java.security.Policy; //導入方法依賴的package包/類
@Test
public void childrenWithPermission() {
Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess")));
currentHndl.children();
}
示例15: parentWithPermission
import java.security.Policy; //導入方法依賴的package包/類
@Test
public void parentWithPermission() {
Policy.setPolicy(new TestPolicy(new RuntimePermission("manageProcess")));
currentHndl.parent();
}