Search in sources :

Example 1 with JexlPermissions

use of org.apache.commons.jexl3.introspection.JexlPermissions in project commons-jexl by apache.

the class PermissionsTest method testPermissions.

@Test
public void testPermissions() throws Exception {
    String src = " org.apache.commons.jexl3.internal.introspection { PermissionsTest { " + "InterNoJexl0 { } " + "InterNoJexl1 { method(); } " + "A0 { A0(); i0; } " + "A1 { A1(); } " + "A2 { } " + "InterNoJexl5 { } " + "} }";
    JexlPermissions p = (Permissions) JexlPermissions.parse(src);
    Assert.assertFalse(p.allow((Field) null));
    Assert.assertFalse(p.allow((Package) null));
    Assert.assertFalse(p.allow((Method) null));
    Assert.assertFalse(p.allow((Constructor<?>) null));
    Assert.assertFalse(p.allow((Class<?>) null));
    Assert.assertFalse(p.allow(A2.class));
    Assert.assertTrue(p.allow(A3.class));
    Assert.assertTrue(p.allow(A5.class));
    Method mA = A.class.getMethod("method");
    Assert.assertNotNull(mA);
    Method mA0 = A0.class.getMethod("method");
    Assert.assertNotNull(mA0);
    Method mA1 = A1.class.getMethod("method");
    Assert.assertNotNull(mA1);
    Method mA2 = A2.class.getMethod("method");
    Assert.assertNotNull(mA2);
    Method mA3 = A2.class.getDeclaredMethod("method");
    Assert.assertNotNull(mA3);
    Assert.assertTrue(p.allow(mA));
    Assert.assertFalse(p.allow(mA0));
    Assert.assertFalse(p.allow(mA1));
    Assert.assertFalse(p.allow(mA2));
    Assert.assertFalse(p.allow(mA3));
    Field fA = A.class.getField("i");
    Assert.assertNotNull(fA);
    Assert.assertTrue(p.allow(fA));
    Field fA0 = A0.class.getField("i0");
    Assert.assertNotNull(fA0);
    Assert.assertFalse(p.allow(fA0));
    Field fA1 = A1.class.getDeclaredField("i1");
    Assert.assertNotNull(fA1);
    Assert.assertFalse(p.allow(fA0));
    Constructor<?> cA = A.class.getConstructor();
    Assert.assertNotNull(cA);
    Assert.assertTrue(p.allow(cA));
    Constructor<?> cA0 = A0.class.getConstructor();
    Assert.assertNotNull(cA0);
    Assert.assertFalse(p.allow(cA0));
    Constructor<?> cA3 = A3.class.getDeclaredConstructor();
    Assert.assertNotNull(cA3);
    Assert.assertFalse(p.allow(cA3));
}
Also used : Field(java.lang.reflect.Field) JexlPermissions(org.apache.commons.jexl3.introspection.JexlPermissions) Constructor(java.lang.reflect.Constructor) JexlPermissions(org.apache.commons.jexl3.introspection.JexlPermissions) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 JexlPermissions (org.apache.commons.jexl3.introspection.JexlPermissions)1 Test (org.junit.Test)1