Commit e7289923 authored by cdanger's avatar cdanger

- Update to new PDP API using java.util.Optional when relevant:

	- Change of type in AttributeGUID constructor's issuer parameter from
String to Optional <String>
	- Change of type in StatusHelper constructor's message and detail
parameters, from String to Optional<String>
	- Change of type returned by Datatype#getTypeParameter(): Datatype<?>
-> Optional<Datatype<?>>
parent 4f69942a
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>${artifactId.prefix}-core-pdp-api</artifactId> <artifactId>${artifactId.prefix}-core-pdp-api</artifactId>
<version>9.0.0</version> <version>9.0.1-SNAPSHOT</version>
</dependency> </dependency>
<!-- /Authzforce dependencies --> <!-- /Authzforce dependencies -->
......
...@@ -27,6 +27,7 @@ import java.util.Collections; ...@@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
...@@ -111,7 +112,7 @@ public final class BasePdpEngine implements CloseablePDP<ImmutablePdpDecisionReq ...@@ -111,7 +112,7 @@ public final class BasePdpEngine implements CloseablePDP<ImmutablePdpDecisionReq
* Indeterminate response iff CombinedDecision element not supported because the request parser does not support any scheme from MultipleDecisionProfile section 2. * Indeterminate response iff CombinedDecision element not supported because the request parser does not support any scheme from MultipleDecisionProfile section 2.
*/ */
private static final Response UNSUPPORTED_COMBINED_DECISION_RESPONSE = new Response(Collections.<Result> singletonList(new Result(DecisionType.INDETERMINATE, new StatusHelper( private static final Response UNSUPPORTED_COMBINED_DECISION_RESPONSE = new Response(Collections.<Result> singletonList(new Result(DecisionType.INDETERMINATE, new StatusHelper(
StatusHelper.STATUS_SYNTAX_ERROR, "Unsupported feature: CombinedDecision='true'"), null, null, null, null))); StatusHelper.STATUS_SYNTAX_ERROR, Optional.of("Unsupported feature: CombinedDecision='true'")), null, null, null, null)));
private interface StandardEnvironmentAttributeIssuer private interface StandardEnvironmentAttributeIssuer
{ {
...@@ -207,7 +208,7 @@ public final class BasePdpEngine implements CloseablePDP<ImmutablePdpDecisionReq ...@@ -207,7 +208,7 @@ public final class BasePdpEngine implements CloseablePDP<ImmutablePdpDecisionReq
/* /*
* Put the non-issued version of the attribute first * Put the non-issued version of the attribute first
*/ */
final AttributeGUID nonIssuedAttributeGUID = new AttributeGUID(attributeGUID.getCategory(), null, attributeGUID.getId()); final AttributeGUID nonIssuedAttributeGUID = new AttributeGUID(attributeGUID.getCategory(), Optional.empty(), attributeGUID.getId());
super.putNamedAttributeIfAbsent(nonIssuedAttributeGUID, attributeValues); super.putNamedAttributeIfAbsent(nonIssuedAttributeGUID, attributeValues);
return super.putNamedAttributeIfAbsent(attributeGUID, attributeValues); return super.putNamedAttributeIfAbsent(attributeGUID, attributeValues);
} }
...@@ -277,8 +278,8 @@ public final class BasePdpEngine implements CloseablePDP<ImmutablePdpDecisionReq ...@@ -277,8 +278,8 @@ public final class BasePdpEngine implements CloseablePDP<ImmutablePdpDecisionReq
private static final IndeterminateEvaluationException INDETERMINATE_EVALUATION_EXCEPTION = new IndeterminateEvaluationException("Internal error in decision cache: null result", private static final IndeterminateEvaluationException INDETERMINATE_EVALUATION_EXCEPTION = new IndeterminateEvaluationException("Internal error in decision cache: null result",
StatusHelper.STATUS_PROCESSING_ERROR); StatusHelper.STATUS_PROCESSING_ERROR);
private static final Result INVALID_DECISION_CACHE_RESULT = new Result(DecisionType.INDETERMINATE, new StatusHelper(StatusHelper.STATUS_PROCESSING_ERROR, "Internal error"), null, null, null, private static final Result INVALID_DECISION_CACHE_RESULT = new Result(DecisionType.INDETERMINATE, new StatusHelper(StatusHelper.STATUS_PROCESSING_ERROR, Optional.of("Internal error")), null,
null); null, null, null);
private final DecisionCache decisionCache; private final DecisionCache decisionCache;
......
...@@ -20,6 +20,7 @@ package org.ow2.authzforce.core.pdp.impl; ...@@ -20,6 +20,7 @@ package org.ow2.authzforce.core.pdp.impl;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
...@@ -57,7 +58,7 @@ public class ModularAttributeProvider implements AttributeProvider ...@@ -57,7 +58,7 @@ public class ModularAttributeProvider implements AttributeProvider
@Override @Override
public void process(final AttributeGUID attributeGUID, final Bag<?> result, final EvaluationContext context) public void process(final AttributeGUID attributeGUID, final Bag<?> result, final EvaluationContext context)
{ {
if (attributeGUID.getIssuer() == null) if (!attributeGUID.getIssuer().isPresent())
{ {
// Attribute already without Issuer -> nothing to copy // Attribute already without Issuer -> nothing to copy
return; return;
...@@ -65,7 +66,7 @@ public class ModularAttributeProvider implements AttributeProvider ...@@ -65,7 +66,7 @@ public class ModularAttributeProvider implements AttributeProvider
/* /*
* Attribute with Issuer -> make Issuer-less copy and put same result in context for match by Issuer-less AttributeDesignator * Attribute with Issuer -> make Issuer-less copy and put same result in context for match by Issuer-less AttributeDesignator
*/ */
final AttributeGUID issuerLessAttributeGUID = new AttributeGUID(attributeGUID.getCategory(), null, attributeGUID.getId()); final AttributeGUID issuerLessAttributeGUID = new AttributeGUID(attributeGUID.getCategory(), Optional.empty(), attributeGUID.getId());
/* /*
* Cache the attribute value(s) for the issuer-less attribute in context in case there is a matching Issuer-less AttributeDesignator to evaluate * Cache the attribute value(s) for the issuer-less attribute in context in case there is a matching Issuer-less AttributeDesignator to evaluate
*/ */
......
...@@ -20,10 +20,11 @@ package org.ow2.authzforce.core.pdp.impl; ...@@ -20,10 +20,11 @@ package org.ow2.authzforce.core.pdp.impl;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import org.ow2.authzforce.core.pdp.api.AttributeGUID; import org.ow2.authzforce.core.pdp.api.AttributeGUID;
import org.ow2.authzforce.xacml.identifiers.XACMLAttributeId;
import org.ow2.authzforce.xacml.identifiers.XACMLAttributeCategory; import org.ow2.authzforce.xacml.identifiers.XACMLAttributeCategory;
import org.ow2.authzforce.xacml.identifiers.XACMLAttributeId;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
...@@ -38,17 +39,17 @@ public enum StandardEnvironmentAttribute ...@@ -38,17 +39,17 @@ public enum StandardEnvironmentAttribute
/** /**
* urn:oasis:names:tc:xacml:1.0:environment:current-time * urn:oasis:names:tc:xacml:1.0:environment:current-time
*/ */
CURRENT_TIME(new AttributeGUID(XACMLAttributeCategory.XACML_3_0_ENVIRONMENT.value(), null, XACMLAttributeId.XACML_1_0_ENVIRONMENT_CURRENT_TIME.value())), CURRENT_TIME(new AttributeGUID(XACMLAttributeCategory.XACML_3_0_ENVIRONMENT.value(), Optional.empty(), XACMLAttributeId.XACML_1_0_ENVIRONMENT_CURRENT_TIME.value())),
/** /**
* urn:oasis:names:tc:xacml:1.0:environment:current-date * urn:oasis:names:tc:xacml:1.0:environment:current-date
*/ */
CURRENT_DATE(new AttributeGUID(XACMLAttributeCategory.XACML_3_0_ENVIRONMENT.value(), null, XACMLAttributeId.XACML_1_0_ENVIRONMENT_CURRENT_DATE.value())), CURRENT_DATE(new AttributeGUID(XACMLAttributeCategory.XACML_3_0_ENVIRONMENT.value(), Optional.empty(), XACMLAttributeId.XACML_1_0_ENVIRONMENT_CURRENT_DATE.value())),
/** /**
* urn:oasis:names:tc:xacml:1.0:environment:current-dateTime * urn:oasis:names:tc:xacml:1.0:environment:current-dateTime
*/ */
CURRENT_DATETIME(new AttributeGUID(XACMLAttributeCategory.XACML_3_0_ENVIRONMENT.value(), null, XACMLAttributeId.XACML_1_0_ENVIRONMENT_CURRENT_DATETIME.value())); CURRENT_DATETIME(new AttributeGUID(XACMLAttributeCategory.XACML_3_0_ENVIRONMENT.value(), Optional.empty(), XACMLAttributeId.XACML_1_0_ENVIRONMENT_CURRENT_DATETIME.value()));
private final AttributeGUID attributeGUID; private final AttributeGUID attributeGUID;
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
*/ */
package org.ow2.authzforce.core.pdp.impl.combining; package org.ow2.authzforce.core.pdp.impl.combining;
import java.util.Optional;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.DecisionType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.DecisionType;
...@@ -55,8 +57,8 @@ final class OnlyOneApplicableCombiningAlg extends BaseCombiningAlg<PolicyEvaluat ...@@ -55,8 +57,8 @@ final class OnlyOneApplicableCombiningAlg extends BaseCombiningAlg<PolicyEvaluat
private Evaluator(final String algId, final Iterable<? extends PolicyEvaluator> policyElements) private Evaluator(final String algId, final Iterable<? extends PolicyEvaluator> policyElements)
{ {
super(policyElements); super(policyElements);
this.tooManyApplicablePoliciesIndeterminateResult = ExtendedDecisions.newIndeterminate(DecisionType.INDETERMINATE, new StatusHelper(StatusHelper.STATUS_PROCESSING_ERROR, this.tooManyApplicablePoliciesIndeterminateResult = ExtendedDecisions.newIndeterminate(DecisionType.INDETERMINATE,
"Too many (more than one) applicable policies for algorithm: " + algId)); new StatusHelper(StatusHelper.STATUS_PROCESSING_ERROR, Optional.of("Too many (more than one) applicable policies for algorithm: " + algId)));
} }
@Override @Override
......
...@@ -57,10 +57,7 @@ import org.ow2.authzforce.core.pdp.api.value.Datatype; ...@@ -57,10 +57,7 @@ import org.ow2.authzforce.core.pdp.api.value.Datatype;
*/ */
public final class AttributeDesignatorExpression<AV extends AttributeValue> implements Expression<Bag<AV>> public final class AttributeDesignatorExpression<AV extends AttributeValue> implements Expression<Bag<AV>>
{ {
private static final IllegalArgumentException NULL_CATEGORY_EXCEPTION = new IllegalArgumentException("Undefined attribute designator category"); private static final IllegalArgumentException NULL_ATTRIBUTE_PROVIDER_EXCEPTION = new IllegalArgumentException("Undefined attribute Provider");
private static final IllegalArgumentException NULL_DATATYPE_EXCEPTION = new IllegalArgumentException("Undefined attribute designator datatype");
private static final IllegalArgumentException NULL_ATTRIBUTE_ID_EXCEPTION = new IllegalArgumentException("Undefined attribute designator AttribtueId");
private static final IllegalArgumentException NULL_ATTRIBUTE_Provider_EXCEPTION = new IllegalArgumentException("Undefined attribute Provider");
private static final UnsupportedOperationException UNSUPPORTED_OPERATION_EXCEPTION = new UnsupportedOperationException(); private static final UnsupportedOperationException UNSUPPORTED_OPERATION_EXCEPTION = new UnsupportedOperationException();
private final transient AttributeGUID attrGUID; private final transient AttributeGUID attrGUID;
...@@ -91,35 +88,19 @@ public final class AttributeDesignatorExpression<AV extends AttributeValue> impl ...@@ -91,35 +88,19 @@ public final class AttributeDesignatorExpression<AV extends AttributeValue> impl
* expected datatype of the result of evaluating this AttributeDesignator ( {@code AV is the expected type of every element in the bag}) * expected datatype of the result of evaluating this AttributeDesignator ( {@code AV is the expected type of every element in the bag})
* @param attrProvider * @param attrProvider
* Attribute Provider responsible for finding the attribute designated by this in a given evaluation context at runtime * Attribute Provider responsible for finding the attribute designated by this in a given evaluation context at runtime
* @throws IllegalArgumentException
* if {@code attrDesignator.getCategory() == null || attrDesignator.getAttributeId() == null}
*/ */
public AttributeDesignatorExpression(final AttributeDesignatorType attrDesignator, final BagDatatype<AV> resultDatatype, final AttributeProvider attrProvider) public AttributeDesignatorExpression(final AttributeDesignatorType attrDesignator, final BagDatatype<AV> resultDatatype, final AttributeProvider attrProvider)
{ {
final String categoryURI = attrDesignator.getCategory();
if (categoryURI == null)
{
throw NULL_CATEGORY_EXCEPTION;
}
final String datatypeURI = attrDesignator.getDataType();
if (datatypeURI == null)
{
throw NULL_DATATYPE_EXCEPTION;
}
final String id = attrDesignator.getAttributeId();
if (id == null)
{
throw NULL_ATTRIBUTE_ID_EXCEPTION;
}
if (attrProvider == null) if (attrProvider == null)
{ {
throw NULL_ATTRIBUTE_Provider_EXCEPTION; throw NULL_ATTRIBUTE_PROVIDER_EXCEPTION;
} }
this.attrGUID = new AttributeGUID(categoryURI, attrDesignator.getIssuer(), id);
this.returnType = resultDatatype;
this.attrProvider = attrProvider; this.attrProvider = attrProvider;
this.attrGUID = new AttributeGUID(attrDesignator);
this.returnType = resultDatatype;
// error messages/exceptions // error messages/exceptions
final String missingAttributeMessage = this + " not found in context"; final String missingAttributeMessage = this + " not found in context";
......
...@@ -24,6 +24,7 @@ import java.util.Collections; ...@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.Deque; import java.util.Deque;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName; import javax.xml.namespace.QName;
...@@ -311,7 +312,7 @@ public final class AttributeSelectorExpression<AV extends AttributeValue> implem ...@@ -311,7 +312,7 @@ public final class AttributeSelectorExpression<AV extends AttributeValue> implem
throw NULL_ATTRIBUTE_Provider_BUT_NON_NULL_CONTEXT_SELECTOR_ID_EXCEPTION; throw NULL_ATTRIBUTE_Provider_BUT_NON_NULL_CONTEXT_SELECTOR_ID_EXCEPTION;
} }
final AttributeGUID contextSelectorGUID = new AttributeGUID(attributeSelectorId.getCategory(), null, contextSelectorId); final AttributeGUID contextSelectorGUID = new AttributeGUID(attributeSelectorId.getCategory(), Optional.empty(), contextSelectorId);
final String missingContextSelectorAttributeExceptionMessage = this + ": No value found for attribute designated by Category=" + attributeCategory + " and ContextSelectorId=" final String missingContextSelectorAttributeExceptionMessage = this + ": No value found for attribute designated by Category=" + attributeCategory + " and ContextSelectorId="
+ contextSelectorId; + contextSelectorId;
final IndeterminateEvaluationException missingAttributeForUnknownReasonException = new IndeterminateEvaluationException(missingAttributeMessage + " for unknown reason", final IndeterminateEvaluationException missingAttributeForUnknownReasonException = new IndeterminateEvaluationException(missingAttributeMessage + " for unknown reason",
...@@ -432,19 +433,14 @@ public final class AttributeSelectorExpression<AV extends AttributeValue> implem ...@@ -432,19 +433,14 @@ public final class AttributeSelectorExpression<AV extends AttributeValue> implem
final AttributeValue attrVal; final AttributeValue attrVal;
try try
{ {
attrVal = attrFactory.getInstance(jaxbAttrVal.getContent(), jaxbAttrVal.getOtherAttributes(), attrVal = attrFactory.getInstance(jaxbAttrVal.getContent(), jaxbAttrVal.getOtherAttributes(), this.xpathCompiler);
this.xpathCompiler);
} }
catch (final IllegalArgumentException e) catch (final IllegalArgumentException e)
{ {
final String contextSelectorId = attributeSelectorId.getContextSelectorId(); final String contextSelectorId = attributeSelectorId.getContextSelectorId();
throw new IndeterminateEvaluationException(this + ": Error creating attribute value of type '" throw new IndeterminateEvaluationException(this + ": Error creating attribute value of type '" + attributeDatatype + "' from result #" + xpathEvalResultItemIndex
+ attributeDatatype + "' from result #" + xpathEvalResultItemIndex + " of evaluating XPath against XML node from Content of Attributes Category='" + attributeSelectorId.getCategory() + "'"
+ " of evaluating XPath against XML node from Content of Attributes Category='" + (contextSelectorId == null ? "" : " selected by ContextSelectorId='" + contextSelectorId + "'") + ": " + xpathEvalResultItem, StatusHelper.STATUS_SYNTAX_ERROR, e);
+ attributeSelectorId.getCategory() + "'"
+ (contextSelectorId == null ? ""
: " selected by ContextSelectorId='" + contextSelectorId + "'")
+ ": " + xpathEvalResultItem, StatusHelper.STATUS_SYNTAX_ERROR, e);
} }
resultBag.add(attributeDatatype.cast(attrVal)); resultBag.add(attributeDatatype.cast(attrVal));
......
...@@ -65,7 +65,7 @@ final class MapFunctionFactory extends GenericHigherOrderFunctionFactory ...@@ -65,7 +65,7 @@ final class MapFunctionFactory extends GenericHigherOrderFunctionFactory
private final String indeterminateSubFuncEvalMessagePrefix; private final String indeterminateSubFuncEvalMessagePrefix;
private Call(final String functionId, final Datatype<Bag<SUB_RETURN>> returnType, final FirstOrderFunction<SUB_RETURN> subFunction, final List<Expression<?>> primitiveInputs, private Call(final String functionId, final Datatype<Bag<SUB_RETURN>> returnType, final FirstOrderFunction<SUB_RETURN> subFunction, final List<Expression<?>> primitiveInputs,
final Expression<?> lastInputBag) final Expression<? extends Bag<?>> lastInputBag)
{ {
super(functionId, returnType, subFunction, primitiveInputs, lastInputBag); super(functionId, returnType, subFunction, primitiveInputs, lastInputBag);
this.returnBagElementType = subFunction.getReturnType(); this.returnBagElementType = subFunction.getReturnType();
...@@ -108,7 +108,7 @@ final class MapFunctionFactory extends GenericHigherOrderFunctionFactory ...@@ -108,7 +108,7 @@ final class MapFunctionFactory extends GenericHigherOrderFunctionFactory
@Override @Override
protected OneBagOnlyHigherOrderFunction.Call<Bag<SUB_RETURN_T>, SUB_RETURN_T> newFunctionCall(final FirstOrderFunction<SUB_RETURN_T> subFunc, final List<Expression<?>> primitiveInputs, protected OneBagOnlyHigherOrderFunction.Call<Bag<SUB_RETURN_T>, SUB_RETURN_T> newFunctionCall(final FirstOrderFunction<SUB_RETURN_T> subFunc, final List<Expression<?>> primitiveInputs,
final Expression<?> lastInputBag) final Expression<? extends Bag<?>> lastInputBag)
{ {
return new Call<>(this.getId(), this.getReturnType(), subFunc, primitiveInputs, lastInputBag); return new Call<>(this.getId(), this.getReturnType(), subFunc, primitiveInputs, lastInputBag);
} }
......
...@@ -58,7 +58,7 @@ final class SubstringFunction<AV extends SimpleValue<String>> extends MultiParam ...@@ -58,7 +58,7 @@ final class SubstringFunction<AV extends SimpleValue<String>> extends MultiParam
private final String invalidArgTypesErrorMsg; private final String invalidArgTypesErrorMsg;
private final String argsOutOfBoundsErrorMessage; private final String argsOutOfBoundsErrorMessage;
private final Class<? extends SimpleValue<String>> firstParamClass; private final Datatype<? extends SimpleValue<String>> param0Type;
private Call(final FirstOrderFunctionSignature<StringValue> functionSig, final Datatype<? extends SimpleValue<String>> param0Type, final List<Expression<?>> args, private Call(final FirstOrderFunctionSignature<StringValue> functionSig, final Datatype<? extends SimpleValue<String>> param0Type, final List<Expression<?>> args,
final Datatype<?>[] remainingArgTypes) throws IllegalArgumentException final Datatype<?>[] remainingArgTypes) throws IllegalArgumentException
...@@ -67,7 +67,7 @@ final class SubstringFunction<AV extends SimpleValue<String>> extends MultiParam ...@@ -67,7 +67,7 @@ final class SubstringFunction<AV extends SimpleValue<String>> extends MultiParam
this.invalidArgTypesErrorMsg = "Function " + functionId + ": Invalid arg types: expected: " + param0Type + ", " + StandardDatatypes.INTEGER_FACTORY.getDatatype() + ", " this.invalidArgTypesErrorMsg = "Function " + functionId + ": Invalid arg types: expected: " + param0Type + ", " + StandardDatatypes.INTEGER_FACTORY.getDatatype() + ", "
+ StandardDatatypes.INTEGER_FACTORY.getDatatype() + "; actual: "; + StandardDatatypes.INTEGER_FACTORY.getDatatype() + "; actual: ";
this.argsOutOfBoundsErrorMessage = "Function " + functionId + ": either beginIndex is out of bounds, or endIndex =/= -1 and out of bounds"; this.argsOutOfBoundsErrorMessage = "Function " + functionId + ": either beginIndex is out of bounds, or endIndex =/= -1 and out of bounds";
this.firstParamClass = param0Type.getValueClass(); this.param0Type = param0Type;
} }
@Override @Override
...@@ -82,7 +82,7 @@ final class SubstringFunction<AV extends SimpleValue<String>> extends MultiParam ...@@ -82,7 +82,7 @@ final class SubstringFunction<AV extends SimpleValue<String>> extends MultiParam
final IntegerValue endIndex; final IntegerValue endIndex;
try try
{ {
arg0 = firstParamClass.cast(rawArg0); arg0 = param0Type.cast(rawArg0);
beginIndex = (IntegerValue) rawArg1; beginIndex = (IntegerValue) rawArg1;
endIndex = (IntegerValue) rawArg2; endIndex = (IntegerValue) rawArg2;
} }
......
...@@ -44,8 +44,7 @@ import org.ow2.authzforce.core.pdp.api.value.DurationValue; ...@@ -44,8 +44,7 @@ import org.ow2.authzforce.core.pdp.api.value.DurationValue;
* *
* @version $Id: $ * @version $Id: $
*/ */
final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends DurationValue<D>> final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends DurationValue<D>> extends MultiParameterTypedFirstOrderFunction<T>
extends MultiParameterTypedFirstOrderFunction<T>
{ {
interface StaticOperation<TV extends BaseTimeValue<TV>, DV extends DurationValue<DV>> interface StaticOperation<TV extends BaseTimeValue<TV>, DV extends DurationValue<DV>>
{ {
...@@ -53,23 +52,20 @@ final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends Dur ...@@ -53,23 +52,20 @@ final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends Dur
TV eval(TV time, DV duration); TV eval(TV time, DV duration);
} }
private static final class Call<TV extends BaseTimeValue<TV>, DV extends DurationValue<DV>> private static final class Call<TV extends BaseTimeValue<TV>, DV extends DurationValue<DV>> extends EagerMultiPrimitiveTypeEval<TV>
extends EagerMultiPrimitiveTypeEval<TV>
{ {
private final String invalidArgTypesErrorMsg; private final String invalidArgTypesErrorMsg;
private final Class<DV> durationParamClass; private final Datatype<DV> durationParamType;
private final Class<TV> timeParamClass; private final Datatype<TV> timeParamType;
private final StaticOperation<TV, DV> op; private final StaticOperation<TV, DV> op;
private Call(final FirstOrderFunctionSignature<TV> functionSig, final Datatype<TV> timeParamType, private Call(final FirstOrderFunctionSignature<TV> functionSig, final Datatype<TV> timeParamType, final Datatype<DV> durationParamType, final StaticOperation<TV, DV> op,
final Datatype<DV> durationParamType, final StaticOperation<TV, DV> op, final List<Expression<?>> args, final List<Expression<?>> args, final Datatype<?>[] remainingArgTypes) throws IllegalArgumentException
final Datatype<?>[] remainingArgTypes) throws IllegalArgumentException
{ {
super(functionSig, args, remainingArgTypes); super(functionSig, args, remainingArgTypes);
invalidArgTypesErrorMsg = "Function " + this.functionId + ": Invalid arg types (expected: " + timeParamType invalidArgTypesErrorMsg = "Function " + this.functionId + ": Invalid arg types (expected: " + timeParamType + "," + durationParamType + "): ";
+ "," + durationParamType + "): "; this.timeParamType = timeParamType;
this.timeParamClass = timeParamType.getValueClass(); this.durationParamType = durationParamType;
this.durationParamClass = durationParamType.getValueClass();
this.op = op; this.op = op;
} }
...@@ -83,14 +79,12 @@ final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends Dur ...@@ -83,14 +79,12 @@ final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends Dur
final DV arg1; final DV arg1;
try try
{ {
arg0 = timeParamClass.cast(rawArg0); arg0 = timeParamType.cast(rawArg0);
arg1 = durationParamClass.cast(rawArg1); arg1 = durationParamType.cast(rawArg1);
} }
catch (final ClassCastException e) catch (final ClassCastException e)
{ {
throw new IndeterminateEvaluationException( throw new IndeterminateEvaluationException(invalidArgTypesErrorMsg + rawArg0.getDataType() + "," + rawArg1.getDataType(), StatusHelper.STATUS_PROCESSING_ERROR, e);
invalidArgTypesErrorMsg + rawArg0.getDataType() + "," + rawArg1.getDataType(),
StatusHelper.STATUS_PROCESSING_ERROR, e);
} }
return op.eval(arg0, arg1); return op.eval(arg0, arg1);
...@@ -115,8 +109,7 @@ final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends Dur ...@@ -115,8 +109,7 @@ final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends Dur
* @param op * @param op
* temporal arithmetic operation * temporal arithmetic operation
*/ */
TemporalArithmeticFunction(final String functionName, final Datatype<T> timeParamType, TemporalArithmeticFunction(final String functionName, final Datatype<T> timeParamType, final Datatype<D> durationParamType, final StaticOperation<T, D> op)
final Datatype<D> durationParamType, final StaticOperation<T, D> op)
{ {
super(functionName, timeParamType, false, Arrays.asList(timeParamType, durationParamType)); super(functionName, timeParamType, false, Arrays.asList(timeParamType, durationParamType));
this.timeParamType = timeParamType; this.timeParamType = timeParamType;
...@@ -127,8 +120,7 @@ final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends Dur ...@@ -127,8 +120,7 @@ final class TemporalArithmeticFunction<T extends BaseTimeValue<T>, D extends Dur
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public FirstOrderFunctionCall<T> newCall(final List<Expression<?>> argExpressions, public FirstOrderFunctionCall<T> newCall(final List<Expression<?>> argExpressions, final Datatype<?>... remainingArgTypes) throws IllegalArgumentException
final Datatype<?>... remainingArgTypes) throws IllegalArgumentException
{ {
return new Call<>(functionSignature, timeParamType, durationParamType, op, argExpressions, remainingArgTypes); return new Call<>(functionSignature, timeParamType, durationParamType, op, argExpressions, remainingArgTypes);
} }
......
...@@ -21,6 +21,7 @@ package org.ow2.authzforce.core.pdp.impl.policy; ...@@ -21,6 +21,7 @@ package org.ow2.authzforce.core.pdp.impl.policy;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
...@@ -176,7 +177,7 @@ public final class RootPolicyEvaluators ...@@ -176,7 +177,7 @@ public final class RootPolicyEvaluators
{ {
LOGGER.warn("One of the possible root policies (resolved by the root policy provider module {}) is invalid", rootPolicyProviderMod, e); LOGGER.warn("One of the possible root policies (resolved by the root policy provider module {}) is invalid", rootPolicyProviderMod, e);
// we consider that // we consider that
return new ImmutablePdpDecisionResult(new StatusHelper(StatusHelper.STATUS_PROCESSING_ERROR, e.getMessage()), context); return new ImmutablePdpDecisionResult(new StatusHelper(StatusHelper.STATUS_PROCESSING_ERROR, Optional.ofNullable(e.getMessage())), context);
} }
if (policy == null) if (policy == null)
......
...@@ -26,8 +26,13 @@ import java.util.HashMap; ...@@ -26,8 +26,13 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Attribute;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes;
import org.ow2.authzforce.core.pdp.api.AttributeGUID; import org.ow2.authzforce.core.pdp.api.AttributeGUID;
import org.ow2.authzforce.core.pdp.api.AttributeProvider; import org.ow2.authzforce.core.pdp.api.AttributeProvider;
import org.ow2.authzforce.core.pdp.api.BaseAttributeProviderModule; import org.ow2.authzforce.core.pdp.api.BaseAttributeProviderModule;
...@@ -44,14 +49,9 @@ import org.ow2.authzforce.core.pdp.api.value.Datatype; ...@@ -44,14 +49,9 @@ import org.ow2.authzforce.core.pdp.api.value.Datatype;
import org.ow2.authzforce.core.pdp.api.value.DatatypeFactoryRegistry; import org.ow2.authzforce.core.pdp.api.value.DatatypeFactoryRegistry;
import org.ow2.authzforce.core.xmlns.test.TestAttributeProvider; import org.ow2.authzforce.core.xmlns.test.TestAttributeProvider;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Attribute;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes;
/** /**
* *
* Fake AttributeProviderModule for test purposes only that can be configured to support a specific set of attribute Providers, but always return an empty bag * Fake AttributeProviderModule for test purposes only that can be configured to support a specific set of attribute Providers, but always return an empty bag as attribute value.
* as attribute value.
* *
*/ */
public class TestAttributeProviderModule extends BaseAttributeProviderModule public class TestAttributeProviderModule extends BaseAttributeProviderModule
...@@ -70,7 +70,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule ...@@ -70,7 +70,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule
} }
@Override @Override
public DependencyAwareFactory getInstance(final TestAttributeProvider conf, EnvironmentProperties environmentProperties) public DependencyAwareFactory getInstance(final TestAttributeProvider conf, final EnvironmentProperties environmentProperties)
{ {
return new DependencyAwareFactory() return new DependencyAwareFactory()
{ {
...@@ -83,7 +83,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule ...@@ -83,7 +83,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule
} }
@Override @Override
public CloseableAttributeProviderModule getInstance(DatatypeFactoryRegistry attrDatatypeFactory, AttributeProvider depAttrProvider) public CloseableAttributeProviderModule getInstance(final DatatypeFactoryRegistry attrDatatypeFactory, final AttributeProvider depAttrProvider)
{ {
return new TestAttributeProviderModule(conf, attrDatatypeFactory); return new TestAttributeProviderModule(conf, attrDatatypeFactory);
} }
...@@ -95,7 +95,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule ...@@ -95,7 +95,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule
private final Set<AttributeDesignatorType> supportedDesignatorTypes = new HashSet<>(); private final Set<AttributeDesignatorType> supportedDesignatorTypes = new HashSet<>();
private final Map<AttributeGUID, Bag<?>> attrMap = new HashMap<>(); private final Map<AttributeGUID, Bag<?>> attrMap = new HashMap<>();
private TestAttributeProviderModule(TestAttributeProvider conf, DatatypeFactoryRegistry attrDatatypeFactory) throws IllegalArgumentException private TestAttributeProviderModule(final TestAttributeProvider conf, final DatatypeFactoryRegistry attrDatatypeFactory) throws IllegalArgumentException
{ {
super(conf.getId()); super(conf.getId());
final JaxbXACMLAttributeParser<Bag<?>> xacmlAttributeParser = new NonIssuedLikeIssuedStrictJaxbXACMLAttributeParser(attrDatatypeFactory); final JaxbXACMLAttributeParser<Bag<?>> xacmlAttributeParser = new NonIssuedLikeIssuedStrictJaxbXACMLAttributeParser(attrDatatypeFactory);
...@@ -110,8 +110,8 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule ...@@ -110,8 +110,8 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule
for (final Attribute jaxbAttr : jaxbAttributes.getAttributes()) for (final Attribute jaxbAttr : jaxbAttributes.getAttributes())
{ {
xacmlAttributeParser.parseAttribute(attrMap, new AttributeGUID(categoryName, jaxbAttr.getIssuer(), jaxbAttr.getAttributeId()), xacmlAttributeParser
jaxbAttr.getAttributeValues(), null); .parseAttribute(attrMap, new AttributeGUID(categoryName, Optional.ofNullable(jaxbAttr.getIssuer()), jaxbAttr.getAttributeId()), jaxbAttr.getAttributeValues(), null);
} }
} }
...@@ -119,8 +119,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule ...@@ -119,8 +119,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule
{ {
final AttributeGUID attrKey = attrEntry.getKey(); final AttributeGUID attrKey = attrEntry.getKey();
final Bag<?> attrVals = attrEntry.getValue(); final Bag<?> attrVals = attrEntry.getValue();
supportedDesignatorTypes.add(new AttributeDesignatorType(attrKey.getCategory(), attrKey.getId(), attrVals.getElementDatatype().getId(), attrKey supportedDesignatorTypes.add(new AttributeDesignatorType(attrKey.getCategory(), attrKey.getId(), attrVals.getElementDatatype().getId(), attrKey.getIssuer().orElse(null), false));
.getIssuer(), false));
} }
} }
...@@ -137,8 +136,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule ...@@ -137,8 +136,7 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule
} }
@Override @Override
public <AV extends AttributeValue> Bag<AV> get(AttributeGUID attributeGUID, Datatype<AV> attributeDatatype, EvaluationContext context) public <AV extends AttributeValue> Bag<AV> get(final AttributeGUID attributeGUID, final Datatype<AV> attributeDatatype, final EvaluationContext context) throws IndeterminateEvaluationException
throws IndeterminateEvaluationException
{ {
final Bag<?> attrVals = attrMap.get(attributeGUID); final Bag<?> attrVals = attrMap.get(attributeGUID);
if (attrVals == null) if (attrVals == null)
...@@ -151,8 +149,8 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule ...@@ -151,8 +149,8 @@ public class TestAttributeProviderModule extends BaseAttributeProviderModule
return (Bag<AV>) attrVals; return (Bag<AV>) attrVals;
} }
throw new IndeterminateEvaluationException("Requested datatype (" + attributeDatatype + ") != provided by " + this + " (" throw new IndeterminateEvaluationException("Requested datatype (" + attributeDatatype + ") != provided by " + this + " (" + attrVals.getElementDatatype() + ")",
+ attrVals.getElementDatatype() + ")", StatusHelper.STATUS_MISSING_ATTRIBUTE); StatusHelper.STATUS_MISSING_ATTRIBUTE);