/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2013-2014 Manuel Gaupp
* Portions Copyright 2014-2015 ForgeRock AS
*/
/**
* This class defines a filter that may be used in conjunction with the matched
* values control to indicate which particular values of a multivalued attribute
* should be returned. The matched values filter is essentially a subset of an
* LDAP search filter, lacking support for AND, OR, and NOT components, and
* lacking support for the dnAttributes component of extensible matching
* filters.
*/
public class MatchedValuesFilter
{
/** The BER type associated with the equalityMatch filter type. */
/** The BER type associated with the substrings filter type. */
/** The BER type associated with the greaterOrEqual filter type. */
/** The BER type associated with the lessOrEqual filter type. */
/** The BER type associated with the present filter type. */
/** The BER type associated with the approxMatch filter type. */
/** The BER type associated with the extensibleMatch filter type. */
/** The matching rule ID for this matched values filter. */
/** Indicates whether the elements of this matched values filter have been fully decoded. */
private boolean decoded;
/** The match type for this matched values filter. */
private final byte matchType;
/** The raw, unprocessed attribute type for this matched values filter. */
/** The processed attribute type for this matched values filter. */
/** The matching rule for this matched values filter. */
/** The equality matching rule for this matched values filter. */
/** The ordering matching rule for this matched values filter. */
/** The substring matching rule for this matched values filter. */
/** The approximate matching rule for this matched values filter. */
/** The raw, unprocessed assertion value for this matched values filter. */
/** The processed assertion value for this matched values filter. */
/** The assertion created from substring matching rule using values of this filter. */
/** The subInitial value for this matched values filter. */
/** The set of subAny values for this matched values filter. */
/** The subFinal value for this matched values filter. */
/**
* Creates a new matched values filter with the provided information.
*
* @param matchType The match type for this matched values filter.
* @param rawAttributeType The raw, unprocessed attribute type.
* @param rawAssertionValue The raw, unprocessed assertion value.
* @param subInitial The subInitial element.
* @param subAny The set of subAny elements.
* @param subFinal The subFinal element.
* @param matchingRuleID The matching rule ID.
*/
{
this.rawAttributeType = rawAttributeType;
this.rawAssertionValue = rawAssertionValue;
this.subInitial = subInitial;
this.matchingRuleID = matchingRuleID;
}
/**
* Creates a new equalityMatch filter with the provided information.
*
* @param rawAttributeType The raw, unprocessed attribute type.
* @param rawAssertionValue The raw, unprocessed assertion value.
*
* @return The created equalityMatch filter.
*/
{
}
/**
* Creates a new equalityMatch filter with the provided information.
*
* @param attributeType The attribute type.
* @param assertionValue The assertion value.
*
* @return The created equalityMatch filter.
*/
{
return filter;
}
/**
* Creates a new substrings filter with the provided information.
*
* @param rawAttributeType The raw, unprocessed attribute type.
* @param subInitial The subInitial element.
* @param subAny The set of subAny elements.
* @param subFinal The subFinal element.
*
* @return The created substrings filter.
*/
{
}
/**
* Creates a new substrings filter with the provided information.
*
* @param attributeType The raw, unprocessed attribute type.
* @param subInitial The subInitial element.
* @param subAny The set of subAny elements.
* @param subFinal The subFinal element.
*
* @return The created substrings filter.
*/
{
return filter;
}
/**
* Creates a new greaterOrEqual filter with the provided information.
*
* @param rawAttributeType The raw, unprocessed attribute type.
* @param rawAssertionValue The raw, unprocessed assertion value.
*
* @return The created greaterOrEqual filter.
*/
{
}
/**
* Creates a new greaterOrEqual filter with the provided information.
*
* @param attributeType The attribute type.
* @param assertionValue The assertion value.
*
* @return The created greaterOrEqual filter.
*/
{
return filter;
}
/**
* Creates a new lessOrEqual filter with the provided information.
*
* @param rawAttributeType The raw, unprocessed attribute type.
* @param rawAssertionValue The raw, unprocessed assertion value.
*
* @return The created lessOrEqual filter.
*/
{
}
/**
* Creates a new lessOrEqual filter with the provided information.
*
* @param attributeType The attribute type.
* @param assertionValue The assertion value.
*
* @return The created lessOrEqual filter.
*/
{
return filter;
}
/**
* Creates a new present filter with the provided information.
*
* @param rawAttributeType The raw, unprocessed attribute type.
*
* @return The created present filter.
*/
{
}
/**
* Creates a new present filter with the provided information.
*
* @param attributeType The attribute type.
*
* @return The created present filter.
*/
{
return filter;
}
/**
* Creates a new approxMatch filter with the provided information.
*
* @param rawAttributeType The raw, unprocessed attribute type.
* @param rawAssertionValue The raw, unprocessed assertion value.
*
* @return The created approxMatch filter.
*/
{
}
/**
* Creates a new approxMatch filter with the provided information.
*
* @param attributeType The attribute type.
* @param assertionValue The assertion value.
*
* @return The created approxMatch filter.
*/
{
return filter;
}
/**
* Creates a new extensibleMatch filter with the provided information.
*
* @param rawAttributeType The raw, unprocessed attribute type.
* @param matchingRuleID The matching rule ID.
* @param rawAssertionValue The raw, unprocessed assertion value.
*
* @return The created extensibleMatch filter.
*/
{
}
/**
* Creates a new extensibleMatch filter with the provided information.
*
* @param attributeType The attribute type.
* @param matchingRule The matching rule.
* @param assertionValue The assertion value.
*
* @return The created extensibleMatch filter.
*/
{
return filter;
}
/**
* Creates a new matched values filter from the provided LDAP filter.
*
* @param filter The LDAP filter to use for this matched values filter.
*
* @return The corresponding matched values filter.
*
* @throws LDAPException If the provided LDAP filter cannot be treated as a
* matched values filter.
*/
throws LDAPException
{
switch (filter.getFilterType())
{
case AND:
case OR:
case NOT:
// These filter types cannot be used in a matched values filter.
case EQUALITY:
return new MatchedValuesFilter(EQUALITY_MATCH_TYPE,
case SUBSTRING:
return new MatchedValuesFilter(SUBSTRINGS_TYPE,
case GREATER_OR_EQUAL:
return new MatchedValuesFilter(GREATER_OR_EQUAL_TYPE,
case LESS_OR_EQUAL:
return new MatchedValuesFilter(LESS_OR_EQUAL_TYPE,
case PRESENT:
case APPROXIMATE_MATCH:
return new MatchedValuesFilter(APPROXIMATE_MATCH_TYPE,
case EXTENSIBLE_MATCH:
if (filter.getDNAttributes())
{
// This cannot be represented in a matched values filter.
}
else
{
return new MatchedValuesFilter(EXTENSIBLE_MATCH_TYPE,
}
default:
}
}
/**
* Encodes this matched values filter as an ASN.1 element.
*
* @param writer The ASN1Writer to use to encode this matched values filter.
* @throws IOException if an error occurs while encoding.
*/
{
switch (matchType)
{
case EQUALITY_MATCH_TYPE:
case GREATER_OR_EQUAL_TYPE:
case LESS_OR_EQUAL_TYPE:
case APPROXIMATE_MATCH_TYPE:
// These will all be encoded in the same way.
return;
case SUBSTRINGS_TYPE:
if (subInitial != null)
{
}
{
for (ByteString s : subAny)
{
}
}
{
}
return;
case PRESENT_TYPE:
return;
case EXTENSIBLE_MATCH_TYPE:
if (matchingRuleID != null)
{
}
if (rawAttributeType != null)
{
}
return;
default:
}
}
/**
* Decodes the provided ASN.1 element as a matched values filter item.
*
* @param reader The ASN.1 reader.
*
* @return The decoded matched values filter.
*
* @throws LDAPException If a problem occurs while attempting to decode the
* filter item.
*/
throws LDAPException
{
byte type;
try
{
}
catch(Exception e)
{
// TODO: Need a better message.
}
switch (type)
{
case EQUALITY_MATCH_TYPE:
case GREATER_OR_EQUAL_TYPE:
case LESS_OR_EQUAL_TYPE:
case APPROXIMATE_MATCH_TYPE:
// These will all be decoded in the same manner. The element must be a
// sequence consisting of the attribute type and assertion value.
try
{
}
catch (Exception e)
{
logger.traceException(e);
}
case SUBSTRINGS_TYPE:
// This must be a sequence of two elements, where the second is a
// sequence of substring types.
try
{
if(!reader.hasNextElement())
{
}
if(reader.hasNextElement() &&
{
}
while(reader.hasNextElement() &&
{
{
}
}
if(reader.hasNextElement() &&
{
}
}
catch (LDAPException le)
{
throw le;
}
catch (Exception e)
{
logger.traceException(e);
}
case PRESENT_TYPE:
// The element must be an ASN.1 octet string holding the attribute type.
try
{
}
catch (Exception e)
{
logger.traceException(e);
getExceptionMessage(e));
}
case EXTENSIBLE_MATCH_TYPE:
// This must be a two or three element sequence with an assertion value
// the first element(s).
try
{
{
}
if(matchingRuleID == null ||
{
}
}
catch (Exception e)
{
logger.traceException(e);
getExceptionMessage(e));
}
default:
}
}
/**
* Retrieves the match type for this matched values filter.
*
* @return The match type for this matched values filter.
*/
public byte getMatchType()
{
return matchType;
}
/**
* Retrieves the raw, unprocessed attribute type for this matched values
* filter.
*
* @return The raw, unprocessed attribute type for this matched values
* filter, or <CODE>null</CODE> if there is none.
*/
{
return rawAttributeType;
}
/**
* Retrieves the attribute type for this matched values filter.
*
* @return The attribute type for this matched values filter, or
* <CODE>null</CODE> if there is none.
*/
{
{
}
return attributeType;
}
/**
* Retrieves the raw, unprocessed assertion value for this matched values
* filter.
*
* @return The raw, unprocessed assertion value for this matched values
* filter, or <CODE>null</CODE> if there is none.
*/
{
return rawAssertionValue;
}
/**
* Retrieves the assertion value for this matched values filter.
*
* @return The assertion value for this matched values filter, or
* <CODE>null</CODE> if there is none.
*/
{
{
}
return assertionValue;
}
/**
* Retrieves the subInitial element for this matched values filter.
*
* @return The subInitial element for this matched values filter, or
* <CODE>null</CODE> if there is none.
*/
{
return subInitial;
}
if (substringAssertion == null)
{
try
{
{
}
}
catch (DecodeException e)
{
logger.traceException(e);
}
}
return substringAssertion;
}
/**
* Retrieves the set of subAny elements for this matched values filter.
*
* @return The set of subAny elements for this matched values filter. If
* there are none, then the return value may be either
* <CODE>null</CODE> or an empty list.
*/
{
return subAny;
}
/**
* Retrieves the subFinal element for this matched values filter.
*
* @return The subFinal element for this matched values filter, or
* <CODE>null</CODE> if there is none.
*/
{
return subFinal;
}
/**
* Retrieves the matching rule ID for this matched values filter.
*
* @return The matching rule ID for this matched values filter, or
* <CODE>null</CODE> if there is none.
*/
{
return matchingRuleID;
}
/**
* Retrieves the matching rule for this matched values filter.
*
* @return The matching rule for this matched values filter, or
* <CODE>null</CODE> if there is none.
*/
{
{
}
return matchingRule;
}
/**
* Retrieves the approximate matching rule that should be used for this
* matched values filter.
*
* @return The approximate matching rule that should be used for this matched
* values filter, or <CODE>null</CODE> if there is none.
*/
{
if (approximateMatchingRule == null)
{
{
}
}
return approximateMatchingRule;
}
/**
* Retrieves the equality matching rule that should be used for this matched
* values filter.
*
* @return The equality matching rule that should be used for this matched
* values filter, or <CODE>null</CODE> if there is none.
*/
{
if (equalityMatchingRule == null)
{
{
}
}
return equalityMatchingRule;
}
/**
* Retrieves the ordering matching rule that should be used for this matched
* values filter.
*
* @return The ordering matching rule that should be used for this matched
* values filter, or <CODE>null</CODE> if there is none.
*/
{
if (orderingMatchingRule == null)
{
{
}
}
return orderingMatchingRule;
}
/**
* Retrieves the substring matching rule that should be used for this matched
* values filter.
*
* @return The substring matching rule that should be used for this matched
* values filter, or <CODE>null</CODE> if there is none.
*/
{
if (substringMatchingRule == null)
{
{
}
}
return substringMatchingRule;
}
/**
* Decodes all components of the matched values filter so that they can be
* referenced as member variables.
*/
private void fullyDecode()
{
if (! decoded)
{
decoded = true;
}
}
/**
* Indicates whether the specified attribute value matches the criteria
* defined in this matched values filter.
*
* @param type The attribute type with which the provided value is
* associated.
* @param value The attribute value for which to make the determination.
*
* @return <CODE>true</CODE> if the specified attribute value matches the
* criteria defined in this matched values filter, or
* <CODE>false</CODE> if not.
*/
{
fullyDecode();
switch (matchType)
{
case EQUALITY_MATCH_TYPE:
if (attributeType != null
&& rawAssertionValue != null
&& equalityMatchingRule != null)
{
}
return false;
case SUBSTRINGS_TYPE:
if (attributeType != null
&& substringAssertion != null)
{
try
{
return substringAssertion.matches(substringMatchingRule.normalizeAttributeValue(value)).toBoolean();
}
catch (Exception e)
{
logger.traceException(e);
}
}
return false;
case GREATER_OR_EQUAL_TYPE:
if (attributeType != null
&& assertionValue != null
&& orderingMatchingRule != null)
{
try
{
}
catch (DecodeException e)
{
logger.traceException(e);
}
}
return false;
case LESS_OR_EQUAL_TYPE:
if (attributeType != null
&& assertionValue != null
&& orderingMatchingRule != null)
{
try
{
}
catch (DecodeException e)
{
logger.traceException(e);
}
}
return false;
case PRESENT_TYPE:
case APPROXIMATE_MATCH_TYPE:
if (attributeType != null
&& assertionValue != null
&& approximateMatchingRule != null)
{
}
return false;
case EXTENSIBLE_MATCH_TYPE:
if (attributeType == null)
{
}
{
return false;
}
default:
return false;
}
}
{
{
return false;
}
try
{
}
catch (DecodeException e)
{
logger.traceException(e);
return false;
}
}
/**
* Retrieves a string representation of this matched values filter, as an RFC
* 2254-compliant filter string.
*
* @return A string representation of this matched values filter.
*/
{
}
/**
* Appends a string representation of this matched values filter, as an RFC
* 2254-compliant filter string, to the provided buffer.
*
* @param buffer The buffer to which the filter string should be appended.
*/
{
switch (matchType)
{
case EQUALITY_MATCH_TYPE:
break;
case SUBSTRINGS_TYPE:
if (subInitial != null)
{
}
{
for (ByteString s : subAny)
{
}
}
{
}
break;
case GREATER_OR_EQUAL_TYPE:
break;
case LESS_OR_EQUAL_TYPE:
break;
case PRESENT_TYPE:
break;
case APPROXIMATE_MATCH_TYPE:
break;
case EXTENSIBLE_MATCH_TYPE:
if (rawAttributeType != null)
{
}
if (matchingRuleID != null)
{
}
break;
}
}
{
}
}