org.mvel2.PropertyAccessException Java Examples

The following examples show how to use org.mvel2.PropertyAccessException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MvelScriptInvokable.java    From bulbasaur with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke0(Map<String, Object> context) {
	context.putAll(beans);
	context.putAll(pojos);
	if (StringUtils.isNotBlank(expr) && !MvelUtils.evalToBoolean(expr, context)) {
		return null;
	}
	try {
		return MvelUtils.eval(script, context);
	} catch (PropertyAccessException e) {
		logger.error("mvel script execute error:" + e.getMessage(), e);
		Throwable sourceE = MvelUtils.unboxingException(e);
		if (sourceE instanceof RuntimeException) {
			throw (BizException) sourceE;
		} else {
			throw new UndeclaredThrowableException(sourceE);
		}
	}
}
 
Example #2
Source File: TestEasyRulesEngineService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testIgnoreConditionErrorsTrueNIFI() throws InitializationException, IOException {
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
    final RulesEngineService service = new MockEasyRulesEngineService();
    runner.addControllerService("easy-rules-engine-service-test",service);
    runner.setProperty(service, EasyRulesEngineService.RULES_FILE_PATH, "src/test/resources/test_nifi_rules.json");
    runner.setProperty(service,EasyRulesEngineService.RULES_FILE_TYPE, "JSON");
    runner.setProperty(service,EasyRulesEngineService.RULES_FILE_FORMAT, "NIFI");
    runner.setProperty(service,EasyRulesEngineService.IGNORE_CONDITION_ERRORS,"true");
    runner.enableControllerService(service);
    runner.assertValid(service);
    Map<String, Object> facts = new HashMap<>();
    facts.put("fakeMetric",60);
    facts.put("predictedTimeToBytesBackpressureMillis",299999);
    try {
        List<Action> actions = service.fireRules(facts);
        assertNotNull(actions);
        assertEquals(actions.size(), 1);
    }catch (PropertyAccessException pae){
        fail();
    }
}
 
Example #3
Source File: TestEasyRulesEngineService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testIgnoreConditionErrorsTrueMVEL() throws InitializationException, IOException {
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
    final RulesEngineService service = new MockEasyRulesEngineService();
    runner.addControllerService("easy-rules-engine-service-test",service);
    runner.setProperty(service, EasyRulesEngineService.RULES_FILE_PATH, "src/test/resources/test_mvel_rules.json");
    runner.setProperty(service,EasyRulesEngineService.RULES_FILE_TYPE, "JSON");
    runner.setProperty(service,EasyRulesEngineService.RULES_FILE_FORMAT, "MVEL");
    runner.setProperty(service,EasyRulesEngineService.IGNORE_CONDITION_ERRORS,"true");
    runner.enableControllerService(service);
    runner.assertValid(service);
    Map<String, Object> facts = new HashMap<>();
    facts.put("fakeMetric",60);
    facts.put("predictedTimeToBytesBackpressureMillis",299999);
    try {
        List<Action> actions = service.fireRules(facts);
        assertNotNull(actions);
        assertEquals(actions.size(), 1);
    }catch (PropertyAccessException pae){
        fail();
    }
}
 
Example #4
Source File: SecurityPolicyTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@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();
        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" ) ) {
            fail("The security policy for the rule should have prevented this from executing...");
        } else {
            // test succeeded
        }
    }
}
 
Example #5
Source File: SecurityPolicyTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@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();
        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" ) ) {
            fail("The security policy for the rule should have prevented this from executing...");
        } else {
            // test succeeded
        }
    }
}
 
Example #6
Source File: MVELSafeHelperTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testReflectionAttack() throws Exception {
    String setup = "java.lang.reflect.Field field = org.drools.core.util.MVELSafeHelper.getDeclaredField(\"evaluator\");\n"
            + "System.out.println(field);\n"  
            + "field.setAccessible(true);\n"  
            + "field.set(null, \"new org.drools.core.util.MVELSafeHelper.RawMVELEvaluator()\");";
    try {
        assertEquals( SafeMVELEvaluator.class.getName(), MVELSafeHelper.getEvaluator().getClass().getName() );
        MVELSafeHelper.getEvaluator().eval(setup, new HashMap<String,Object>());
        fail("Should have raised an AccessControlException");
    } catch (PropertyAccessException e) {
        // test succeeded. the policy in place prevented the rule from executing field.setAccessible().
        //e.printStackTrace();
    }
}
 
Example #7
Source File: StaticUtil.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private static MvelException processPropertyAccessException(long line, String column, PropertyAccessException e) {
    char c = e.getExpr()[e.getCursor()];

    switch(c) {
    case '\u201c':
    case '\u201d':
        return new MvelException(line, column, "Expression contains invalid double quotation mark: " + c, e);
    default:
        return new MvelException(line, column, e);
    }
}
 
Example #8
Source File: MvelUtils.java    From bulbasaur with Apache License 2.0 5 votes vote down vote up
public static Throwable unboxingException(Throwable ex) {
    if (ex instanceof PropertyAccessException) {
        Throwable innerEx = getCauseOver(ex);
        if (innerEx instanceof InvocationTargetException) {
            return ((InvocationTargetException)innerEx).getTargetException();
        } else {
            return innerEx;
        }
    } else {
        return ex;
    }

}
 
Example #9
Source File: MvelUtils.java    From bulbasaur with Apache License 2.0 5 votes vote down vote up
public static Throwable getCauseOver(Throwable pae) {
    if (pae.getCause() == null) {
        return pae;
    } else if ((pae.getCause() instanceof PropertyAccessException) && !(pae.getCause() == pae)) {
        return getCauseOver(pae.getCause());
    } else {
        return pae.getCause();
    }
}