use of java.util.PropertyPermission in project guava by google.
the class AbstractFutureInnocuousThreadTest method setUp.
@Override
protected void setUp() throws Exception {
// Load the "normal" copy of SettableFuture and related classes.
SettableFuture<?> unused = SettableFuture.create();
// Hack to load AbstractFuture et. al. in a new classloader so that it tries to re-read the
// cancellation-cause system property. This allows us to test what happens if reading the
// property is forbidden and then continue running tests normally in one jvm without resorting
// to even crazier hacks to reset static final boolean fields.
final String concurrentPackage = SettableFuture.class.getPackage().getName();
classReloader = new URLClassLoader(ClassPathUtil.getClassPathUrls()) {
@GuardedBy("loadedClasses")
final Map<String, Class<?>> loadedClasses = new HashMap<>();
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if (name.startsWith(concurrentPackage) && // Use other classloader for ListenableFuture, so that the objects can interact
!ListenableFuture.class.getName().equals(name)) {
synchronized (loadedClasses) {
Class<?> toReturn = loadedClasses.get(name);
if (toReturn == null) {
toReturn = super.findClass(name);
loadedClasses.put(name, toReturn);
}
return toReturn;
}
}
return super.loadClass(name);
}
};
oldClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classReloader);
oldSecurityManager = System.getSecurityManager();
/*
* TODO(cpovirk): Why couldn't I get this to work with PermissionCollection and implies(), as
* used by ClassPathTest?
*/
final PropertyPermission readSystemProperty = new PropertyPermission("guava.concurrent.generate_cancellation_cause", "read");
SecurityManager disallowPropertySecurityManager = new SecurityManager() {
@Override
public void checkPermission(Permission p) {
if (readSystemProperty.equals(p)) {
throw new SecurityException("Disallowed: " + p);
}
}
};
System.setSecurityManager(disallowPropertySecurityManager);
settableFutureClass = classReloader.loadClass(SettableFuture.class.getName());
/*
* We must keep the SecurityManager installed during the test body: It affects what kind of
* threads ForkJoinPool.commonPool() creates.
*/
}
use of java.util.PropertyPermission in project groovy by apache.
the class SecurityTest method testForbiddenProperty.
public void testForbiddenProperty() {
String script = "System.getProperty(\"user.home\")";
assertExecute(script, null, new PropertyPermission("user.home", "read"));
}
use of java.util.PropertyPermission in project wildfly by wildfly.
the class RemoteProtocolChangeTestCase method createDeployment.
@Deployment
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "remote-protocol-interceptor-test.jar");
jar.addClasses(SampleBean.class, TestSuiteEnvironment.class);
jar.addPackage(RemoteProtocolChangeTestCase.class.getPackage());
jar.addPackage(AbstractServerInterceptorsSetupTask.class.getPackage());
jar.addAsManifestResource(createPermissionsXmlAsset(new PropertyPermission("management.address", "read"), new PropertyPermission("node0", "read")), "permissions.xml");
return jar;
}
use of java.util.PropertyPermission in project wildfly by wildfly.
the class ScheduledThreadPoolMetricsTestCase method getDeployment.
@Deployment
public static JavaArchive getDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ArtemisScheduledThreadpoolMetricsTestCase.jar");
ejbJar.addPackage(TimeoutUtil.class.getPackage());
ejbJar.addClasses(JMSThreadPoolMetricsSetup.class, JMSThreadPoolMetricsMDB.class, JMSThreadPoolMetricsUtil.class);
ejbJar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr,org.jboss.remoting\n"), "MANIFEST.MF");
ejbJar.addAsManifestResource(createPermissionsXmlAsset(new FilePermission(System.getProperty("jboss.inst") + File.separatorChar + "standalone" + File.separatorChar + "tmp" + File.separatorChar + "auth" + File.separatorChar + "*", "read"), new PropertyPermission("ts.timeout.factor", "read"), RemotingPermission.CREATE_ENDPOINT, RemotingPermission.CONNECT, new SocketPermission("localhost", "resolve")), "jboss-permissions.xml");
return ejbJar;
}
use of java.util.PropertyPermission in project wildfly by wildfly.
the class AbstractRemoteEJBForwardingTestCase method createForwardingDeployment.
public static Archive<?> createForwardingDeployment(String moduleName, boolean tx) {
JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, moduleName + ".jar");
ejbJar.addClass(CommonStatefulSB.class);
ejbJar.addClass(RemoteStatefulSB.class);
// the forwarding classes
ejbJar.addClass(AbstractForwardingStatefulSBImpl.class);
if (tx) {
ejbJar.addClass(ForwardingStatefulSBImpl.class);
} else {
ejbJar.addClass(NonTxForwardingStatefulSBImpl.class);
}
ejbJar.addClasses(EJBDirectory.class, NamingEJBDirectory.class, RemoteEJBDirectory.class);
// remote outbound connection configuration
ejbJar.addAsManifestResource(AbstractRemoteEJBForwardingTestCase.class.getPackage(), "jboss-ejb-client.xml", "jboss-ejb-client.xml");
ejbJar.addAsResource(createPermissionsXmlAsset(new SocketPermission("localhost", "resolve"), new EJBClientPermission("changeWeakAffinity"), new PropertyPermission("jboss.node.name", "read")), "META-INF/jboss-permissions.xml");
return ejbJar;
}
Aggregations