Search in sources :

Example 6 with PropertyPermission

use of java.util.PropertyPermission in project jdk8u_jdk by JetBrains.

the class InnerClassLambdaMetafactory method spinInnerClass.

/**
     * Generate a class file which implements the functional
     * interface, define and return the class.
     *
     * @implNote The class that is generated does not include signature
     * information for exceptions that may be present on the SAM method.
     * This is to reduce classfile size, and is harmless as checked exceptions
     * are erased anyway, no one will ever compile against this classfile,
     * and we make no guarantees about the reflective properties of lambda
     * objects.
     *
     * @return a Class which implements the functional interface
     * @throws LambdaConversionException If properly formed functional interface
     * is not found
     */
private Class<?> spinInnerClass() throws LambdaConversionException {
    String[] interfaces;
    String samIntf = samBase.getName().replace('.', '/');
    boolean accidentallySerializable = !isSerializable && Serializable.class.isAssignableFrom(samBase);
    if (markerInterfaces.length == 0) {
        interfaces = new String[] { samIntf };
    } else {
        // Assure no duplicate interfaces (ClassFormatError)
        Set<String> itfs = new LinkedHashSet<>(markerInterfaces.length + 1);
        itfs.add(samIntf);
        for (Class<?> markerInterface : markerInterfaces) {
            itfs.add(markerInterface.getName().replace('.', '/'));
            accidentallySerializable |= !isSerializable && Serializable.class.isAssignableFrom(markerInterface);
        }
        interfaces = itfs.toArray(new String[itfs.size()]);
    }
    cw.visit(CLASSFILE_VERSION, ACC_SUPER + ACC_FINAL + ACC_SYNTHETIC, lambdaClassName, null, JAVA_LANG_OBJECT, interfaces);
    // Generate final fields to be filled in by constructor
    for (int i = 0; i < argDescs.length; i++) {
        FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_FINAL, argNames[i], argDescs[i], null, null);
        fv.visitEnd();
    }
    generateConstructor();
    if (invokedType.parameterCount() != 0) {
        generateFactory();
    }
    // Forward the SAM method
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, samMethodName, samMethodType.toMethodDescriptorString(), null, null);
    mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Hidden;", true);
    new ForwardingMethodGenerator(mv).generate(samMethodType);
    // Forward the bridges
    if (additionalBridges != null) {
        for (MethodType mt : additionalBridges) {
            mv = cw.visitMethod(ACC_PUBLIC | ACC_BRIDGE, samMethodName, mt.toMethodDescriptorString(), null, null);
            mv.visitAnnotation("Ljava/lang/invoke/LambdaForm$Hidden;", true);
            new ForwardingMethodGenerator(mv).generate(mt);
        }
    }
    if (isSerializable)
        generateSerializationFriendlyMethods();
    else if (accidentallySerializable)
        generateSerializationHostileMethods();
    cw.visitEnd();
    // Define the generated class in this VM.
    final byte[] classBytes = cw.toByteArray();
    // If requested, dump out to a file for debugging purposes
    if (dumper != null) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {

            @Override
            public Void run() {
                dumper.dumpClass(lambdaClassName, classBytes);
                return null;
            }
        }, null, new FilePermission("<<ALL FILES>>", "read, write"), // createDirectories may need it
        new PropertyPermission("user.dir", "read"));
    }
    return UNSAFE.defineAnonymousClass(targetClass, classBytes, null);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Serializable(java.io.Serializable) PropertyPermission(java.util.PropertyPermission) FilePermission(java.io.FilePermission)

Example 7 with PropertyPermission

use of java.util.PropertyPermission in project jdk8u_jdk by JetBrains.

the class System method setProperty.

