Tabnine Logo
System.setSecurityManager
Code IndexAdd Tabnine to your IDE (free)

How to use
setSecurityManager
method
in
java.lang.System

Best Java code snippets using java.lang.System.setSecurityManager (Showing top 20 results out of 2,133)

origin: neo4j/neo4j

@Override
protected void after()
{
  System.setSecurityManager( originalSecurityManager );
}
origin: google/guava

public void testExistsThrowsSecurityException() throws IOException, URISyntaxException {
 SecurityManager oldSecurityManager = System.getSecurityManager();
 try {
  doTestExistsThrowsSecurityException();
 } finally {
  System.setSecurityManager(oldSecurityManager);
 }
}
origin: spring-projects/spring-framework

@After
public void tearDown() {
  env.remove(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME);
  System.setSecurityManager(originalSecurityManager);
}
origin: org.apache.logging.log4j/log4j-api

  private void before() {
    securityManagerBefore = System.getSecurityManager();
    System.setSecurityManager(securityManager);
  }
};
origin: google/guava

/**
 * Tests that the use of a {@link FinalizableReferenceQueue} does not subsequently prevent the
 * loader of that class from being garbage-collected.
 */
public void testUnloadableWithoutSecurityManager() throws Exception {
 if (isJdk9OrHigher()) {
  return;
 }
 SecurityManager oldSecurityManager = System.getSecurityManager();
 try {
  System.setSecurityManager(null);
  doTestUnloadable();
 } finally {
  System.setSecurityManager(oldSecurityManager);
 }
}
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: neo4j/neo4j

@Override
protected void before()
{
  originalSecurityManager = System.getSecurityManager();
  TestSecurityManager testSecurityManager = new TestSecurityManager( originalSecurityManager );
  System.setSecurityManager( testSecurityManager );
}
origin: pentaho/pentaho-kettle

@After
public void tearDown() {
 System.setSecurityManager( oldSecurityManager );
 sysOutContent = null;
 sysErrContent = null;
 mockRepositoriesMeta = null;
 mockRepositoryMeta = null;
 mockRepository = null;
 mockRepositoryDirectory = null;
}
origin: google/guava

