java.lang.SecurityManager.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中java.lang.SecurityManager.<init>()方法的一些代码示例,展示了SecurityManager.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SecurityManager.<init>()方法的具体详情如下:
包路径:java.lang.SecurityManager
类名称:SecurityManager
方法名:<init>

SecurityManager.<init>介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

public CallbacksSecurityTests() {
  // setup security
  if (System.getSecurityManager() == null) {
    Policy policy = Policy.getPolicy();
    URL policyURL = getClass()
        .getResource(
            "/org/springframework/beans/factory/support/security/policy.all");
    System.setProperty("java.security.policy", policyURL.toString());
    System.setProperty("policy.allowSystemProperty", "true");
    policy.refresh();
    System.setSecurityManager(new SecurityManager());
  }
}

代码示例来源:origin: stackoverflow.com

System.setSecurityManager(new SecurityManager());

代码示例来源:origin: groovy/groovy-core

protected void setUp() {
  if (checkSecurity()) {
    securityManager = System.getSecurityManager();
    if (securityManager == null) {
      System.setSecurityManager(new SecurityManager());
    }
  }
  currentClassLoader = Thread.currentThread().getContextClassLoader();
  AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {
      Thread.currentThread().setContextClassLoader(loader);
      return null;
    }
  });
}

代码示例来源:origin: ben-manes/caffeine

/**
 * Runs all JSR166 unit tests using junit.textui.TestRunner.
 * Optional command line arg provides the number of iterations to
 * repeat running the tests.
 */
public static void main(String[] args) {
  if (useSecurityManager) {
    System.err.println("Setting a permissive security manager");
    Policy.setPolicy(permissivePolicy());
    System.setSecurityManager(new SecurityManager());
  }
  int iters = (args.length == 0) ? 1 : Integer.parseInt(args[0]);
  Test s = suite();
  for (int i = 0; i < iters; ++i) {
    junit.textui.TestRunner.run(s);
    System.gc();
    System.runFinalization();
  }
  System.exit(0);
}

代码示例来源:origin: google/guava

public void testUnloadableInStaticFieldIfClosed() throws Exception {
 if (isJdk9OrHigher()) {
  return;
 }
 Policy oldPolicy = Policy.getPolicy();
 SecurityManager oldSecurityManager = System.getSecurityManager();
 try {
  Policy.setPolicy(new PermissivePolicy());
  System.setSecurityManager(new SecurityManager());
  WeakReference<ClassLoader> loaderRef = doTestUnloadableInStaticFieldIfClosed();
  GcFinalization.awaitClear(loaderRef);
 } finally {
  System.setSecurityManager(oldSecurityManager);
  Policy.setPolicy(oldPolicy);
 }
}

代码示例来源:origin: google/guava

/**
 * Tests that the use of a {@link FinalizableReferenceQueue} does not subsequently prevent the
 * loader of that class from being garbage-collected even if there is a {@link SecurityManager}.
 * The {@link SecurityManager} environment makes such leaks more likely because when you create a
 * {@link URLClassLoader} with a {@link SecurityManager}, the creating code's {@link
 * java.security.AccessControlContext} is captured, and that references the creating code's {@link
 * ClassLoader}.
 */
public void testUnloadableWithSecurityManager() throws Exception {
 if (isJdk9OrHigher()) {
  return;
 }
 Policy oldPolicy = Policy.getPolicy();
 SecurityManager oldSecurityManager = System.getSecurityManager();
 try {
  Policy.setPolicy(new PermissivePolicy());
  System.setSecurityManager(new SecurityManager());
  doTestUnloadable();
 } finally {
  System.setSecurityManager(oldSecurityManager);
  Policy.setPolicy(oldPolicy);
 }
}

代码示例来源:origin: languagetool-org/languagetool

@BeforeClass
public static void startup() throws Exception {
 Policy.setPolicy(new MyPolicy());
 System.setSecurityManager(new SecurityManager());
}

代码示例来源:origin: google/guava

/**
 * Runs Runnable r with a security policy that permits precisely the specified permissions. If
 * there is no current security manager, the runnable is run twice, both with and without a
 * security manager. We require that any security manager permit getPolicy/setPolicy.
 */
public void runWithPermissions(Runnable r, Permission... permissions) {
 SecurityManager sm = System.getSecurityManager();
 if (sm == null) {
  r.run();
  Policy savedPolicy = Policy.getPolicy();
  try {
   Policy.setPolicy(permissivePolicy());
   System.setSecurityManager(new SecurityManager());
   runWithPermissions(r, permissions);
  } finally {
   System.setSecurityManager(null);
   Policy.setPolicy(savedPolicy);
  }
 } else {
  Policy savedPolicy = Policy.getPolicy();
  AdjustablePolicy policy = new AdjustablePolicy(permissions);
  Policy.setPolicy(policy);
  try {
   r.run();
  } finally {
   policy.addPermission(new SecurityPermission("setPolicy"));
   Policy.setPolicy(savedPolicy);
  }
 }
}

