Search in sources :

Example 11 with PropertyAccessException

use of org.mule.mvel2.PropertyAccessException in project drools by kiegroup.

the class SecurityPolicyTest method testUntrustedMVELEnabled.

@Test
public void testUntrustedMVELEnabled() throws Exception {
    String drl = "package org.foo.bar\n" + "import " + MaliciousExitHelper.class.getName().replace('$', '.') + " \n" + "rule R1 dialect \"mvel\" enabled( MaliciousExitHelper.isEnabled() ) \n" + "when\n" + "then\n" + "end\n";
    try {
        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newByteArrayResource(drl.getBytes()).setSourcePath("org/foo/bar/r1.drl"));
        ks.newKieBuilder(kfs).buildAll();
        ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
        KieContainer kc = ks.newKieContainer(releaseId);
        KieSession ksession = kc.newKieSession();
        ksession.fireAllRules();
        Assert.fail("The security policy for the rule should have prevented this from executing...");
    } catch (PropertyAccessException e) {
        // weak way of testing but couldn't find a better way
        if (e.toString().contains("The security policy should have prevented")) {
            Assert.fail("The security policy for the rule should have prevented this from executing...");
        } else {
        // test succeeded
        }
    }
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) PropertyAccessException(org.mvel2.PropertyAccessException) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 12 with PropertyAccessException

use of org.mule.mvel2.PropertyAccessException in project drools by kiegroup.

the class SecurityPolicyTest method testUntrustedMVELSalience.

@Test
public void testUntrustedMVELSalience() throws Exception {
    String drl = "package org.foo.bar\n" + "import " + MaliciousExitHelper.class.getName().replace('$', '.') + " \n" + "rule R1 dialect \"mvel\" salience( MaliciousExitHelper.exit() ) \n" + "when\n" + "then\n" + "end\n";
    try {
        KieServices ks = KieServices.Factory.get();
        KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newByteArrayResource(drl.getBytes()).setSourcePath("org/foo/bar/r1.drl"));
        ks.newKieBuilder(kfs).buildAll();
        ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
        KieContainer kc = ks.newKieContainer(releaseId);
        KieSession ksession = kc.newKieSession();
        ksession.fireAllRules();
        Assert.fail("The security policy for the rule should have prevented this from executing...");
    } catch (PropertyAccessException e) {
        // weak way of testing but couldn't find a better way
        if (e.toString().contains("The security policy should have prevented")) {
            Assert.fail("The security policy for the rule should have prevented this from executing...");
        } else {
        // test succeeded
        }
    }
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) PropertyAccessException(org.mvel2.PropertyAccessException) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

PropertyAccessException (org.mvel2.PropertyAccessException)12 CompileException (org.mvel2.CompileException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Method (java.lang.reflect.Method)5 Test (org.junit.Test)5 KieServices (org.kie.api.KieServices)5 KieFileSystem (org.kie.api.builder.KieFileSystem)5 ReleaseId (org.kie.api.builder.ReleaseId)5 KieContainer (org.kie.api.runtime.KieContainer)5 KieSession (org.kie.api.runtime.KieSession)5 Field (java.lang.reflect.Field)4 Member (java.lang.reflect.Member)4 Map (java.util.Map)4 IOException (java.io.IOException)3 ConsequenceException (org.kie.api.runtime.rule.ConsequenceException)3 Array (java.lang.reflect.Array)2 List (java.util.List)2 OptimizationFailure (org.mvel2.OptimizationFailure)2 Label (org.mvel2.asm.Label)2 ExecutableStatement (org.mvel2.compiler.ExecutableStatement)2