/**
     * Sets the system property indicated by the specified key.
     * <p>
     * First, if a security manager exists, its
     * <code>SecurityManager.checkPermission</code> method
     * is called with a <code>PropertyPermission(key, "write")</code>
     * permission. This may result in a SecurityException being thrown.
     * If no exception is thrown, the specified property is set to the given
     * value.
     * <p>
     *
     * @param      key   the name of the system property.
     * @param      value the value of the system property.
     * @return     the previous value of the system property,
     *             or <code>null</code> if it did not have one.
     *
     * @exception  SecurityException  if a security manager exists and its
     *             <code>checkPermission</code> method doesn't allow
     *             setting of the specified property.
     * @exception  NullPointerException if <code>key</code> or
     *             <code>value</code> is <code>null</code>.
     * @exception  IllegalArgumentException if <code>key</code> is empty.
     * @see        #getProperty
     * @see        java.lang.System#getProperty(java.lang.String)
     * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
     * @see        java.util.PropertyPermission
     * @see        SecurityManager#checkPermission
     * @since      1.2
     */
public static String setProperty(String key, String value) {
    checkKey(key);
    SecurityManager sm = getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new PropertyPermission(key, SecurityConstants.PROPERTY_WRITE_ACTION));
    }
    return (String) props.setProperty(key, value);
}
Also used : PropertyPermission(java.util.PropertyPermission)

Example 8 with PropertyPermission

use of java.util.PropertyPermission in project rt.equinox.framework by eclipse.

the class PackagePermissionTests method testPackagePermission.

public void testPackagePermission() {
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "x");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "   get  ,  x   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "      ");
    // $NON-NLS-1$
    badPackagePermission("a.b.c", null);
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", ",");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", ",xxx");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "xxx,");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "import,");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "export,   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "importme,");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "exportme,");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", ",import");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", ",export");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "   importme   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "   exportme     ");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "   impor");
    // $NON-NLS-1$ //$NON-NLS-2$
    badPackagePermission("a.b.c", "   expor");
    // $NON-NLS-1$ //$NON-NLS-2$
    Permission op = new PropertyPermission("java.home", "read");
    // $NON-NLS-1$ //$NON-NLS-2$
    PackagePermission p11 = new PackagePermission("com.foo.service1", "    IMPORT,export   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    PackagePermission p12 = new PackagePermission("com.foo.service1", "EXPORT  ,   import");
    // $NON-NLS-1$ //$NON-NLS-2$
    PackagePermission p13 = new PackagePermission("com.foo.service1", "expORT   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    PackagePermission p14 = new PackagePermission("com.foo.service1", "    Import    ");
    shouldImply(p11, p11);
    shouldImply(p11, p12);
    shouldImply(p11, p13);
    shouldImply(p11, p14);
    shouldImply(p12, p11);
    shouldImply(p12, p12);
    shouldImply(p12, p13);
    shouldImply(p12, p14);
    shouldImply(p13, p11);
    shouldImply(p13, p12);
    shouldImply(p13, p13);
    shouldImply(p13, p14);
    shouldImply(p14, p14);
    shouldNotImply(p14, p11);
    shouldNotImply(p14, p12);
    shouldNotImply(p14, p13);
    shouldNotImply(p11, op);
    shouldEqual(p11, p11);
    shouldEqual(p11, p12);
    shouldEqual(p11, p13);
    shouldEqual(p12, p11);
    shouldEqual(p12, p12);
    shouldEqual(p12, p13);
    shouldEqual(p13, p11);
    shouldEqual(p13, p12);
    shouldEqual(p13, p13);
    shouldNotEqual(p11, p14);
    shouldNotEqual(p12, p14);
    shouldNotEqual(p13, p14);
    shouldNotEqual(p14, p11);
    shouldNotEqual(p14, p12);
    shouldNotEqual(p14, p13);
    PermissionCollection pc = p13.newPermissionCollection();
    checkEnumeration(pc.elements(), true);
    shouldNotImply(pc, p11);
    shouldAdd(pc, p14);
    shouldImply(pc, p14);
    shouldNotImply(pc, p11);
    shouldNotImply(pc, p12);
    shouldNotImply(pc, p13);
    shouldAdd(pc, p13);
    shouldImply(pc, p11);
    shouldImply(pc, p12);
    shouldImply(pc, p13);
    shouldImply(pc, p14);
    shouldNotAdd(pc, op);
    pc = p13.newPermissionCollection();
    shouldAdd(pc, p13);
    shouldImply(pc, p11);
    shouldImply(pc, p12);
    shouldImply(pc, p13);
    shouldImply(pc, p14);
    pc = p11.newPermissionCollection();
    shouldAdd(pc, p11);
    shouldImply(pc, p11);
    shouldImply(pc, p12);
    shouldImply(pc, p13);
    shouldImply(pc, p14);
    pc.setReadOnly();
    shouldNotAdd(pc, p12);
    checkEnumeration(pc.elements(), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    PackagePermission p21 = new PackagePermission("com.foo.service2", "import");
    // $NON-NLS-1$ //$NON-NLS-2$
    PackagePermission p22 = new PackagePermission("com.foo.*", "import");
    // $NON-NLS-1$ //$NON-NLS-2$
    PackagePermission p23 = new PackagePermission("com.*", "import");
    // $NON-NLS-1$ //$NON-NLS-2$
    PackagePermission p24 = new PackagePermission("*", "import");
    shouldImply(p21, p21);
    shouldImply(p22, p21);
    shouldImply(p23, p21);
    shouldImply(p24, p21);
    shouldImply(p22, p22);
    shouldImply(p23, p22);
    shouldImply(p24, p22);
    shouldImply(p23, p23);
    shouldImply(p24, p23);
    shouldImply(p24, p24);
    shouldNotImply(p21, p22);
    shouldNotImply(p21, p23);
    shouldNotImply(p21, p24);
    shouldNotImply(p22, p23);
    shouldNotImply(p22, p24);
    shouldNotImply(p23, p24);
    pc = p21.newPermissionCollection();
    shouldAdd(pc, p21);
    shouldImply(pc, p21);
    shouldNotImply(pc, p22);
    shouldNotImply(pc, p23);
    shouldNotImply(pc, p24);
    shouldAdd(pc, p22);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldNotImply(pc, p23);
    shouldNotImply(pc, p24);
    shouldAdd(pc, p23);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldImply(pc, p23);
    shouldNotImply(pc, p24);
    shouldAdd(pc, p24);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldImply(pc, p23);
    shouldImply(pc, p24);
    pc = p22.newPermissionCollection();
    shouldAdd(pc, p22);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldNotImply(pc, p23);
    shouldNotImply(pc, p24);
    pc = p23.newPermissionCollection();
    shouldAdd(pc, p23);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldImply(pc, p23);
    shouldNotImply(pc, p24);
    pc = p24.newPermissionCollection();
    shouldAdd(pc, p24);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldImply(pc, p23);
    shouldImply(pc, p24);
    testSerialization(p11);
    testSerialization(p12);
    testSerialization(p13);
    testSerialization(p14);
    testSerialization(p21);
    testSerialization(p22);
    testSerialization(p23);
    testSerialization(p24);
}
Also used : PermissionCollection(java.security.PermissionCollection) PropertyPermission(java.util.PropertyPermission) PackagePermission(org.osgi.framework.PackagePermission) Permission(java.security.Permission) PropertyPermission(java.util.PropertyPermission) PackagePermission(org.osgi.framework.PackagePermission)

Example 9 with PropertyPermission

use of java.util.PropertyPermission in project rt.equinox.framework by eclipse.

the class ServicePermissionTests method testServicePermission.

public void testServicePermission() {
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "x");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "   get  ,  x   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "      ");
    // $NON-NLS-1$
    badServicePermission("a.b.c", null);
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", ",");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", ",xxx");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "xxx,");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "get,");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "register,   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "getme,");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "registerme,");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", ",get");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", ",register");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "   getme   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "   registerme     ");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "   ge");
    // $NON-NLS-1$ //$NON-NLS-2$
    badServicePermission("a.b.c", "   registe");
    // $NON-NLS-1$ //$NON-NLS-2$
    Permission op = new PropertyPermission("java.home", "read");
    // $NON-NLS-1$ //$NON-NLS-2$
    ServicePermission p11 = new ServicePermission("com.foo.service1", "    GET,register   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    ServicePermission p12 = new ServicePermission("com.foo.service1", "REGISTER  ,   get");
    // $NON-NLS-1$ //$NON-NLS-2$
    ServicePermission p13 = new ServicePermission("com.foo.service1", "regisTER   ");
    // $NON-NLS-1$ //$NON-NLS-2$
    ServicePermission p14 = new ServicePermission("com.foo.service1", "    Get    ");
    shouldImply(p11, p11);
    shouldImply(p11, p12);
    shouldImply(p11, p13);
    shouldImply(p11, p14);
    shouldImply(p12, p11);
    shouldImply(p12, p12);
    shouldImply(p12, p13);
    shouldImply(p12, p14);
    shouldImply(p13, p13);
    shouldImply(p14, p14);
    shouldNotImply(p13, p11);
    shouldNotImply(p13, p12);
    shouldNotImply(p14, p11);
    shouldNotImply(p14, p12);
    shouldNotImply(p13, p14);
    shouldNotImply(p14, p13);
    shouldNotImply(p11, op);
    shouldEqual(p11, p11);
    shouldEqual(p11, p12);
    shouldEqual(p12, p11);
    shouldEqual(p12, p12);
    shouldEqual(p13, p13);
    shouldEqual(p14, p14);
    shouldNotEqual(p11, p13);
    shouldNotEqual(p11, p14);
    shouldNotEqual(p12, p13);
    shouldNotEqual(p12, p14);
    shouldNotEqual(p13, p11);
    shouldNotEqual(p13, p12);
    shouldNotEqual(p13, p14);
    shouldNotEqual(p14, p11);
    shouldNotEqual(p14, p12);
    shouldNotEqual(p14, p13);
    PermissionCollection pc = p13.newPermissionCollection();
    checkEnumeration(pc.elements(), true);
    shouldNotImply(pc, p11);
    shouldAdd(pc, p14);
    shouldImply(pc, p14);
    shouldNotImply(pc, p11);
    shouldNotImply(pc, p12);
    shouldNotImply(pc, p13);
    shouldAdd(pc, p13);
    shouldImply(pc, p11);
    shouldImply(pc, p12);
    shouldImply(pc, p13);
    shouldImply(pc, p14);
    shouldNotAdd(pc, op);
    pc = p13.newPermissionCollection();
    shouldAdd(pc, p13);
    shouldImply(pc, p13);
    shouldNotImply(pc, p11);
    shouldNotImply(pc, p12);
    shouldNotImply(pc, p14);
    shouldAdd(pc, p14);
    shouldImply(pc, p11);
    shouldImply(pc, p12);
    shouldImply(pc, p13);
    shouldImply(pc, p14);
    pc = p11.newPermissionCollection();
    shouldAdd(pc, p11);
    shouldImply(pc, p11);
    shouldImply(pc, p12);
    shouldImply(pc, p13);
    shouldImply(pc, p14);
    pc.setReadOnly();
    shouldNotAdd(pc, p12);
    checkEnumeration(pc.elements(), false);
    // $NON-NLS-1$ //$NON-NLS-2$
    ServicePermission p21 = new ServicePermission("com.foo.service2", "get");
    // $NON-NLS-1$ //$NON-NLS-2$
    ServicePermission p22 = new ServicePermission("com.foo.*", "get");
    // $NON-NLS-1$ //$NON-NLS-2$
    ServicePermission p23 = new ServicePermission("com.*", "get");
    // $NON-NLS-1$ //$NON-NLS-2$
    ServicePermission p24 = new ServicePermission("*", "get");
    shouldImply(p21, p21);
    shouldImply(p22, p21);
    shouldImply(p23, p21);
    shouldImply(p24, p21);
    shouldImply(p22, p22);
    shouldImply(p23, p22);
    shouldImply(p24, p22);
    shouldImply(p23, p23);
    shouldImply(p24, p23);
    shouldImply(p24, p24);
    shouldNotImply(p21, p22);
    shouldNotImply(p21, p23);
    shouldNotImply(p21, p24);
    shouldNotImply(p22, p23);
    shouldNotImply(p22, p24);
    shouldNotImply(p23, p24);
    pc = p21.newPermissionCollection();
    shouldAdd(pc, p21);
    shouldImply(pc, p21);
    shouldNotImply(pc, p22);
    shouldNotImply(pc, p23);
    shouldNotImply(pc, p24);
    shouldAdd(pc, p22);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldNotImply(pc, p23);
    shouldNotImply(pc, p24);
    shouldAdd(pc, p23);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldImply(pc, p23);
    shouldNotImply(pc, p24);
    shouldAdd(pc, p24);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldImply(pc, p23);
    shouldImply(pc, p24);
    pc = p22.newPermissionCollection();
    shouldAdd(pc, p22);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldNotImply(pc, p23);
    shouldNotImply(pc, p24);
    pc = p23.newPermissionCollection();
    shouldAdd(pc, p23);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldImply(pc, p23);
    shouldNotImply(pc, p24);
    pc = p24.newPermissionCollection();
    shouldAdd(pc, p24);
    shouldImply(pc, p21);
    shouldImply(pc, p22);
    shouldImply(pc, p23);
    shouldImply(pc, p24);
    testSerialization(p11);
    testSerialization(p12);
    testSerialization(p13);
    testSerialization(p14);
    testSerialization(p21);
    testSerialization(p22);
    testSerialization(p23);
    testSerialization(p24);
}
Also used : PermissionCollection(java.security.PermissionCollection) PropertyPermission(java.util.PropertyPermission) ServicePermission(org.osgi.framework.ServicePermission) Permission(java.security.Permission) ServicePermission(org.osgi.framework.ServicePermission) PropertyPermission(java.util.PropertyPermission)

