Commit e4d0cf4e authored by cdanger's avatar cdanger

Merge branch 'develop' of https://github.com/authzforce/core-pdp-api.git into develop

parents d9d2180c 9768f639
......@@ -60,7 +60,7 @@ public abstract class BaseStaticRefPolicyProvider implements CloseableStaticRefP
* @throws IndeterminateEvaluationException
* error resolving policy
*/
protected abstract StaticTopLevelPolicyElementEvaluator getPolicy(String policyIdRef, Optional<VersionPatterns> constraints) throws IndeterminateEvaluationException;
protected abstract StaticTopLevelPolicyElementEvaluator getPolicy(String policyIdRef, Optional<PolicyVersionPatterns> constraints) throws IndeterminateEvaluationException;
/**
* Finds a policySet based on an reference. This may involve using the reference as indexing data to lookup a policy.
......@@ -98,11 +98,11 @@ public abstract class BaseStaticRefPolicyProvider implements CloseableStaticRefP
* @throws IndeterminateEvaluationException
* if error determining a matching policy of type {@code policyType}
*/
protected abstract StaticTopLevelPolicyElementEvaluator getPolicySet(String policyIdRef, Optional<VersionPatterns> constraints, Deque<String> policySetRefChainWithPolicyIdRef)
protected abstract StaticTopLevelPolicyElementEvaluator getPolicySet(String policyIdRef, Optional<PolicyVersionPatterns> constraints, Deque<String> policySetRefChainWithPolicyIdRef)
throws IndeterminateEvaluationException;
@Override
public final StaticTopLevelPolicyElementEvaluator get(final TopLevelPolicyElementType refPolicyType, final String policyIdRef, final Optional<VersionPatterns> constraints,
public final StaticTopLevelPolicyElementEvaluator get(final TopLevelPolicyElementType refPolicyType, final String policyIdRef, final Optional<PolicyVersionPatterns> constraints,
final Deque<String> policySetRefChain) throws IndeterminateEvaluationException
{
if (refPolicyType == TopLevelPolicyElementType.POLICY)
......@@ -114,7 +114,7 @@ public abstract class BaseStaticRefPolicyProvider implements CloseableStaticRefP
}
@Override
public final TopLevelPolicyElementEvaluator get(final TopLevelPolicyElementType policyType, final String policyId, final Optional<VersionPatterns> policyVersionConstraints,
public final TopLevelPolicyElementEvaluator get(final TopLevelPolicyElementType policyType, final String policyId, final Optional<PolicyVersionPatterns> policyVersionConstraints,
final Deque<String> policySetRefChain, final EvaluationContext evaluationCtx) throws IllegalArgumentException, IndeterminateEvaluationException
{
return get(policyType, policyId, policyVersionConstraints, policySetRefChain);
......
......@@ -3,28 +3,34 @@
*
* This file is part of AuthzForce CE.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.ow2.authzforce.core.pdp.api.policy;
import java.util.Optional;
/**
* Version patterns used in policy references to match specific policy version(s). This class also provides a simple set of comparison methods for matching against the patterns.
* Version patterns used in policy references to match specific policy
* version(s). This class also provides a simple set of comparison methods for
* matching against the patterns.
*
*/
public class VersionPatterns
public final class PolicyVersionPatterns
{
/**
* Wildcard pattern, i.e. version pattern that matches any version ('*')
*/
public static final PolicyVersionPattern WILDCARD = new PolicyVersionPattern("*");
// the three constraints
private final Optional<PolicyVersionPattern> versionPattern;
......@@ -32,38 +38,49 @@ public class VersionPatterns
private final Optional<PolicyVersionPattern> latestVersionPattern;
/**
* Creates a <code>VersionConstraints</code> with the three optional constraint strings. Each of the three strings must conform to the VersionMatchType type defined in the XACML schema. Any of the
* strings may be null to specify that the given constraint is not used.
* Creates a <code>VersionConstraints</code> with the three optional
* constraint strings. Each of the three strings must conform to the
* VersionMatchType type defined in the XACML schema. Any of the strings may
* be null to specify that the given constraint is not used.
*
* @param versionMatch
* matching expression for the version; or null if none
* @param earliestMatch
* matching expression for the earliest acceptable version; or null if none
* matching expression for the earliest acceptable version; or
* null if none
* @param latestMatch
* matching expression for the earliest acceptable version; or null if none
* matching expression for the earliest acceptable version; or
* null if none
* @throws IllegalArgumentException
* if one of the match expressions is invalid
*/
public VersionPatterns(final String versionMatch, final String earliestMatch, final String latestMatch) throws IllegalArgumentException
public PolicyVersionPatterns(final String versionMatch, final String earliestMatch, final String latestMatch)
throws IllegalArgumentException
{
this.versionPattern = versionMatch == null ? Optional.empty() : Optional.of(new PolicyVersionPattern(versionMatch));
this.earliestVersionPattern = earliestMatch == null ? Optional.empty() : Optional.of(new PolicyVersionPattern(earliestMatch));
this.latestVersionPattern = latestMatch == null ? Optional.empty() : Optional.of(new PolicyVersionPattern(latestMatch));
this.versionPattern = versionMatch == null ? Optional.empty()
: Optional.of(new PolicyVersionPattern(versionMatch));
this.earliestVersionPattern = earliestMatch == null ? Optional.empty()
: Optional.of(new PolicyVersionPattern(earliestMatch));
this.latestVersionPattern = latestMatch == null ? Optional.empty()
: Optional.of(new PolicyVersionPattern(latestMatch));
if (this.versionPattern.isPresent())
{
final PolicyVersion versionLiteral = this.versionPattern.get().toLiteral();
if (versionLiteral != null)
{
if (this.earliestVersionPattern.isPresent() && !this.earliestVersionPattern.get().matches(versionLiteral))
if (this.earliestVersionPattern.isPresent()
&& !this.earliestVersionPattern.get().matches(versionLiteral))
{
throw new IllegalArgumentException("Version (literal) '" + versionPattern.get() + "' and EarliestVersion '" + earliestVersionPattern.get()
+ "' cannot be both matched by the same version.");
throw new IllegalArgumentException(
"Version (literal) '" + versionPattern.get() + "' and EarliestVersion '"
+ earliestVersionPattern.get() + "' cannot be both matched by the same version.");
}
if (this.latestVersionPattern.isPresent() && !this.latestVersionPattern.get().matches(versionLiteral))
{
throw new IllegalArgumentException("Version (literal) '" + versionPattern.get() + "' and LatestVersion '" + latestVersionPattern.get()
+ "' cannot be both matched by the same version.");
throw new IllegalArgumentException(
"Version (literal) '" + versionPattern.get() + "' and LatestVersion '"
+ latestVersionPattern.get() + "' cannot be both matched by the same version.");
}
}
}
......@@ -72,9 +89,11 @@ public class VersionPatterns
{
final PolicyVersion earliestVersionLiteral = this.earliestVersionPattern.get().toLiteral();
final PolicyVersion latestVersionLiteral = this.latestVersionPattern.get().toLiteral();
if (earliestVersionLiteral != null && latestVersionLiteral != null && earliestVersionLiteral.compareTo(latestVersionLiteral) > 0)
if (earliestVersionLiteral != null && latestVersionLiteral != null
&& earliestVersionLiteral.compareTo(latestVersionLiteral) > 0)
{
throw new IllegalArgumentException("EarliestVersion (literal) '" + earliestVersionPattern + "' > LatestVersion (literal) '" + latestVersionPattern + "'!");
throw new IllegalArgumentException("EarliestVersion (literal) '" + earliestVersionPattern
+ "' > LatestVersion (literal) '" + latestVersionPattern + "'!");
}
}
}
......@@ -85,10 +104,9 @@ public class VersionPatterns
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return String.format("Version=%s,EarliestVersion=%s,LatestVersion=%s", (versionPattern == null) ? "*" : versionPattern, (earliestVersionPattern == null) ? "*" : earliestVersionPattern,
(latestVersionPattern == null) ? "*" : latestVersionPattern);
public String toString() {
return String.format("Version=%s,EarliestVersion=%s,LatestVersion=%s", versionPattern.orElse(WILDCARD),
earliestVersionPattern.orElse(WILDCARD), latestVersionPattern.orElse(WILDCARD));
}
/**
......@@ -98,8 +116,7 @@ public class VersionPatterns
* input version to be checked
* @return true iff LatestVersion matched
*/
public boolean matchLatestVersion(final PolicyVersion version)
{
public boolean matchLatestVersion(final PolicyVersion version) {
return !latestVersionPattern.isPresent() || latestVersionPattern.get().isLaterOrMatches(version);
}
......@@ -110,8 +127,7 @@ public class VersionPatterns
* input version to be checked
* @return true iff EarliestVersion matched
*/
public boolean matchEarliestVersion(final PolicyVersion version)
{
public boolean matchEarliestVersion(final PolicyVersion version) {
return !earliestVersionPattern.isPresent() || earliestVersionPattern.get().isEarlierOrMatches(version);
}
......@@ -122,8 +138,7 @@ public class VersionPatterns
* input version to be checked
* @return true iff Version matched
*/
public boolean matchVersion(final PolicyVersion version)
{
public boolean matchVersion(final PolicyVersion version) {
return !versionPattern.isPresent() || versionPattern.get().matches(version);
}
......@@ -132,28 +147,27 @@ public class VersionPatterns
*
* @return Version to be matched; null if none
*/
public Optional<PolicyVersionPattern> getVersionPattern()
{
public Optional<PolicyVersionPattern> getVersionPattern() {
return this.versionPattern;
}
/**
* Get EarliestVersion pattern: matching expression for the earliest acceptable version
* Get EarliestVersion pattern: matching expression for the earliest
* acceptable version
*
* @return EarliestVersion pattern to be matched; null if none
*/
public Optional<PolicyVersionPattern> getEarliestVersionPattern()
{
public Optional<PolicyVersionPattern> getEarliestVersionPattern() {
return this.earliestVersionPattern;
}
/**
* Get LatestVersion pattern: matching expression for the latest acceptable version
* Get LatestVersion pattern: matching expression for the latest acceptable
* version
*
* @return LatestVersion pattern to be matched; null if none
*/
public Optional<PolicyVersionPattern> getLatestVersionPattern()
{
public Optional<PolicyVersionPattern> getLatestVersionPattern() {
return this.latestVersionPattern;
}
......
......@@ -175,7 +175,7 @@ public interface RefPolicyProvider
* @throws IndeterminateEvaluationException
* if error determining a matching policy of type {@code policyType}
*/
TopLevelPolicyElementEvaluator get(TopLevelPolicyElementType policyType, String policyId, Optional<VersionPatterns> policyVersionConstraints, Deque<String> policySetRefChain,
TopLevelPolicyElementEvaluator get(TopLevelPolicyElementType policyType, String policyId, Optional<PolicyVersionPatterns> policyVersionConstraints, Deque<String> policySetRefChain,
EvaluationContext evaluationCtx) throws IllegalArgumentException, IndeterminateEvaluationException;
}
\ No newline at end of file
......@@ -69,11 +69,11 @@ public interface StaticRefPolicyProvider extends RefPolicyProvider
* @throws IndeterminateEvaluationException
* if error determining a matching policy of type {@code policyType}
*/
StaticTopLevelPolicyElementEvaluator get(TopLevelPolicyElementType refPolicyType, String policyIdRef, Optional<VersionPatterns> constraints, Deque<String> policySetRefChain)
StaticTopLevelPolicyElementEvaluator get(TopLevelPolicyElementType refPolicyType, String policyIdRef, Optional<PolicyVersionPatterns> constraints, Deque<String> policySetRefChain)
throws IndeterminateEvaluationException;
@Override
default TopLevelPolicyElementEvaluator get(final TopLevelPolicyElementType policyType, final String policyId, final Optional<VersionPatterns> policyVersionConstraints,
default TopLevelPolicyElementEvaluator get(final TopLevelPolicyElementType policyType, final String policyId, final Optional<PolicyVersionPatterns> policyVersionConstraints,
final Deque<String> policySetRefChain, final EvaluationContext evaluationCtx) throws IllegalArgumentException, IndeterminateEvaluationException
{
return get(policyType, policyId, policyVersionConstraints, policySetRefChain);
......
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