System.setSecurityManager(
  new SecurityManager() {
   @Override
 assertEquals(oldName, Thread.currentThread().getName());
} finally {
 System.setSecurityManager(null);
origin: pentaho/pentaho-kettle

@Before
public void setUp() throws KettleException {
 KettleEnvironment.init();
 oldSecurityManager = System.getSecurityManager();
 sysOutContent = new ByteArrayOutputStream();
 sysErrContent = new ByteArrayOutputStream();
 System.setSecurityManager( new MySecurityManager( oldSecurityManager ) );
 mockRepositoriesMeta = mock( RepositoriesMeta.class );
 mockRepositoryMeta = mock( RepositoryMeta.class );
 mockRepository = mock( Repository.class );
 mockRepositoryDirectory = mock( RepositoryDirectoryInterface.class );
}
origin: languagetool-org/languagetool

@Test
public void testPermissionManager() throws Exception {
 try {
  PatternRuleLoader loader = new PatternRuleLoader();
  // do not crash if Authenticator.setDefault() is forbidden,
  // see https://github.com/languagetool-org/languagetool/issues/255
  loader.getRules(new ByteArrayInputStream("<rules lang='xx'></rules>".getBytes("utf-8")), "fakeName");
 } finally {
  System.setSecurityManager(null);
 }
}
origin: spring-projects/spring-framework

@Test
public void systemPropertiesSecurityManager() {
  AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
  GenericBeanDefinition bd = new GenericBeanDefinition();
  bd.setBeanClass(TestBean.class);
  bd.getPropertyValues().add("country", "#{systemProperties.country}");
  ac.registerBeanDefinition("tb", bd);
  SecurityManager oldSecurityManager = System.getSecurityManager();
  try {
    System.setProperty("country", "NL");
    SecurityManager securityManager = new SecurityManager() {
      @Override
      public void checkPropertiesAccess() {
        throw new AccessControlException("Not Allowed");
      }
      @Override
      public void checkPermission(Permission perm) {
        // allow everything else
      }
    };
    System.setSecurityManager(securityManager);
    ac.refresh();
    TestBean tb = ac.getBean("tb", TestBean.class);
    assertEquals("NL", tb.getCountry());
  }
  finally {
    System.setSecurityManager(oldSecurityManager);
    System.getProperties().remove("country");
  }
}
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: spring-projects/spring-framework

System.setSecurityManager(securityManager);
System.setSecurityManager(oldSecurityManager);
getModifiableSystemEnvironment().remove(ALLOWED_PROPERTY_NAME);
getModifiableSystemEnvironment().remove(DISALLOWED_PROPERTY_NAME);
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: google/guava

System.setSecurityManager(disallowFilesSecurityManager);
try {
 file.exists();
origin: spring-projects/spring-framework

@Test
public void securityManagerDisallowsAccessToSystemEnvironmentButAllowsAccessToIndividualKeys() {
  SecurityManager securityManager = new SecurityManager() {
    @Override
    public void checkPermission(Permission perm) {
      // Disallowing access to System#getenv means that our
      // ReadOnlySystemAttributesMap will come into play.
      if ("getenv.*".equals(perm.getName())) {
        throw new AccessControlException("Accessing the system environment is disallowed");
      }
    }
  };
  System.setSecurityManager(securityManager);
  DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
  AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf);
  reader.register(C1.class);
  assertThat(bf.containsBean("c1"), is(true));
}
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: spring-projects/spring-framework

@Test
public void securityManagerDisallowsAccessToSystemEnvironmentAndDisallowsAccessToIndividualKey() {
  SecurityManager securityManager = new SecurityManager() {
    @Override
    public void checkPermission(Permission perm) {
      // Disallowing access to System#getenv means that our
      // ReadOnlySystemAttributesMap will come into play.
      if ("getenv.*".equals(perm.getName())) {
        throw new AccessControlException("Accessing the system environment is disallowed");
      }
      // Disallowing access to the spring.profiles.active property means that
      // the BeanDefinitionReader won't be able to determine which profiles are
      // active. We should see an INFO-level message in the console about this
      // and as a result, any components marked with a non-default profile will
      // be ignored.
      if (("getenv." + AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME).equals(perm.getName())) {
        throw new AccessControlException(
            format("Accessing system environment variable [%s] is disallowed",
                AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME));
      }
    }
  };
  System.setSecurityManager(securityManager);
  DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
  AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf);
  reader.register(C1.class);
  assertThat(bf.containsBean("c1"), is(false));
}
origin: languagetool-org/languagetool

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

Javadoc

Throws SecurityException.

Security managers do not provide a secure environment for executing untrusted code and are unsupported on Android. Untrusted code cannot be safely isolated within a single VM on Android, so this method always throws a SecurityException.

Popular methods of System

  • currentTimeMillis
    Returns the current time in milliseconds. Note that while the unit of time of the return value is a
  • getProperty
    Returns the value of a particular system property. The defaultValue will be returned if no such prop
  • arraycopy
  • exit
  • setProperty
    Sets the value of a particular system property.
  • nanoTime
    Returns the current timestamp of the most precise timer available on the local system, in nanosecond
  • getenv
    Returns the value of the environment variable with the given name, or null if no such variable exist
  • getProperties
    Returns the system properties. Note that this is not a copy, so that changes made to the returned Pr
  • identityHashCode
    Returns an integer hash code for the parameter. The hash code returned is the same one that would be
  • getSecurityManager
    Gets the system security interface.
  • gc
    Indicates to the VM that it would be a good time to run the garbage collector. Note that this is a h
  • lineSeparator
    Returns the system's line separator. On Android, this is "\n". The value comes from the value of the
  • gc,
  • lineSeparator,
  • clearProperty,
  • setOut,
  • setErr,
  • console,
  • loadLibrary,
  • load,
  • mapLibraryName

Popular in Java

  • Making http requests using okhttp
  • setScale (BigDecimal)
  • getSupportFragmentManager (FragmentActivity)
  • runOnUiThread (Activity)
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now