Commit c00bee7a authored by cdanger's avatar cdanger

- Fixed issues reported by Codacy

- Removed PortRange class already in dependency core-pdp-api
parent 05702e49
......@@ -43,7 +43,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${artifactId.prefix}-core-pdp-api</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</dependency>
<!-- /Authzforce dependencies -->
......
......@@ -29,8 +29,8 @@ import java.util.List;
import org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException;
import org.ow2.authzforce.core.pdp.api.expression.Expression;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.value.BooleanValue;
import org.ow2.authzforce.core.pdp.api.value.Datatype;
import org.ow2.authzforce.core.pdp.api.value.StandardDatatypes;
......@@ -44,7 +44,7 @@ import org.ow2.authzforce.core.pdp.api.value.StandardDatatypes;
* @author Seth Proctor
* @version $Id: $
*/
public final class NotFunction extends FirstOrderFunction.SingleParameterTyped<BooleanValue, BooleanValue>
public final class NotFunction extends SingleParameterTypedFirstOrderFunction<BooleanValue, BooleanValue>
{
/**
......
/**
*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistribution in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED
* WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS
* SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility.
*/
package com.sun.xacml;
import java.util.Objects;
/**
* This class represents a port range as specified in the <code>dnsName</code> and <code>ipAddress</code> datatypes. The range may have upper and lower bounds, be specified by a single port number, or
* may be unbound.
*
* @version $Id: $
*/
public final class PortRange
{
/**
* Constant used to specify that the range is unbound on one side.
*/
private static final int UNBOUND = -1;
// the port bound values
private final int lowerBound;
private final int upperBound;
/**
* Default constructor used to represent an unbound range. This is typically used when an address has no port information.
*/
public PortRange()
{
this(UNBOUND, UNBOUND);
}
/**
* Creates a <code>PortRange</code> with upper and lower bounds. Either of the parameters may have the value <code>UNBOUND</code> meaning that there is no bound at the respective end.
*
* @param lowerBound
* the lower-bound port number or <code>UNBOUND</code>
* @param upperBound
* the upper-bound port number or <code>UNBOUND</code>
*/
private PortRange(int lowerBound, int upperBound)
{
this.lowerBound = lowerBound;
this.upperBound = upperBound;
}
/**
* Creates an instance of <code>PortRange</code> based on the given value.
*
* @param value
* a <code>String</code> representing the range
* @return a new <code>PortRange</code>
* @throws java.lang.NumberFormatException
* if a port value isn't an integer
*/
public static PortRange getInstance(String value)
{
int lowerBound = UNBOUND;
int upperBound = UNBOUND;
// first off, make sure there's actually content here
if (value.length() == 0 || value.equals("-"))
{
return new PortRange();
}
// there's content, so figure where the '-' is, if at all
int dashPos = value.indexOf('-');
if (dashPos == -1)
{
// there's no dash, so it's just a single number
lowerBound = upperBound = Integer.parseInt(value);
} else if (dashPos == 0)
{
// it starts with a dash, so it's just upper-range bound
upperBound = Integer.parseInt(value.substring(1));
} else
{
// it's a number followed by a dash, so get the lower-bound...
lowerBound = Integer.parseInt(value.substring(0, dashPos));
int len = value.length();
// ... and see if there is a second port number
if (dashPos != len - 1)
{
// the dash wasn't at the end, so there's an upper-bound
upperBound = Integer.parseInt(value.substring(dashPos + 1, len));
}
}
return new PortRange(lowerBound, upperBound);
}
/**
* Returns the lower-bound port value. If the range is not lower-bound, then this returns <code>UNBOUND</code>. If the range is actually a single port number, then this returns the same value as
* <code>getUpperBound</code>.
*
* @return the upper-bound
*/
public int getLowerBound()
{
return lowerBound;
}
/**
* Returns the upper-bound port value. If the range is not upper-bound, then this returns <code>UNBOUND</code>. If the range is actually a single port number, then this returns the same value as
* <code>getLowerBound</code>.
*
* @return the upper-bound
*/
public int getUpperBound()
{
return upperBound;
}
/**
* Returns whether the range is bounded by a lower port number.
*
* @return true if lower-bounded, false otherwise
*/
public boolean isLowerBounded()
{
return lowerBound != UNBOUND;
}
/**
* Returns whether the range is bounded by an upper port number.
*
* @return true if upper-bounded, false otherwise
*/
public boolean isUpperBounded()
{
return upperBound != UNBOUND;
}
/**
* Returns whether the range is actually a single port number.
*
* @return true if the range is a single port number, false otherwise
*/
public boolean isSinglePort()
{
return lowerBound == upperBound && lowerBound != UNBOUND;
}
/**
* Returns whether the range is unbound, which means that it specifies no port number or range. This is typically used with addresses that include no port information.
*
* @return true if the range is unbound, false otherwise
*/
public boolean isUnbound()
{
return lowerBound == UNBOUND && upperBound == UNBOUND;
}
private transient volatile int hashCode = 0; // Effective Java - Item 9
/** {@inheritDoc} */
@Override
public int hashCode()
{
if (hashCode == 0)
{
hashCode = Objects.hash(lowerBound, upperBound);
}
return hashCode;
}
/**
* {@inheritDoc}
*
* Returns true if the input is an instance of this class and if its value equals the value contained in this class.
*/
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof PortRange))
{
return false;
}
final PortRange other = (PortRange) o;
return lowerBound == other.lowerBound && upperBound == other.upperBound;
}
/**
* <p>
* encode
* </p>
*
* @return encoded port range
*/
public String encode()
{
if (isUnbound())
return "";
if (isSinglePort())
return Integer.toString(lowerBound, 10);
if (!isLowerBounded())
return "-" + Integer.toString(upperBound, 10);
if (!isUpperBounded())
return Integer.toString(lowerBound, 10) + "-";
return Integer.toString(lowerBound, 10) + "-" + Integer.toString(upperBound, 10);
}
}
......@@ -31,11 +31,11 @@ import java.util.Locale;
import org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException;
import org.ow2.authzforce.core.pdp.api.expression.Expression;
import org.ow2.authzforce.core.pdp.api.func.BaseFunctionSet;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
import org.ow2.authzforce.core.pdp.api.func.FunctionSet;
import org.ow2.authzforce.core.pdp.api.func.FunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunctionSignature;
import org.ow2.authzforce.core.pdp.api.value.Datatype;
import org.ow2.authzforce.core.pdp.api.value.StandardDatatypes;
import org.ow2.authzforce.core.pdp.api.value.StringValue;
......@@ -48,7 +48,7 @@ import org.ow2.authzforce.core.pdp.api.value.StringValue;
* @author Seth Proctor
* @version $Id: $
*/
public final class StringNormalizeFunction extends FirstOrderFunction.SingleParameterTyped<StringValue, StringValue>
public final class StringNormalizeFunction extends SingleParameterTypedFirstOrderFunction<StringValue, StringValue>
{
/**
......@@ -70,9 +70,9 @@ public final class StringNormalizeFunction extends FirstOrderFunction.SinglePara
{
private final StringNormalizer strNormalizer;
private final FunctionSignature.SingleParameterTyped<StringValue, StringValue> funcSig;
private final SingleParameterTypedFirstOrderFunctionSignature<StringValue, StringValue> funcSig;
public CallFactory(FunctionSignature.SingleParameterTyped<StringValue, StringValue> functionSignature, StringNormalizer stringNormalizer)
public CallFactory(SingleParameterTypedFirstOrderFunctionSignature<StringValue, StringValue> functionSignature, StringNormalizer stringNormalizer)
{
this.funcSig = functionSignature;
this.strNormalizer = stringNormalizer;
......
......@@ -31,9 +31,9 @@ import java.util.TimeZone;
import org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException;
import org.ow2.authzforce.core.pdp.api.expression.Expression;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall;
import org.ow2.authzforce.core.pdp.api.func.FunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunctionSignature;
import org.ow2.authzforce.core.pdp.api.value.BooleanValue;
import org.ow2.authzforce.core.pdp.api.value.Datatype;
import org.ow2.authzforce.core.pdp.api.value.StandardDatatypes;
......@@ -50,7 +50,7 @@ import org.ow2.authzforce.core.pdp.api.value.TimeValue;
* @author seth proctor
* @version $Id: $
*/
public final class TimeInRangeFunction extends FirstOrderFunction.SingleParameterTyped<BooleanValue, TimeValue>
public final class TimeInRangeFunction extends SingleParameterTypedFirstOrderFunction<BooleanValue, TimeValue>
{
/**
......@@ -180,7 +180,7 @@ public final class TimeInRangeFunction extends FirstOrderFunction.SingleParamete
return !calCheckedWhetherInRange.after(endCal);
}
private Call(FunctionSignature.SingleParameterTyped<BooleanValue, TimeValue> functionSignature, List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes)
private Call(SingleParameterTypedFirstOrderFunctionSignature<BooleanValue, TimeValue> functionSignature, List<Expression<?>> argExpressions, Datatype<?>... remainingArgTypes)
{
super(functionSignature, argExpressions, remainingArgTypes);
}
......
......@@ -228,18 +228,8 @@ public final class BaseDecisionResult implements DecisionResult
// this.getObligations() derived from this.pepActions
// pepActions never null
if (!this.pepActions.equals(other.getPepActions()))
{
return false;
}
// applicablePolicyIdList never null
if (!this.applicablePolicyIdList.equals(other.getApplicablePolicyIdList()))
{
return false;
}
return true;
return this.pepActions.equals(other.getPepActions()) && this.applicablePolicyIdList.equals(other.getApplicablePolicyIdList());
}
/**
......
......@@ -143,7 +143,8 @@ public class SchemaHandler
*/
private static class OASISCatalogManager
{
private static final IllegalArgumentException ERROR_CREATING_CATALOG_RESOLVER_EXCEPTION = new IllegalArgumentException("Error creating org.apache.xml.resolver.tools.CatalogResolver for OASIS CatalogManager");
private static final IllegalArgumentException ERROR_CREATING_CATALOG_RESOLVER_EXCEPTION = new IllegalArgumentException(
"Error creating org.apache.xml.resolver.tools.CatalogResolver for OASIS CatalogManager");
private final static Logger _LOGGER = LoggerFactory.getLogger(OASISCatalogManager.class);
......@@ -430,13 +431,6 @@ public class SchemaHandler
private Schema schema;
private String catalogLocation;
/**
* Default empty constructor, needed for instantiation by Spring framework
*/
public SchemaHandler()
{
}
/**
* Sets (Spring-supported) locations to XML schema files
*
......
......@@ -158,8 +158,9 @@ public final class DenyOverridesAlg extends BaseCombiningAlg<Decidable>
/**
* The standard URIs used to identify this algorithm
*/
static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:deny-overrides", "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides",
"urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:ordered-deny-overrides", "urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:ordered-deny-overrides" };
private static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:deny-overrides",
"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides", "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:ordered-deny-overrides",
"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:ordered-deny-overrides" };
/**
* Supported algorithms
......
......@@ -73,7 +73,7 @@ public final class DenyUnlessPermitAlg extends BaseCombiningAlg<Decidable>
}
break;
default:
continue;
break;
}
}
......@@ -93,7 +93,7 @@ public final class DenyUnlessPermitAlg extends BaseCombiningAlg<Decidable>
/**
* The standard URIs used to identify this algorithm; first one is for policy combinging, second one for rule combining.
*/
static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:deny-unless-permit",
private static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:deny-unless-permit",
"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-unless-permit" };
/**
......
......@@ -83,7 +83,7 @@ public final class FirstApplicableAlg extends BaseCombiningAlg<Decidable>
/**
* The standard URIs used to identify this algorithm
*/
static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:first-applicable",
private static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:first-applicable",
"urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:first-applicable" };
/**
......
......@@ -41,8 +41,9 @@ public final class LegacyDenyOverridesAlg extends BaseCombiningAlg<Decidable>
/**
* The standard URIs used to identify this algorithm
*/
static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:deny-overrides", "urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:deny-overrides",
"urn:oasis:names:tc:xacml:1.1:policy-combining-algorithm:ordered-deny-overrides", "urn:oasis:names:tc:xacml:1.1:rule-combining-algorithm:ordered-deny-overrides" };
private static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:deny-overrides",
"urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:deny-overrides", "urn:oasis:names:tc:xacml:1.1:policy-combining-algorithm:ordered-deny-overrides",
"urn:oasis:names:tc:xacml:1.1:rule-combining-algorithm:ordered-deny-overrides" };
/**
* Supported algorithms
......
......@@ -41,7 +41,7 @@ public final class LegacyPermitOverridesAlg extends BaseCombiningAlg<Decidable>
/**
* The standard URIs used to identify this algorithm
*/
static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:permit-overrides",
private static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:1.0:policy-combining-algorithm:permit-overrides",
"urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-overrides", "urn:oasis:names:tc:xacml:1.1:policy-combining-algorithm:ordered-permit-overrides",
"urn:oasis:names:tc:xacml:1.1:rule-combining-algorithm:ordered-permit-overrides" };
......
......@@ -169,7 +169,7 @@ public final class PermitOverridesAlg extends BaseCombiningAlg<Decidable>
/**
* The standard URN used to identify this algorithm
*/
static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-overrides",
private static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-overrides",
"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides", "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:ordered-permit-overrides",
"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:ordered-permit-overrides" };
......
......@@ -75,7 +75,7 @@ public final class PermitUnlessDenyAlg extends BaseCombiningAlg<Decidable>
}
break;
default:
continue;
break;
}
}
......@@ -94,7 +94,7 @@ public final class PermitUnlessDenyAlg extends BaseCombiningAlg<Decidable>
/**
* The standard URN used to identify this algorithm
*/
static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-unless-deny",
private static final String[] SUPPORTED_IDENTIFIERS = { "urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-unless-deny",
"urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny" };
/**
......
......@@ -164,21 +164,15 @@ public class AttributeSelectorExpression<AV extends AttributeValue> extends Attr
return new AttributeValueType(content, attrDatatype, otherAttributes);
}
private final transient AttributeSelectorId id;
private final transient Datatype<AV> attributeType;
private final transient String missingAttributeMessage;
private final transient AttributeProvider attrProvider;
private final transient AttributeGUID contextSelectorGUID;
private final transient XPathCompiler xpathCompiler;
private final transient XMLUtils.XPathEvaluator xpathEvaluator;
private final transient DatatypeFactory<?> attrFactory;
private final AttributeSelectorId id;
private final transient BagDatatype<AV> returnType;
private final transient IndeterminateEvaluationException missingAttributeForUnknownReasonException;
private final transient IndeterminateEvaluationException missingAttributeBecauseNullContextException;
private final transient IndeterminateEvaluationException missingAttributesContentException;
......@@ -188,7 +182,6 @@ public class AttributeSelectorExpression<AV extends AttributeValue> extends Attr
// cached method results
private transient volatile String toString = null;
private transient volatile int hashCode = 0;
private final Datatype<AV> attributeType;
/*
* (non-Javadoc)
......
......@@ -26,9 +26,10 @@ import org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException;
import org.ow2.authzforce.core.pdp.api.StatusHelper;
import org.ow2.authzforce.core.pdp.api.expression.Expression;
import org.ow2.authzforce.core.pdp.api.expression.Expressions;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall;
import org.ow2.authzforce.core.pdp.api.func.FunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunctionSignature;
import org.ow2.authzforce.core.pdp.api.value.AttributeValue;
import org.ow2.authzforce.core.pdp.api.value.BooleanValue;
import org.ow2.authzforce.core.pdp.api.value.Datatype;
......@@ -44,17 +45,15 @@ import org.ow2.authzforce.core.pdp.api.value.StandardDatatypes;
*
* @version $Id: $
*/
public final class LogicalAndFunction extends FirstOrderFunction.SingleParameterTyped<BooleanValue, BooleanValue>
public final class LogicalAndFunction extends SingleParameterTypedFirstOrderFunction<BooleanValue, BooleanValue>
{
/**
* XACML standard identifier for the "and" logical function
*/
public static final String NAME_AND = XACML_NS_1_0 + "and";
/**
* Singleton instance of "and" logical function
*/
public static final LogicalAndFunction INSTANCE = new LogicalAndFunction();
private static final String INVALID_ARG_TYPE_MESSAGE_PREFIX = "Function " + NAME_AND + ": Invalid type (expected = " + StandardDatatypes.BOOLEAN_FACTORY.getDatatype() + ") of arg#";
private static final String INDETERMINATE_ARG_MESSAGE_PREFIX = "Function " + NAME_AND + ": Indeterminate arg #";
private static final class CallFactory
{
......@@ -74,7 +73,7 @@ public final class LogicalAndFunction extends FirstOrderFunction.SingleParameter
{
private final List<Expression<?>> checkedArgExpressions;
private Call(FunctionSignature<BooleanValue> functionSig, List<Expression<?>> argExpressions, Datatype<?>[] remainingArgTypes) throws IllegalArgumentException
private Call(FirstOrderFunctionSignature<BooleanValue> functionSig, List<Expression<?>> argExpressions, Datatype<?>[] remainingArgTypes) throws IllegalArgumentException
{
super(functionSig, argExpressions, remainingArgTypes);
this.checkedArgExpressions = argExpressions;
......@@ -142,12 +141,9 @@ public final class LogicalAndFunction extends FirstOrderFunction.SingleParameter
}
}
private static final String INVALID_ARG_TYPE_MESSAGE_PREFIX = "Function " + NAME_AND + ": Invalid type (expected = " + StandardDatatypes.BOOLEAN_FACTORY.getDatatype() + ") of arg#";
private static final String INDETERMINATE_ARG_MESSAGE_PREFIX = "Function " + NAME_AND + ": Indeterminate arg #";
private final FunctionSignature.SingleParameterTyped<BooleanValue, BooleanValue> funcSig;
private final SingleParameterTypedFirstOrderFunctionSignature<BooleanValue, BooleanValue> funcSig;
private CallFactory(FunctionSignature.SingleParameterTyped<BooleanValue, BooleanValue> functionSignature)
private CallFactory(SingleParameterTypedFirstOrderFunctionSignature<BooleanValue, BooleanValue> functionSignature)
{
this.funcSig = functionSignature;
}
......@@ -167,6 +163,11 @@ public final class LogicalAndFunction extends FirstOrderFunction.SingleParameter
this.funcCallFactory = new CallFactory(this.functionSignature);
}
/**
* Singleton instance of "and" logical function
*/
public static final LogicalAndFunction INSTANCE = new LogicalAndFunction();
/*
* (non-Javadoc)
*
......
......@@ -27,9 +27,9 @@ import org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException;
import org.ow2.authzforce.core.pdp.api.StatusHelper;
import org.ow2.authzforce.core.pdp.api.expression.Expression;
import org.ow2.authzforce.core.pdp.api.expression.Expressions;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall;
import org.ow2.authzforce.core.pdp.api.func.FunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.MultiParameterTypedFirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.value.AttributeValue;
import org.ow2.authzforce.core.pdp.api.value.BooleanValue;
import org.ow2.authzforce.core.pdp.api.value.Datatype;
......@@ -50,7 +50,7 @@ import org.ow2.authzforce.core.pdp.api.value.StandardDatatypes;
*
* @version $Id: $
*/
public final class LogicalNOfFunction extends FirstOrderFunction.MultiParameterTyped<BooleanValue>
public final class LogicalNOfFunction extends MultiParameterTypedFirstOrderFunction<BooleanValue>
{
private static final class Call extends FirstOrderFunctionCall<BooleanValue>
......@@ -63,7 +63,7 @@ public final class LogicalNOfFunction extends FirstOrderFunction.MultiParameterT
+ ": evaluation failed because of indeterminate arg", StatusHelper.STATUS_PROCESSING_ERROR);
private final List<Expression<?>> checkedArgExpressions;
private Call(FunctionSignature<BooleanValue> functionSig, List<Expression<?>> checkedArgExpressions, Datatype<?>[] remainingArgTypes) throws IllegalArgumentException
private Call(FirstOrderFunctionSignature<BooleanValue> functionSig, List<Expression<?>> checkedArgExpressions, Datatype<?>[] remainingArgTypes) throws IllegalArgumentException
{
super(functionSig, checkedArgExpressions, remainingArgTypes);
this.checkedArgExpressions = checkedArgExpressions;
......
......@@ -26,9 +26,9 @@ import org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException;
import org.ow2.authzforce.core.pdp.api.StatusHelper;
import org.ow2.authzforce.core.pdp.api.expression.Expression;
import org.ow2.authzforce.core.pdp.api.expression.Expressions;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall;
import org.ow2.authzforce.core.pdp.api.func.FunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.value.AttributeValue;
import org.ow2.authzforce.core.pdp.api.value.BooleanValue;
import org.ow2.authzforce.core.pdp.api.value.Datatype;
......@@ -37,25 +37,23 @@ import org.ow2.authzforce.core.pdp.api.value.StandardDatatypes;
/**
* A class that implements the logical functions "or" and "and".
* <p>
* From XACML core specification of function 'urn:oasis:names:tc:xacml:1.0:function:or': This function SHALL return "False" if it has no arguments and SHALL
* return "True" if at least one of its arguments evaluates to "True". The order of evaluation SHALL be from first argument to last. The evaluation SHALL stop
* with a result of "True" if any argument evaluates to "True", leaving the rest of the arguments unevaluated.
* From XACML core specification of function 'urn:oasis:names:tc:xacml:1.0:function:or': This function SHALL return "False" if it has no arguments and SHALL return "True" if at least one of its
* arguments evaluates to "True". The order of evaluation SHALL be from first argument to last. The evaluation SHALL stop with a result of "True" if any argument evaluates to "True", leaving the rest
* of the arguments unevaluated.
*
*
* @version $Id: $
*/
public final class LogicalOrFunction extends FirstOrderFunction.SingleParameterTyped<BooleanValue, BooleanValue>
public final class LogicalOrFunction extends SingleParameterTypedFirstOrderFunction<BooleanValue, BooleanValue>
{
private static final class Call extends FirstOrderFunctionCall<BooleanValue>
{
private static final String INDETERMINATE_ARG_MESSAGE_PREFIX = "Function " + NAME_OR + ": Indeterminate arg #";
private static final String INVALID_ARG_TYPE_MESSAGE_PREFIX = "Function " + NAME_OR + ": Invalid type (expected = " + StandardDatatypes.BOOLEAN_FACTORY.getDatatype()
+ ") of arg#";
private static final String INVALID_ARG_TYPE_MESSAGE_PREFIX = "Function " + NAME_OR + ": Invalid type (expected = " + StandardDatatypes.BOOLEAN_FACTORY.getDatatype() + ") of arg#";
private final List<Expression<?>> checkedArgExpressions;
private Call(FunctionSignature<BooleanValue> functionSig, List<Expression<?>> argExpressions, Datatype<?>[] remainingArgTypes)
throws IllegalArgumentException
private Call(FirstOrderFunctionSignature<BooleanValue> functionSig, List<Expression<?>> argExpressions, Datatype<?>[] remainingArgTypes) throws IllegalArgumentException
{
super(functionSig, argExpressions, remainingArgTypes);
this.checkedArgExpressions = argExpressions;
......@@ -70,11 +68,10 @@ public final class LogicalOrFunction extends FirstOrderFunction.SingleParameterT
* <li>If any argument expression is constant BooleanAttributeValue True, return always true.</li>
* <li>Else If all argument expressions are constant BooleanAttributeValue False, return always false.</li>
* <li>
* Else If any argument expression is constant BooleanAttributeValue False, remove it from the arguments, as it has no effect on the final result.
* Indeed, or function is commutative and or(false, x, y...) = or(x, y...).</li>
* Else If any argument expression is constant BooleanAttributeValue False, remove it from the arguments, as it has no effect on the final result. Indeed, or function is commutative and
* or(false, x, y...) = or(x, y...).</li>
* </ol>
* The first two optimizations can be achieved by pre-evaluating the function call with context = null and check the result if no
* IndeterminateEvaluationException is thrown.
* The first two optimizations can be achieved by pre-evaluating the function call with context = null and check the result if no IndeterminateEvaluationException is thrown.
*/
IndeterminateEvaluationException indeterminateException = null;
......@@ -94,8 +91,7 @@ public final class LogicalOrFunction extends FirstOrderFunction.SingleParameterT
{
// save the indeterminate to throw later only if there was not any TRUE in remaining
// args
indeterminateException = new IndeterminateEvaluationException(INDETERMINATE_ARG_MESSAGE_PREFIX + argIndex,
StatusHelper.STATUS_PROCESSING_ERROR, e);
indeterminateException = new IndeterminateEvaluationException(INDETERMINATE_ARG_MESSAGE_PREFIX + argIndex, StatusHelper.STATUS_PROCESSING_ERROR, e);
}
argIndex++;
......@@ -114,8 +110,7 @@ public final class LogicalOrFunction extends FirstOrderFunction.SingleParameterT
attrVal = BooleanValue.class.cast(arg);
} catch (ClassCastException e)
{
throw new IndeterminateEvaluationException(INVALID_ARG_TYPE_MESSAGE_PREFIX + argIndex + ": " + arg.getClass().getName(),
StatusHelper.STATUS_PROCESSING_ERROR, e);
throw new IndeterminateEvaluationException(INVALID_ARG_TYPE_MESSAGE_PREFIX + argIndex + ": " + arg.getClass().getName(), StatusHelper.STATUS_PROCESSING_ERROR, e);
}
if (attrVal.getUnderlyingValue())
......
......@@ -26,11 +26,11 @@ import org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException;
import org.ow2.authzforce.core.pdp.api.StatusHelper;
import org.ow2.authzforce.core.pdp.api.expression.Expression;
import org.ow2.authzforce.core.pdp.api.func.BaseFunctionSet;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall;
import org.ow2.authzforce.core.pdp.api.func.FirstOrderFunctionCall.EagerSinglePrimitiveTypeEval;
import org.ow2.authzforce.core.pdp.api.func.FunctionSet;
import org.ow2.authzforce.core.pdp.api.func.FunctionSignature;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunction;
import org.ow2.authzforce.core.pdp.api.func.SingleParameterTypedFirstOrderFunctionSignature;
import org.ow2.authzforce.core.pdp.api.value.Datatype;
import org.ow2.authzforce.core.pdp.api.value.DoubleValue;
import org.ow2.authzforce.core.pdp.api.value.IntegerValue;
......@@ -46,7 +46,7 @@ import org.ow2.authzforce.core.pdp.api.value.Value;
*
* @version $Id: $
*/