throw new DirectoryException(ResultCode.PROTOCOL_ERROR,
message);
}
MatchingRule matchingRule = null;
if (matchingRuleID != null)
{
matchingRule =
DirectoryServer.getMatchingRule(
toLowerCase(matchingRuleID));
if (matchingRule == null)
{
if (debugEnabled())
{
TRACER.debugInfo(
"Unknown matching rule %s defined in extensibleMatch " +
"component of filter %s -- returning undefined.",
matchingRuleID, this);
}
return ConditionResult.UNDEFINED;
}
}
else
{
if (attributeType == null)
{
Message message =
ERR_SEARCH_FILTER_EXTENSIBLE_MATCH_NO_RULE_OR_TYPE.
get(String.valueOf(entry.getDN()),
String.valueOf(completeFilter));
throw new DirectoryException(ResultCode.PROTOCOL_ERROR,
message);
}
else
{
matchingRule = attributeType.getEqualityMatchingRule();
if (matchingRule == null)
{
if (debugEnabled())
{
TRACER.debugInfo(
"Attribute type %s does not have an equality matching " +
"rule -- returning undefined.",
attributeType.getNameOrOID());
}
return ConditionResult.UNDEFINED;
}
}
}
// If there is an attribute type, then check to see if there is a
// corresponding matching rule use for the matching rule and
// determine if it allows that attribute type.
if (attributeType != null)
{
MatchingRuleUse mru =
DirectoryServer.getMatchingRuleUse(matchingRule);
if (mru != null)
{
if (! mru.appliesToAttribute(attributeType))
{
if (debugEnabled())
{
TRACER.debugInfo(
"Attribute type %s is not allowed for use with " +
"matching rule %s because of matching rule use " +
"definition %s", attributeType.getNameOrOID(),
matchingRule.getNameOrOID(), mru.getName());
}
return ConditionResult.UNDEFINED;
}
}
}
// Normalize the assertion value using the matching rule.
ByteString normalizedValue;
try
{
normalizedValue =
matchingRule.
normalizeAssertionValue(assertionValue.getValue());
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
// We can't normalize the assertion value, so the result must be
// undefined.
return ConditionResult.UNDEFINED;
}
// If there is an attribute type, then we should only check for
// that attribute. Otherwise, we should check against all
// attributes in the entry.
ConditionResult result = ConditionResult.FALSE;
if (attributeType == null)
{
for (List<Attribute> attrList :
entry.getUserAttributes().values())
{
for (Attribute a : attrList)
{
for (AttributeValue v : a)
{
try
{
ByteString nv =
matchingRule.normalizeValue(v.getValue());
ConditionResult r =
matchingRule.valuesMatch(nv, normalizedValue);
switch (r)
{
case TRUE:
return ConditionResult.TRUE;
case FALSE:
break;
case UNDEFINED:
result = ConditionResult.UNDEFINED;
break;
default:
Message message =
ERR_SEARCH_FILTER_INVALID_RESULT_TYPE.
get(String.valueOf(entry.getDN()),
String.valueOf(completeFilter),
String.valueOf(r));
throw new DirectoryException(
ResultCode.PROTOCOL_ERROR, message);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
// We couldn't normalize one of the values. If we don't
// find a definite match, then we should return
// undefined.
result = ConditionResult.UNDEFINED;
}
}
}
}
for (List<Attribute> attrList :
entry.getOperationalAttributes().values())
{
for (Attribute a : attrList)
{
for (AttributeValue v : a)
{
try
{
ByteString nv =
matchingRule.normalizeValue(v.getValue());
ConditionResult r =
matchingRule.valuesMatch(nv, normalizedValue);
switch (r)
{
case TRUE:
return ConditionResult.TRUE;
case FALSE:
break;
case UNDEFINED:
result = ConditionResult.UNDEFINED;
break;
default:
Message message =
ERR_SEARCH_FILTER_INVALID_RESULT_TYPE.
get(String.valueOf(entry.getDN()),
String.valueOf(completeFilter),
String.valueOf(r));
throw new DirectoryException(
ResultCode.PROTOCOL_ERROR, message);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
// We couldn't normalize one of the values. If we don't
// find a definite match, then we should return
// undefined.
result = ConditionResult.UNDEFINED;
}
}
}
}
Attribute a = entry.getObjectClassAttribute();
for (AttributeValue v : a)
{
try
{
ByteString nv = matchingRule.normalizeValue(v.getValue());
ConditionResult r =
matchingRule.valuesMatch(nv, normalizedValue);
switch (r)
{
case TRUE:
return ConditionResult.TRUE;
case FALSE:
break;
case UNDEFINED:
result = ConditionResult.UNDEFINED;
break;
default:
Message message = ERR_SEARCH_FILTER_INVALID_RESULT_TYPE.
get(String.valueOf(entry.getDN()),
String.valueOf(completeFilter),
String.valueOf(r));
throw new DirectoryException(ResultCode.PROTOCOL_ERROR,
message);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
// We couldn't normalize one of the values. If we don't
// find a definite match, then we should return undefined.
result = ConditionResult.UNDEFINED;
}
}
}
else
{
List<Attribute> attrList = entry.getAttribute(attributeType,
attributeOptions);
if (attrList != null)
{
for (Attribute a : attrList)
{
for (AttributeValue v : a)
{
try
{
ByteString nv =
matchingRule.normalizeValue(v.getValue());
ConditionResult r =
matchingRule.valuesMatch(nv, normalizedValue);
switch (r)
{
case TRUE:
return ConditionResult.TRUE;
case FALSE:
break;
case UNDEFINED:
result = ConditionResult.UNDEFINED;
break;
default:
Message message =
ERR_SEARCH_FILTER_INVALID_RESULT_TYPE.
get(String.valueOf(entry.getDN()),
String.valueOf(completeFilter),
String.valueOf(r));
throw new DirectoryException(
ResultCode.PROTOCOL_ERROR, message);
}
}
catch (Exception e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
// We couldn't normalize one of the values. If we don't
// find a definite match, then we should return
// undefined.
result = ConditionResult.UNDEFINED;
}
}
}
}
}
// If we've gotten here, then we know that there is no definite
// match in the set of attributes. If we should check DN
// attributes, then do so.
if (dnAttributes)
{
DN entryDN = entry.getDN();
int count = entryDN.getNumComponents();
for (int rdnIndex = 0; rdnIndex < count; rdnIndex++)
{
RDN rdn = entryDN.getRDN(rdnIndex);
int numAVAs = rdn.getNumValues();
for (int i=0; i < numAVAs; i++)
{
try
{
if ((attributeType == null) ||
attributeType.equals(rdn.getAttributeType(i)))
{
AttributeValue v = rdn.getAttributeValue(i);
ByteString nv =
matchingRule.normalizeValue(v.getValue());
ConditionResult r =
matchingRule.valuesMatch(nv, normalizedValue);
switch (r)
{
case TRUE:
return ConditionResult.TRUE;
case FALSE: