Search in sources :

Example 11 with PropertyPermission

use of java.util.PropertyPermission in project Bytecoder by mirkosertic.

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<>() {

            @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 12 with PropertyPermission

use of java.util.PropertyPermission in project Bytecoder by mirkosertic.

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.
 *
 * @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 13 with PropertyPermission

use of java.util.PropertyPermission in project Bytecoder by mirkosertic.

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.
 *
 * @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)

Example 14 with PropertyPermission

use of java.util.PropertyPermission in project openj9 by eclipse.

the class TestToArrayOfProtectionDomains method main.

public static void main(String[] args) {
    try {
        AccessController.checkPermission(new PropertyPermission("java.home", "read"));
        System.out.println("FAILED: access not denied!");
    } catch (AccessControlException ace) {
        System.out.println("ALL TESTS COMPLETED AND PASSED");
    }
}
Also used : PropertyPermission(java.util.PropertyPermission) AccessControlException(java.security.AccessControlException)

Example 15 with PropertyPermission

use of java.util.PropertyPermission in project openj9 by eclipse.

the class Test_AccessController method test_doPrivileged_createAccessControlContext.

/**
 *  java.security.AccessController#doPrivileged(java.security.PrivilegedAction, AccessControlContext)
 */
@Test
public void test_doPrivileged_createAccessControlContext() {
    /*
		 * Classes loaded by this Classloader withPermCL have the Permission JAVA_HOME_READ & CREATE_ACC
		 */
    ClassLoader withPermCL = new TestURLClassLoader(new URL[] { this.getClass().getProtectionDomain().getCodeSource().getLocation() }, null) {

        public PermissionCollection getPermissions(CodeSource cs) {
            PermissionCollection pc = super.getPermissions(cs);
            pc.add(new PropertyPermission("java.home", "read"));
            pc.add(new SecurityPermission("createAccessControlContext"));
            return pc;
        }
    };
    try {
        Class<?> mwp = Class.forName("org.openj9.test.java.security.Test_AccessController$MainWithPerm", true, withPermCL);
        Object mwpObj = mwp.newInstance();
        Method m = mwp.getDeclaredMethod("testCreateACC");
        m.setAccessible(true);
        m.invoke(mwpObj);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("FAIL: TEST FAILED, probably setup issue.");
    }
}
Also used : PermissionCollection(java.security.PermissionCollection) PropertyPermission(java.util.PropertyPermission) BeforeMethod(org.testng.annotations.BeforeMethod) AfterMethod(org.testng.annotations.AfterMethod) Method(java.lang.reflect.Method) CodeSource(java.security.CodeSource) SecurityPermission(java.security.SecurityPermission) PrivilegedActionException(java.security.PrivilegedActionException) AccessControlException(java.security.AccessControlException) Test(org.testng.annotations.Test)

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