Commit 41d96e92 authored by Cyril Dangerville's avatar Cyril Dangerville

Added FunctionCall class for eager evaluation with parameters of

different primitive types like time arithmetic functions
parent 3bb493a6
......@@ -41,7 +41,7 @@ import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunction;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
/**
* A class that implements the not function. This function takes one boolean argument and returns
......@@ -71,7 +71,7 @@ public class NotFunction extends FirstOrderFunction<BooleanAttributeValue>
@Override
protected FirstOrderFunctionCall<BooleanAttributeValue> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes) throws IllegalArgumentException
{
return new EagerPrimitiveEval<BooleanAttributeValue, BooleanAttributeValue>(signature, BooleanAttributeValue[].class, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<BooleanAttributeValue, BooleanAttributeValue>(signature, BooleanAttributeValue[].class, argExpressions, remainingArgTypes)
{
@Override
protected BooleanAttributeValue evaluate(BooleanAttributeValue[] args) throws IndeterminateEvaluationException
......
......@@ -42,7 +42,7 @@ import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunction;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
import com.thalesgroup.authzforce.core.func.FunctionSet;
/**
......@@ -91,7 +91,7 @@ public abstract class StringNormalizeFunction extends FirstOrderFunction<StringA
@Override
protected final FirstOrderFunctionCall<StringAttributeValue> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes) throws IllegalArgumentException
{
return new EagerPrimitiveEval<StringAttributeValue, StringAttributeValue>(signature, StringAttributeValue[].class, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<StringAttributeValue, StringAttributeValue>(signature, StringAttributeValue[].class, argExpressions, remainingArgTypes)
{
@Override
protected StringAttributeValue evaluate(StringAttributeValue[] args) throws IndeterminateEvaluationException
......
......@@ -44,7 +44,7 @@ import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunction;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
/**
* This class implements the time-in-range function, which takes three time values and returns true
......@@ -192,7 +192,7 @@ public class TimeInRangeFunction extends FirstOrderFunction<BooleanAttributeValu
@Override
protected FirstOrderFunctionCall<BooleanAttributeValue> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes) throws IllegalArgumentException
{
return new EagerPrimitiveEval<BooleanAttributeValue, TimeAttributeValue>(signature, TimeAttributeValue[].class, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<BooleanAttributeValue, TimeAttributeValue>(signature, TimeAttributeValue[].class, argExpressions, remainingArgTypes)
{
@Override
......
......@@ -173,20 +173,21 @@ public class DoubleAttributeValue extends NumericAttributeValue<Double, DoubleAt
return new DoubleAttributeValue(Math.rint(value));
}
public static void main(String... args)
{
Double arg1 = new Double("1");
Double divisor = new Double("0");
Double result = arg1 / divisor;
System.out.println(result); // Infinity!
arg1 = new Double("-1");
result = arg1 / divisor;
System.out.println(result); // -Infinity!
Double positiveZero = new Double("0.");
Double negativeZero = new Double("-0.");
System.out.println(positiveZero.equals(negativeZero));
}
// For quick testing
// public static void main(String... args)
// {
// Double arg1 = new Double("1");
// Double divisor = new Double("0");
// Double result = arg1 / divisor;
// System.out.println(result); // Infinity!
// arg1 = new Double("-1");
// result = arg1 / divisor;
// System.out.println(result); // -Infinity!
//
// Double positiveZero = new Double("0.");
// Double negativeZero = new Double("-0.");
// System.out.println(positiveZero.equals(negativeZero));
// }
@Override
public DoubleAttributeValue subtract(DoubleAttributeValue subtractedVal)
......
......@@ -142,12 +142,14 @@ public class X500NameAttributeValue extends SimpleAttributeValue<String, X500Nam
return ldapName.equals(other.ldapName);
}
public static void main(String[] args) throws InvalidNameException
{
// System.out.println(new LdapName("cn=John Smith, o=Medico Corp, c=US").equals(new
// LdapName("cn= John Smith,o =Medico Corp, C=US")));
// System.out.println(new LdapName("ou=test+cn=bob,dc =example,dc=com"));
System.out.println(new LdapName("cn=John Smith, o=Medico Corp, c=US").endsWith(new LdapName("o=Medico Corp, c=US").getRdns()));
}
// For quick testing
// public static void main(String[] args) throws InvalidNameException
// {
// // System.out.println(new LdapName("cn=John Smith, o=Medico Corp, c=US").equals(new
// // LdapName("cn= John Smith,o =Medico Corp, C=US")));
// // System.out.println(new LdapName("ou=test+cn=bob,dc =example,dc=com"));
// System.out.println(new LdapName("cn=John Smith, o=Medico Corp, c=US").endsWith(new
// LdapName("o=Medico Corp, c=US").getRdns()));
// }
}
......@@ -28,7 +28,7 @@ import com.thalesgroup.authzforce.core.attr.BooleanAttributeValue;
import com.thalesgroup.authzforce.core.attr.DatatypeConstants;
import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
/**
* A superclass of all the standard comparison functions (return a boolean).
......@@ -136,7 +136,7 @@ public abstract class BaseComparisonFunction<AV extends AttributeValue<AV>> exte
@Override
protected final FirstOrderFunctionCall<BooleanAttributeValue> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes)
{
return new EagerPrimitiveEval<BooleanAttributeValue, AV>(signature, paramArrayClass, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<BooleanAttributeValue, AV>(signature, paramArrayClass, argExpressions, remainingArgTypes)
{
@Override
protected BooleanAttributeValue evaluate(AV[] args) throws IndeterminateEvaluationException
......
......@@ -41,7 +41,7 @@ import com.thalesgroup.authzforce.core.attr.X500NameAttributeValue;
import com.thalesgroup.authzforce.core.attr.YearMonthDurationAttributeValue;
import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
/**
* A class that implements all the primitive datatype conversion functions: double-to-integer,
......@@ -285,7 +285,7 @@ public abstract class DatatypeConversionFunction<PARAM_T extends SimpleAttribute
@Override
protected final FirstOrderFunctionCall<RETURN_T> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes) throws IllegalArgumentException
{
return new EagerPrimitiveEval<RETURN_T, PARAM_T>(signature, parameterArrayClass, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<RETURN_T, PARAM_T>(signature, parameterArrayClass, argExpressions, remainingArgTypes)
{
@Override
protected RETURN_T evaluate(PARAM_T[] args) throws IndeterminateEvaluationException
......
......@@ -41,7 +41,7 @@ import com.thalesgroup.authzforce.core.attr.X500NameAttributeValue;
import com.thalesgroup.authzforce.core.attr.YearMonthDurationAttributeValue;
import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
/**
* Implements generic match functions taking parameters of same/equal type, i.e. standard (A.3.1)
......@@ -219,7 +219,7 @@ public abstract class EqualTypeMatchFunction<PARAM extends AttributeValue<PARAM>
@Override
protected FirstOrderFunctionCall<BooleanAttributeValue> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes)
{
return new EagerPrimitiveEval<BooleanAttributeValue, PARAM>(signature, parameterArrayClass, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<BooleanAttributeValue, PARAM>(signature, parameterArrayClass, argExpressions, remainingArgTypes)
{
@Override
protected final BooleanAttributeValue evaluate(PARAM[] args) throws IndeterminateEvaluationException
......
......@@ -37,7 +37,7 @@ import com.thalesgroup.authzforce.core.eval.Expression.Value;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerBagEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPartlyBagEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
/**
* Base class for first-order bag function groups, as opposed to the higher-order bag functions (see
......@@ -216,7 +216,7 @@ public abstract class FirstOrderBagFunctionSet extends FunctionSet
@Override
protected final FirstOrderFunctionCall<Bag<AV>> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes) throws IllegalArgumentException
{
return new EagerPrimitiveEval<Bag<AV>, AV>(signature, arrayClass, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<Bag<AV>, AV>(signature, arrayClass, argExpressions, remainingArgTypes)
{
@Override
......
......@@ -246,8 +246,11 @@ public abstract class HigherOrderBagFunction<RETURN_T extends Expression.Value<?
private final Expression<?> lastArgBag;
private final int lastArgIndex;
protected OneBagOnlyFunctionCall(FirstOrderFunction<SUB_RETURN_T> subFunction, List<Expression<?>> primitiveInputs, Expression<Bag<?>> lastInputBag)
protected OneBagOnlyFunctionCall(FirstOrderFunction<SUB_RETURN_T> subFunction, List<Expression<?>> primitiveInputs, Expression<?> lastInputBag)
{
assert lastInputBag.getReturnType().isBag();
// primitiveInputs types are validated by subFunction.newCall(...);
/*
* The actual expression passed as last argument to the sub-function is not yet
* known; but we know the expected datatype is the type of each element
......@@ -310,7 +313,7 @@ public abstract class HigherOrderBagFunction<RETURN_T extends Expression.Value<?
// inputs that we can parse/validate for the sub-function are the primitive inputs, i.e.
// all except last one which is a bag
final List<Expression<?>> primitiveInputs = new ArrayList<>();
Expression<Bag<?>> lastInputBag = null;
Expression<?> lastInputBag = null;
boolean hasNextInput = true;
while (hasNextInput)
{
......@@ -334,7 +337,7 @@ public abstract class HigherOrderBagFunction<RETURN_T extends Expression.Value<?
throw new IllegalArgumentException(this + ": Invalid last argument type: primitive (not a bag). Required: a bag");
}
lastInputBag = (Expression<Bag<?>>) input;
lastInputBag = input;
}
}
......
......@@ -36,7 +36,7 @@ import com.thalesgroup.authzforce.core.attr.StringAttributeValue;
import com.thalesgroup.authzforce.core.eval.EvaluationContext;
import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerMultiPrimitiveTypeEval;
/**
* Implements generic match functions taking two parameters of possibly different types, e.g. a
......@@ -161,11 +161,11 @@ public abstract class NonEqualTypeMatchFunction<T0 extends AttributeValue<T0>, T
* Actual argument types are expected to be different, therefore we use the supertype
* AttributeValue as generic parameter type for all when creating the function call
*/
return new EagerPrimitiveEval<BooleanAttributeValue, AttributeValue>(signature, AttributeValue[].class, argExpressions, remainingArgTypes)
return new EagerMultiPrimitiveTypeEval<BooleanAttributeValue>(signature, argExpressions, remainingArgTypes)
{
@Override
protected final BooleanAttributeValue evaluate(AttributeValue[] args) throws IndeterminateEvaluationException
protected final BooleanAttributeValue evaluate(AttributeValue<?>[] args) throws IndeterminateEvaluationException
{
final T0 arg0;
final T1 arg1;
......
......@@ -28,7 +28,7 @@ import com.thalesgroup.authzforce.core.attr.IntegerAttributeValue;
import com.thalesgroup.authzforce.core.attr.NumericAttributeValue;
import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
/**
* A class that implements all the numeric *-add functions (as opposed to date/time *-add-*
......@@ -157,7 +157,7 @@ public abstract class NumericArithmeticFunction<AV extends NumericAttributeValue
*
*/
return new EagerPrimitiveEval<AV, AV>(signature, parameterArrayClass, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<AV, AV>(signature, parameterArrayClass, argExpressions, remainingArgTypes)
{
@Override
......
......@@ -25,7 +25,7 @@ import com.thalesgroup.authzforce.core.attr.SimpleAttributeValue;
import com.thalesgroup.authzforce.core.attr.StringAttributeValue;
import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
/**
* Implements string-concatenate function
......@@ -65,7 +65,7 @@ public class StringConcatenateFunction<AV extends SimpleAttributeValue<String, A
protected FirstOrderFunctionCall<StringAttributeValue> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes)
{
return new EagerPrimitiveEval<StringAttributeValue, AV>(signature, paramArrayClass, argExpressions, remainingArgTypes)
return new EagerSinglePrimitiveTypeEval<StringAttributeValue, AV>(signature, paramArrayClass, argExpressions, remainingArgTypes)
{
@Override
......
......@@ -28,7 +28,7 @@ import com.thalesgroup.authzforce.core.attr.SimpleAttributeValue;
import com.thalesgroup.authzforce.core.attr.StringAttributeValue;
import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerMultiPrimitiveTypeEval;
/**
* Implements *-substring functions
......@@ -78,11 +78,11 @@ public class SubstringFunction<AV extends SimpleAttributeValue<String, AV>> exte
@Override
protected FirstOrderFunctionCall<StringAttributeValue> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes)
{
return new EagerPrimitiveEval<StringAttributeValue, AttributeValue>(signature, AttributeValue[].class, argExpressions, remainingArgTypes)
return new EagerMultiPrimitiveTypeEval<StringAttributeValue>(signature, argExpressions, remainingArgTypes)
{
@Override
protected StringAttributeValue evaluate(AttributeValue[] args) throws IndeterminateEvaluationException
protected StringAttributeValue evaluate(AttributeValue<?>[] args) throws IndeterminateEvaluationException
{
final AV arg0;
final IntegerAttributeValue beginIndex;
......
......@@ -27,7 +27,7 @@ import com.thalesgroup.authzforce.core.attr.DatatypeConstants;
import com.thalesgroup.authzforce.core.attr.DurationAttributeValue;
import com.thalesgroup.authzforce.core.eval.Expression;
import com.thalesgroup.authzforce.core.eval.IndeterminateEvaluationException;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerPrimitiveEval;
import com.thalesgroup.authzforce.core.func.FirstOrderFunctionCall.EagerMultiPrimitiveTypeEval;
/**
* Implements generic match functions taking parameters of possibly different types.
......@@ -97,12 +97,13 @@ public abstract class TemporalArithmeticFunction<T extends BaseTimeAttributeValu
@Override
protected final FirstOrderFunctionCall<T> newCall(List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes) throws IllegalArgumentException
{
return new EagerPrimitiveEval<T, AttributeValue>(signature, AttributeValue[].class, argExpressions, remainingArgTypes)
return new EagerMultiPrimitiveTypeEval<T>(signature, argExpressions, remainingArgTypes)
{
@Override
protected T evaluate(AttributeValue[] args) throws IndeterminateEvaluationException
protected T evaluate(AttributeValue<?>[] args) throws IndeterminateEvaluationException
{
final T arg0;
final D arg1;
try
......
......@@ -18,6 +18,10 @@
*/
package com.thalesgroup.authzforce.core.test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
......@@ -26,6 +30,8 @@ import org.junit.runners.Suite.SuiteClasses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.thalesgroup.authzforce.core.attr.AttributeValue;
import com.thalesgroup.authzforce.core.attr.BooleanAttributeValue;
import com.thalesgroup.authzforce.core.test.attr.AnyURIAttributeTest;
import com.thalesgroup.authzforce.core.test.conformance.ConformanceV3FromV2;
import com.thalesgroup.authzforce.core.test.conformance.ConformanceV3Others;
......@@ -76,4 +82,14 @@ public class MainTest
{
LOGGER.info("Finishing Tests");
}
public static void main(String[] args)
{
Collection<? extends AttributeValue<?>> values = Collections.unmodifiableCollection(Arrays.asList(BooleanAttributeValue.TRUE, BooleanAttributeValue.FALSE));
// values.add(BooleanAttributeValue.TRUE);
// values.add(BooleanAttributeValue.FALSE);
Collection<BooleanAttributeValue> boolValues = (Collection) values;
System.out.println(boolValues);
}
}
......@@ -14,13 +14,13 @@
</encoder>
</appender>
<logger name="com.sun.xacml" additivity="false" level="DEBUG">
<appender-ref ref="stdout" />
</logger>
<logger name="com.thalesgroup.authzforce" additivity="false" level="DEBUG">
<appender-ref ref="stdout" />
</logger>
<!-- <root level="INFO"> -->
<!-- <logger name="com.sun.xacml" additivity="false" level="DEBUG"> -->
<!-- <appender-ref ref="stdout" /> -->
<!-- </root> -->
<!-- </logger> -->
<!-- <logger name="com.thalesgroup.authzforce" additivity="false" level="DEBUG"> -->
<!-- <appender-ref ref="stdout" /> -->
<!-- </logger> -->
<root level="INFO">
<appender-ref ref="stdout" />
</root>
</configuration>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment