Search in sources :

Example 1 with AllPermission

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")));
}
Also used : PermissionCollection(java.security.PermissionCollection) ProtectionDomain(java.security.ProtectionDomain) Permission(java.security.Permission) FilePermission(java.io.FilePermission) SocketPermission(java.net.SocketPermission) AllPermission(java.security.AllPermission) Permissions(java.security.Permissions) AllPermission(java.security.AllPermission) FilePermission(java.io.FilePermission)

Example 2 with AllPermission

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);
    }
}
Also used : Policy(java.security.Policy) PermissionCollection(java.security.PermissionCollection) ProtectionDomain(java.security.ProtectionDomain) CodeSource(java.security.CodeSource) FilePermission(java.io.FilePermission) Random(java.util.Random) Permissions(java.security.Permissions) AllPermission(java.security.AllPermission) FilePermission(java.io.FilePermission) Permission(java.security.Permission) AllPermission(java.security.AllPermission) HashSet(java.util.HashSet)

Example 3 with AllPermission

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);
    }
}
Also used : Policy(java.security.Policy) XPathExpressionException(javax.xml.xpath.XPathExpressionException) AllPermission(java.security.AllPermission) XPathFactoryConfigurationException(javax.xml.xpath.XPathFactoryConfigurationException)

Example 4 with AllPermission

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);
    }
}
Also used : Policy(java.security.Policy) InputSource(org.xml.sax.InputSource) StreamResult(javax.xml.transform.stream.StreamResult) StreamResult(javax.xml.transform.stream.StreamResult) SAXSource(javax.xml.transform.sax.SAXSource) StringWriter(java.io.StringWriter) AllPermission(java.security.AllPermission)

Example 5 with AllPermission

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");
}
Also used : PermissionCollection(java.security.PermissionCollection) AllPermission(java.security.AllPermission) CodeSource(java.security.CodeSource) URL(java.net.URL)

Aggregations

AllPermission (java.security.AllPermission)37 PermissionCollection (java.security.PermissionCollection)14 Permissions (java.security.Permissions)13 Permission (java.security.Permission)9 Policy (java.security.Policy)8 File (java.io.File)5 FilePermission (java.io.FilePermission)5 CodeSource (java.security.CodeSource)5 Test (org.junit.Test)5 ProtectionDomain (java.security.ProtectionDomain)4 Deployment (org.jboss.arquillian.container.test.api.Deployment)3 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 InetSocketAddress (java.net.InetSocketAddress)2 SocketPermission (java.net.SocketPermission)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 PrivilegedActionException (java.security.PrivilegedActionException)2 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2