代码示例来源:origin: dlew/joda-time-android

@Test
public void testDefaultSecurity() {
  if (OLD_JDK) {
    return;
  }
  try {
    Policy.setPolicy(RESTRICT);
    System.setSecurityManager(new SecurityManager());
    DateTimeZone.setDefault(PARIS);
    fail();
  } catch (SecurityException ex) {
    // ok
  } finally {
    System.setSecurityManager(null);
    Policy.setPolicy(ALLOW);
  }
}

代码示例来源:origin: dlew/joda-time-android

@Test
public void testNameProviderSecurity() {
  if (OLD_JDK) {
    return;
  }
  try {
    Policy.setPolicy(RESTRICT);
    System.setSecurityManager(new SecurityManager());
    DateTimeZone.setNameProvider(new MockOKButNullNameProvider());
    fail();
  } catch (SecurityException ex) {
    // ok
  } finally {
    System.setSecurityManager(null);
    Policy.setPolicy(ALLOW);
  }
}

代码示例来源:origin: dlew/joda-time-android

@Test
public void testProviderSecurity() {
  if (OLD_JDK) {
    return;
  }
  try {
    Policy.setPolicy(RESTRICT);
    System.setSecurityManager(new SecurityManager());
    DateTimeZone.setProvider(new MockOKProvider());
    fail();
  } catch (SecurityException ex) {
    // ok
  } finally {
    System.setSecurityManager(null);
    Policy.setPolicy(ALLOW);
  }
}

代码示例来源:origin: ben-manes/caffeine

try {
  Policy.setPolicy(permissivePolicy());
  System.setSecurityManager(new SecurityManager());
  runWithSecurityManagerWithPermissions(r, permissions);
} finally {

代码示例来源:origin: jankotek/mapdb

try {
  Policy.setPolicy(permissivePolicy());
  System.setSecurityManager(new SecurityManager());
  runWithSecurityManagerWithPermissions(r, permissions);
} finally {

代码示例来源:origin: org.drools/drools-compiler

@Before
public void init() {
  final String policy = SerializationSecurityPolicyTest.class.getResource("serialization-rules.policy").getFile();
  System.setProperty("java.security.policy", policy);
  System.setProperty("kie.security.policy", policy);
  Policy.getPolicy().refresh();
  System.setSecurityManager(new SecurityManager());
}

代码示例来源:origin: org.drools/drools-compiler

@BeforeClass
public static void initSecurityManager() throws NoSuchAlgorithmException {
  oldSecurityManager = System.getSecurityManager();
  oldPolicy = Policy.getPolicy();
  // permissive policy
  Policy.setPolicy(new Policy() {
    @Override
    public boolean implies(ProtectionDomain domain, Permission permission) {
      return true;
    }
  });
  System.setSecurityManager(new SecurityManager());
}

代码示例来源:origin: stackoverflow.com

//set the policy file as the system securuty policy
System.setProperty("java.security.policy", "file:/C:/java.policy");
// create a security manager
SecurityManager sm = new SecurityManager();
//alternatively, get the current securiy manager using System.getSecuriyManager() 
//set the system security manager
System.setSecurityManager(sm);

代码示例来源:origin: stackoverflow.com

public static void main(String args[]){

  System.setSecurityManager(new SecurityManager());
  String jedi1 = "jedi";

  toUpperCase(jedi1);
  System.out.println(jedi1);
}

代码示例来源:origin: lionoggo/FastApp

public static boolean deleteFileWithPath(String filePath) {
  SecurityManager checker = new SecurityManager();
  File f = new File(filePath);
  checker.checkDelete(filePath);
  if (f.isFile()) {
    f.delete();
    return true;
  }
  return false;
}

代码示例来源:origin: lionoggo/Akit-Reader

public static boolean deleteFileWithPath(String filePath) {
  SecurityManager checker = new SecurityManager();
  File f = new File(filePath);
  checker.checkDelete(filePath);
  if (f.isFile()) {
    f.delete();
    return true;
  }
  return false;
}

代码示例来源:origin: z-android/ZLayer

public static boolean deleteFileWithPath(String filePath) {
  SecurityManager checker = new SecurityManager();
  File f = new File(filePath);
  checker.checkDelete(filePath);
  if(f.isFile()) {
    f.delete();
    return true;
  } else {
    return false;
  }
}

相关文章