Example 10 with PropertyPermission

use of java.util.PropertyPermission in project checker-framework by typetools.

the class System method clearProperty.

/**
 * Removes the system property indicated by the specified key.
 * <p>
 * First, if a security manager exists, its
 * <code>SecurityManager.checkPermission</code> method
 * is called with a <code>PropertyPermission(key, "write")</code>
 * permission. This may result in a SecurityException being thrown.
 * If no exception is thrown, the specified property is removed.
 * <p>
 *
 * @param      key   the name of the system property to be removed.
 * @return     the previous string value of the system property,
 *             or <code>null</code> if there was no property with that key.
 *
 * @exception  SecurityException  if a security manager exists and its
 *             <code>checkPropertyAccess</code> method doesn't allow
 *              access to the specified system property.
 * @exception  NullPointerException if <code>key</code> is
 *             <code>null</code>.
 * @exception  IllegalArgumentException if <code>key</code> is empty.
 * @see        #getProperty
 * @see        #setProperty
 * @see        java.util.Properties
 * @see        java.lang.SecurityException
 * @see        java.lang.SecurityManager#checkPropertiesAccess()
 * @since 1.5
 */
public static String clearProperty(String key) {
    checkKey(key);
    SecurityManager sm = getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new PropertyPermission(key, "write"));
    }
    return (String) props.remove(key);
}
Also used : PropertyPermission(java.util.PropertyPermission)

Aggregations

PropertyPermission (java.util.PropertyPermission)98 Deployment (org.jboss.arquillian.container.test.api.Deployment)49 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)46 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)35 FilePermission (java.io.FilePermission)23 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)18 SocketPermission (java.net.SocketPermission)13 JMSOperations (org.jboss.as.test.integration.common.jms.JMSOperations)13 Permission (java.security.Permission)10 AccessControlException (java.security.AccessControlException)8 RemotingPermission (org.jboss.remoting3.security.RemotingPermission)8 PermissionCollection (java.security.PermissionCollection)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)7 ReflectPermission (java.lang.reflect.ReflectPermission)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)6 Permissions (java.security.Permissions)5 SecurityPermission (java.security.SecurityPermission)5 AccessControlContext (java.security.AccessControlContext)4 TimeoutUtil (org.jboss.as.test.shared.TimeoutUtil)4 Method (java.lang.reflect.Method)3