opendj-server-legacy/src/main/java/org/opends/server/api/Backend.java
@@ -35,6 +35,7 @@ import org.forgerock.opendj.ldap.ResultCode; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException; import org.opends.server.backends.RebuildConfig; import org.opends.server.backends.VerifyConfig; import org.opends.server.core.AddOperation; @@ -322,9 +323,7 @@ } String matchingRuleID = filter.getMatchingRuleID(); MatchingRule matchingRule = matchingRuleID != null ? DirectoryServer.getMatchingRule(matchingRuleID) : attrType.getEqualityMatchingRule(); MatchingRule matchingRule = getMatchingRule(attrType, matchingRuleID); // FIXME isIndexed() always return false down below return matchingRule != null && isIndexed(attrType, matchingRule); @@ -334,6 +333,23 @@ } } private MatchingRule getMatchingRule(AttributeType attrType, String matchingRuleID) { if (matchingRuleID == null) { return attrType.getEqualityMatchingRule(); } try { return DirectoryServer.getSchema().getMatchingRule(matchingRuleID); } catch (UnknownSchemaElementException e) { return null; } } /** * Retrieves the requested entry from this backend. The caller is not required to hold any locks * on the specified DN. opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
@@ -46,6 +46,7 @@ import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.Schema; import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException; import org.forgerock.opendj.ldap.spi.IndexQueryFactory; import org.forgerock.opendj.ldap.spi.Indexer; import org.forgerock.opendj.ldap.spi.IndexingOptions; @@ -333,7 +334,7 @@ indexers.putAll(buildBaseIndexers(false, false, indexType, attributeType, indexingOptions)); break; default: throw new ConfigException(ERR_CONFIG_INDEX_TYPE_NEEDS_MATCHING_RULE.get(attributeType, indexType)); throw noMatchingRuleForIndexType(attributeType, indexType); } } return buildIndexesForIndexers(entryContainer, attributeType, state, indexEntryLimit, indexers, cryptoSuite); @@ -344,7 +345,10 @@ { Map<Indexer, Boolean> indexers = new HashMap<>(); MatchingRule rule = getMatchingRule(indexType, attributeType); throwIfNoMatchingRule(attributeType, indexType, rule); if (rule == null) { throw noMatchingRuleForIndexType(attributeType, indexType); } throwIfProtectKeysAndValues(attributeType, protectIndexKeys, protectIndexValues); Collection<? extends Indexer> ruleIndexers = rule.createIndexers(indexingOptions); for (Indexer indexer: ruleIndexers) @@ -361,13 +365,9 @@ return indexers; } private static void throwIfNoMatchingRule(AttributeType attributeType, IndexType indexType, MatchingRule rule) throws ConfigException private static ConfigException noMatchingRuleForIndexType(AttributeType attributeType, IndexType indexType) { if (rule == null) { throw new ConfigException(ERR_CONFIG_INDEX_TYPE_NEEDS_MATCHING_RULE.get(attributeType, indexType)); } return new ConfigException(ERR_CONFIG_INDEX_TYPE_NEEDS_MATCHING_RULE.get(attributeType, indexType)); } private void throwIfProtectKeysAndValues(AttributeType attributeType, boolean protectKeys, boolean protectValues) @@ -403,17 +403,23 @@ IndexType indexType = IndexType.EXTENSIBLE; if (extensibleRules == null || extensibleRules.isEmpty()) { throw new ConfigException(ERR_CONFIG_INDEX_TYPE_NEEDS_MATCHING_RULE.get(attributeType, indexType)); throw noMatchingRuleForIndexType(attributeType, indexType); } final Map<Indexer, Boolean> indexers = new HashMap<>(); for (final String ruleName : extensibleRules) { final MatchingRule rule = DirectoryServer.getMatchingRule(ruleName); throwIfNoMatchingRule(attributeType, indexType, rule); for (Indexer indexer : rule.createIndexers(options)) try { indexers.put(indexer, false); final MatchingRule rule = DirectoryServer.getSchema().getMatchingRule(ruleName); for (Indexer indexer : rule.createIndexers(options)) { indexers.put(indexer, false); } } catch (UnknownSchemaElementException e) { throw noMatchingRuleForIndexType(attributeType, indexType); } } @@ -1088,7 +1094,7 @@ return evaluateFilter(indexQueryFactory, IndexFilterType.EQUALITY, filter, debugBuffer, monitor); } MatchingRule rule = DirectoryServer.getMatchingRule(matchRuleOID); MatchingRule rule = DirectoryServer.getSchema().getMatchingRule(matchRuleOID); if (!ruleHasAtLeastOneIndex(rule)) { if (monitor.isFilterUseEnabled()) opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java
@@ -36,6 +36,7 @@ import org.forgerock.i18n.slf4j.LocalizedLogger; import org.forgerock.opendj.config.server.ConfigChangeResult; import org.forgerock.opendj.config.server.ConfigException; import org.forgerock.opendj.config.server.ConfigurationChangeListener; import org.forgerock.opendj.ldap.AttributeDescription; import org.forgerock.opendj.ldap.ByteSequence; import org.forgerock.opendj.ldap.ByteString; @@ -47,10 +48,10 @@ import org.forgerock.opendj.ldap.SortKey; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.util.Reject; import org.forgerock.opendj.config.server.ConfigurationChangeListener; import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException; import org.forgerock.opendj.server.config.meta.BackendVLVIndexCfgDefn.Scope; import org.forgerock.opendj.server.config.server.BackendVLVIndexCfg; import org.forgerock.util.Reject; import org.opends.server.backends.pluggable.State.IndexFlag; import org.opends.server.backends.pluggable.spi.Cursor; import org.opends.server.backends.pluggable.spi.Importer; @@ -841,10 +842,12 @@ String mrOid = sortKey.getOrderingMatchingRule(); if (mrOid != null) { MatchingRule orderingRule = getMatchingRule(mrOid); if (orderingRule != null) try { return orderingRule; return getSchema().getMatchingRule(mrOid); } catch (UnknownSchemaElementException e) { } } AttributeDescription attrDesc = AttributeDescription.valueOf(sortKey.getAttributeDescription()); opendj-server-legacy/src/main/java/org/opends/server/controls/MatchedValuesFilter.java
@@ -30,6 +30,7 @@ import org.forgerock.opendj.ldap.DecodeException; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException; import org.forgerock.util.Reject; import org.opends.server.core.DirectoryServer; import org.opends.server.protocols.ldap.LDAPResultCode; @@ -944,7 +945,13 @@ { if (matchingRule == null && matchingRuleID != null) { matchingRule = DirectoryServer.getMatchingRule(matchingRuleID); try { matchingRule = DirectoryServer.getSchema().getMatchingRule(matchingRuleID); } catch (UnknownSchemaElementException e) { } } return matchingRule; } opendj-server-legacy/src/main/java/org/opends/server/controls/ServerSideSortRequestControl.java
@@ -35,6 +35,7 @@ import org.forgerock.opendj.ldap.SortKey; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException; import org.opends.server.core.DirectoryServer; import org.opends.server.protocols.ldap.LDAPResultCode; import org.opends.server.types.Control; @@ -111,14 +112,14 @@ reader.peekType() == TYPE_ORDERING_RULE_ID) { String orderingRuleID = reader.readOctetStringAsString(); orderingRule = DirectoryServer.getMatchingRule(orderingRuleID); if (orderingRule == null) try { LocalizableMessage message = INFO_SORTREQ_CONTROL_UNDEFINED_ORDERING_RULE. get(orderingRuleID); throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message); orderingRule = DirectoryServer.getSchema().getMatchingRule(orderingRuleID); } catch (UnknownSchemaElementException e) { LocalizableMessage message = INFO_SORTREQ_CONTROL_UNDEFINED_ORDERING_RULE.get(orderingRuleID); throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message); } } if(reader.hasNextElement() && @@ -431,8 +432,11 @@ MatchingRule orderingRule = null; if(decodedKey[1] != null) { orderingRule = DirectoryServer.getMatchingRule(decodedKey[1]); if (orderingRule == null) try { orderingRule = DirectoryServer.getSchema().getMatchingRule(decodedKey[1]); } catch (UnknownSchemaElementException e) { LocalizableMessage message = INFO_SORTREQ_CONTROL_UNDEFINED_ORDERING_RULE.get(decodedKey[1]); throw new DirectoryException(ResultCode.PROTOCOL_ERROR, message); opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -2283,20 +2283,6 @@ } /** * Retrieves the matching rule with the specified name or OID. * * @param lowerName The lowercase name or OID for the matching rule to * retrieve. * * @return The requested matching rule, or {@code null} if no such * matching rule has been defined in the server. */ public static MatchingRule getMatchingRule(String lowerName) { return directoryServer.schema.getMatchingRule(lowerName); } /** * Retrieves the objectclass for the provided name or OID. It can optionally return a generated * "default" version if the requested objectclass is not defined in the schema. * opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPFilter.java
@@ -32,7 +32,7 @@ import org.forgerock.opendj.ldap.ByteStringBuilder; import org.forgerock.opendj.ldap.ResultCode; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException; import org.opends.server.core.DirectoryServer; import org.opends.server.types.DirectoryException; import org.opends.server.types.FilterType; @@ -1911,8 +1911,11 @@ ERR_LDAP_FILTER_VALUE_WITH_NO_ATTR_OR_MR.get()); } MatchingRule mr = DirectoryServer.getMatchingRule(matchingRuleID); if (mr == null) try { DirectoryServer.getSchema().getMatchingRule(matchingRuleID); } catch (UnknownSchemaElementException e) { throw new DirectoryException(ResultCode.INAPPROPRIATE_MATCHING, ERR_LDAP_FILTER_UNKNOWN_MATCHING_RULE.get(matchingRuleID)); opendj-server-legacy/src/main/java/org/opends/server/types/SearchFilter.java
@@ -38,11 +38,13 @@ import org.forgerock.opendj.ldap.ByteString; import org.forgerock.opendj.ldap.ByteStringBuilder; import org.forgerock.opendj.ldap.ConditionResult; import org.forgerock.opendj.ldap.DecodeException; import org.forgerock.opendj.ldap.RDN; import org.forgerock.opendj.ldap.ResultCode; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.MatchingRuleUse; import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException; import org.opends.server.core.DirectoryServer; /** @@ -2035,8 +2037,11 @@ ERR_SEARCH_FILTER_EXTENSIBLE_MATCH_NO_AD_OR_MR.get(filterString, startPos)); } MatchingRule mr = DirectoryServer.getMatchingRule(matchingRuleID); if (mr == null) try { DirectoryServer.getSchema().getMatchingRule(matchingRuleID); } catch (UnknownSchemaElementException e) { throw new DirectoryException(ResultCode.PROTOCOL_ERROR, ERR_SEARCH_FILTER_EXTENSIBLE_MATCH_NO_SUCH_MR.get(filterString, startPos, matchingRuleID)); @@ -3177,16 +3182,14 @@ if (matchingRuleID != null) { matchingRule = DirectoryServer.getMatchingRule(matchingRuleID); if (matchingRule == null) try { if (logger.isTraceEnabled()) { logger.trace( "Unknown matching rule %s defined in extensibleMatch " + "component of filter %s -- returning undefined.", matchingRuleID, this); } matchingRule = DirectoryServer.getSchema().getMatchingRule(matchingRuleID); } catch (UnknownSchemaElementException e) { logger.trace("Unknown matching rule %s defined in extensibleMatch " + "component of filter %s -- returning undefined.", matchingRuleID, this); return ConditionResult.UNDEFINED; } } @@ -3639,23 +3642,16 @@ } else { MatchingRule mrule = DirectoryServer.getMatchingRule(matchingRuleID); if (mrule == null) try { MatchingRule mrule = DirectoryServer.getSchema().getMatchingRule(matchingRuleID); Assertion assertion = mrule.getAssertion(f.assertionValue); return assertion.matches(mrule.normalizeAttributeValue(assertionValue)).toBoolean(); } catch (DecodeException | UnknownSchemaElementException e) { return false; } else { try { Assertion assertion = mrule.getAssertion(f.assertionValue); return assertion.matches(mrule.normalizeAttributeValue(assertionValue)).toBoolean(); } catch (Exception e) { return false; } } } } opendj-server-legacy/src/test/java/org/opends/server/schema/FakeByteStringIndex.java
@@ -46,7 +46,7 @@ FakeByteStringIndex(String mrName) throws DecodeException { matchingRule = DirectoryServer.getMatchingRule(mrName); matchingRule = DirectoryServer.getSchema().getMatchingRule(mrName); IndexingOptions options = mock(IndexingOptions.class); indexer = matchingRule.createIndexers(options).iterator().next(); } opendj-server-legacy/src/test/java/org/opends/server/schema/FakeEntryIndex.java
@@ -125,7 +125,7 @@ return matchingRule.getGreaterOrEqualAssertion(filter.getAssertionValue()); case EXTENSIBLE_MATCH: MatchingRule rule = DirectoryServer.getMatchingRule(filter.getMatchingRuleID()); MatchingRule rule = DirectoryServer.getSchema().getMatchingRule(filter.getMatchingRuleID()); return rule.getAssertion(filter.getAssertionValue()); default: opendj-server-legacy/src/test/java/org/opends/server/schema/TimeBasedMatchingRuleTest.java
@@ -16,7 +16,10 @@ */ package org.opends.server.schema; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.*; import static org.opends.server.schema.GeneralizedTimeSyntax.format; import static org.opends.server.schema.SchemaConstants.*; import static org.testng.Assert.*; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -47,10 +50,6 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.opends.server.schema.GeneralizedTimeSyntax.*; import static org.opends.server.schema.SchemaConstants.*; import static org.testng.Assert.*; /** This class tests various time-based matching rules. */ @SuppressWarnings("javadoc") public final class TimeBasedMatchingRuleTest @@ -153,7 +152,7 @@ private Collection<DN> getMatchingEntryDNs(SearchFilter filter) throws Exception { AttributeType attrType = filter.getAttributeType(); MatchingRule rule = DirectoryServer.getMatchingRule(filter.getMatchingRuleID()); MatchingRule rule = DirectoryServer.getSchema().getMatchingRule(filter.getMatchingRuleID()); Assertion assertion = rule.getAssertion(filter.getAssertionValue()); Collection<DN> results = new ArrayList<>(); @@ -200,7 +199,7 @@ public void testPartialDateNTimeMatch(long timeInMillis, String generalizedTime, String assertionValue) throws Exception { MatchingRule partialTimeRule = DirectoryServer.getMatchingRule(EXT_PARTIAL_DATE_TIME_NAME); MatchingRule partialTimeRule = DirectoryServer.getSchema().getMatchingRule(EXT_PARTIAL_DATE_TIME_NAME); Assertion assertion = partialTimeRule.getAssertion(ByteString.valueOfUtf8(assertionValue)); assertEquals(assertion.matches(ByteString.valueOfLong(timeInMillis)), ConditionResult.TRUE); } @@ -224,8 +223,7 @@ @Test(dataProvider= "relativeTimeValues") public void testRelativeTimeMatchingRuleAssertionSyntax(String assertion,boolean isValid) { MatchingRule relativeTimeLTRule = DirectoryServer.getMatchingRule(EXT_OMR_RELATIVE_TIME_LT_ALT_NAME.toLowerCase()); MatchingRule relativeTimeLTRule = DirectoryServer.getSchema().getMatchingRule(EXT_OMR_RELATIVE_TIME_LT_ALT_NAME); try { relativeTimeLTRule.getAssertion(ByteString.valueOfUtf8(assertion)); @@ -245,8 +243,7 @@ @Test(dataProvider= "partialDateTimeSyntaxes") public void testPartialDateTimeMatchingRuleAssertionSyntax(String assertion,boolean isValid) { MatchingRule partialDTRule = DirectoryServer.getMatchingRule(EXT_PARTIAL_DATE_TIME_OID); MatchingRule partialDTRule = DirectoryServer.getSchema().getMatchingRule(EXT_PARTIAL_DATE_TIME_OID); try { partialDTRule.getAssertion(ByteString.valueOfUtf8(assertion));