/** * Creates a new <code>PolicyReference</code> instance. This has no * constraints on version matching. Note that an XACML 1.x reference may * not have any constraints. * * @param reference the reference to the policy * @param policyType one of the two fields in this class * @param finder the <code>PolicyFinder</code> used to handle the reference * @param parentMetaData the meta-data associated with the containing * (parent) policy * * @throws IllegalArgumentException if the input policyType isn't valid */ public PolicyReference(URI reference, int policyType, PolicyFinder finder, PolicyMetaData parentMetaData) throws IllegalArgumentException { this(reference, policyType, new VersionConstraints(null, null, null), finder, parentMetaData); }
/** * Checks if the given version string matches the constraint string. * * @param version the version string to check * @param constraint a constraint string to use in matching * * @return true if the version string matches the constraint */ public static boolean matches(String version, String constraint) { return compareHelper(version, constraint, COMPARE_EQUAL); }
/** * Checks if the given version string meets all three constraints. * * @param version the version to compare, which is formatted as a * VersionType XACML type * * @return true if the given version meets all the constraints */ public boolean meetsConstraint(String version) { return (matches(version, this.version) && isEarlier(version, latest) && isLater(version, earliest)); }
/** * Private helper method that encodes the variable constraints info. Note * that if this is a pre-2.0 policy the constraints are always null, so * nothing will be added here. */ private String encodeConstraints() { String str = ""; VersionConstraints version = getConstraints(); String v = version.getVersionConstraint(); if (v != null) str += " Version=\"" + v + "\""; String e = version.getEarliestConstraint(); if (e != null) str += " EarliestVersion=\"" + e + "\""; String l = version.getLatestConstraint(); if (l != null) str += " LatestVersion=\"" + l + "\""; return str; }
if (constraints.meetsConstraint(policy.getVersion()))
if (!constraints.meetsConstraint(policy.getVersion())) return new PolicyFinderResult();
/** * Checks if the given version string is greater-than or equal-to the * constraint string. * * @param version the version string to check * @param constraint a constraint string to use in matching * * @return true if the version string is later than the constraint */ public static boolean isLater(String version, String constraint) { return compareHelper(version, constraint, COMPARE_GREATER); }
new VersionConstraints(versionConstraint, earlyConstraint, lateConstraint);
/** * Checks if the given version string is less-than or equal-to the * constraint string. * * @param version the version string to check * @param constraint a constraint string to use in matching * * @return true if the version string is earlier than the constraint */ public static boolean isEarlier(String version, String constraint) { return compareHelper(version, constraint, COMPARE_LESS); }