use of java.security.AllPermission in project elasticsearch by elastic.
the class ESPolicyUnitTests method testNullCodeSource.
/**
* Test policy with null codesource.
* <p>
* This can happen when restricting privileges with doPrivileged,
* even though ProtectionDomain's ctor javadocs might make you think
* that the policy won't be consulted.
*/
public void testNullCodeSource() throws Exception {
assumeTrue("test cannot run with security manager", System.getSecurityManager() == null);
// create a policy with AllPermission
Permission all = new AllPermission();
PermissionCollection allCollection = all.newPermissionCollection();
allCollection.add(all);
ESPolicy policy = new ESPolicy(allCollection, Collections.emptyMap(), true);
// restrict ourselves to NoPermission
PermissionCollection noPermissions = new Permissions();
assertFalse(policy.implies(new ProtectionDomain(null, noPermissions), new FilePermission("foo", "read")));
}
use of java.security.AllPermission in project joda-time by JodaOrg.
the class TestDateTimeZone method testZoneInfoProviderResourceLoading.
public void testZoneInfoProviderResourceLoading() {
final Set<String> ids = new HashSet<String>(DateTimeZone.getAvailableIDs());
ids.remove(DateTimeZone.getDefault().getID());
final String id = ids.toArray(new String[ids.size()])[new Random().nextInt(ids.size())];
try {
Policy.setPolicy(new Policy() {
@Override
public PermissionCollection getPermissions(CodeSource codesource) {
Permissions p = new Permissions();
// enable everything
p.add(new AllPermission());
return p;
}
@Override
public void refresh() {
}
@Override
public boolean implies(ProtectionDomain domain, Permission permission) {
return !(permission instanceof FilePermission) && !permission.getName().contains(id);
}
});
System.setSecurityManager(new SecurityManager());
// will throw IllegalArgumentException if the resource can
// not be loaded
final DateTimeZone zone = DateTimeZone.forID(id);
assertNotNull(zone);
} finally {
System.setSecurityManager(null);
Policy.setPolicy(ALLOW);
}
}
use of java.security.AllPermission in project jdk8u_jdk by JetBrains.
the class XPathExFuncTest method testEnableExtFunc.
/**
* Security is enabled, use new feature: enableExtensionFunctions
*/
public void testEnableExtFunc() {
Policy p = new SimplePolicy(new AllPermission());
Policy.setPolicy(p);
System.setSecurityManager(new SecurityManager());
try {
evaluate(true);
System.out.println("testEnableExt: OK");
} catch (XPathFactoryConfigurationException e) {
fail(e.getMessage());
} catch (XPathExpressionException e) {
fail(e.getMessage());
} finally {
System.setSecurityManager(null);
}
}
use of java.security.AllPermission in project jdk8u_jdk by JetBrains.
the class XSLTExFuncTest method testTemplatesEnableExtFunc.
/**
* use Templates template = factory.newTemplates(new StreamSource( new
* FileInputStream(xslFilename))); // Use the template to create a
* transformer Transformer xformer = template.newTransformer();
*
* @param factory
* @return
*/
/**
* Security is enabled, use new feature: enableExtensionFunctions Use the
* template to create a transformer
*/
public void testTemplatesEnableExtFunc() {
Policy p = new SimplePolicy(new AllPermission());
Policy.setPolicy(p);
System.setSecurityManager(new SecurityManager());
TransformerFactory factory = TransformerFactory.newInstance();
/**
* Use of the extension function 'http://exslt.org/strings:tokenize' is
* not allowed when the secure processing feature is set to true.
* Attempt to use the new property to enable extension function
*/
boolean isExtensionSupported = enableExtensionFunction(factory);
try {
SAXSource xslSource = new SAXSource(new InputSource(xslFile));
xslSource.setSystemId(xslFileId);
Templates template = factory.newTemplates(xslSource);
Transformer transformer = template.newTransformer();
StringWriter stringResult = new StringWriter();
Result result = new StreamResult(stringResult);
transformer.transform(new SAXSource(new InputSource(xmlFile)), result);
System.out.println("testTemplatesEnableExtFunc: OK");
} catch (TransformerConfigurationException e) {
fail(e.getMessage());
} catch (TransformerException e) {
fail(e.getMessage());
} finally {
System.setSecurityManager(null);
}
}
use of java.security.AllPermission in project jdk8u_jdk by JetBrains.
the class JarURL method main.
public static void main(String[] args) throws Exception {
String userDir = System.getProperty("user.dir");
String jarURL = "jar:file:" + userDir + File.separator + "foo.jar!/";
URL codeSourceURL = new URL(jarURL);
CodeSource cs = new CodeSource(codeSourceURL, new Certificate[0]);
PermissionCollection perms = Policy.getPolicy().getPermissions(cs);
if (!perms.implies(new AllPermission()))
throw new Exception("FAILED: " + codeSourceURL + " not granted AllPermission");
}
Aggregations