use of org.mvel2.ast.Contains 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
}
}
}
use of org.mvel2.ast.Contains in project drools by kiegroup.
the class TraitTriplePropertyWrapperClassBuilderImpl method initSoftField.
protected void initSoftField(MethodVisitor mv, String wrapperName, FieldDefinition field, ClassDefinition core, String internalWrapper) {
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, wrapperName, "store", Type.getDescriptor(TripleStore.class));
mv.visitVarInsn(ALOAD, 0);
mv.visitLdcInsn(field.resolveAlias());
mv.visitMethodInsn(INVOKEVIRTUAL, wrapperName, "propertyKey", "(" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Triple.class), false);
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(TripleStore.class), "contains", "(" + Type.getDescriptor(Triple.class) + ")Z", false);
Label l0 = new Label();
mv.visitJumpInsn(IFNE, l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, wrapperName, "store", Type.getDescriptor(TripleStore.class));
mv.visitVarInsn(ALOAD, 0);
mv.visitLdcInsn(field.resolveAlias());
mv.visitInsn(BuildUtils.zero(field.getTypeName()));
if (BuildUtils.isPrimitive(field.getTypeName())) {
TraitFactory.valueOf(mv, field.getTypeName());
}
mv.visitMethodInsn(INVOKEVIRTUAL, wrapperName, "property", "(" + Type.getDescriptor(String.class) + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(Triple.class), false);
mv.visitInsn(ICONST_1);
mv.visitMethodInsn(INVOKEVIRTUAL, Type.getInternalName(TripleStore.class), "put", "(" + Type.getDescriptor(Triple.class) + "Z)Z", false);
if (core.isFullTraiting()) {
super.registerLogicalField(mv, internalWrapper, field, core);
}
mv.visitInsn(POP);
mv.visitLabel(l0);
}
use of org.mvel2.ast.Contains in project drools by kiegroup.
the class ConditionAnalyzer method analyzeSingleCondition.
private SingleCondition analyzeSingleCondition(ASTNode node, boolean isNegated) {
SingleCondition condition = new SingleCondition(isNegated);
if (node instanceof BinaryOperation) {
BinaryOperation binaryOperation = (BinaryOperation) node;
condition.left = analyzeNode(binaryOperation.getLeft());
condition.operation = BooleanOperator.fromMvelOpCode(binaryOperation.getOperation());
condition.right = analyzeNode(binaryOperation.getRight());
} else if (node instanceof RegExMatch) {
condition.left = analyzeNode(node);
condition.operation = BooleanOperator.MATCHES;
RegExMatch regExNode = (RegExMatch) node;
Pattern pattern = regExNode.getPattern();
if (pattern != null) {
condition.right = new FixedExpression(String.class, pattern.pattern());
} else {
condition.right = analyzeNode(((ExecutableAccessor) regExNode.getPatternStatement()).getNode());
}
} else if (node instanceof Contains) {
condition.left = analyzeNode(((Contains) node).getFirstStatement());
condition.operation = BooleanOperator.CONTAINS;
condition.right = analyzeNode(((Contains) node).getSecondStatement());
} else if (node instanceof Soundslike) {
condition.left = analyzeNode(((Soundslike) node).getStatement());
condition.operation = BooleanOperator.SOUNDSLIKE;
condition.right = analyzeNode(((Soundslike) node).getSoundslike());
} else if (node instanceof Instance) {
condition.left = analyzeNode(((Instance) node).getStatement());
condition.operation = BooleanOperator.INSTANCEOF;
condition.right = analyzeNode(((Instance) node).getClassStatement());
} else {
condition.left = analyzeNode(node);
}
return condition;
}
Aggregations