opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
@@ -45,6 +45,9 @@ 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.ConfigurationAddListener; import org.forgerock.opendj.config.server.ConfigurationChangeListener; import org.forgerock.opendj.config.server.ConfigurationDeleteListener; import org.forgerock.opendj.ldap.ByteSequence; import org.forgerock.opendj.ldap.ByteString; import org.forgerock.opendj.ldap.ByteStringBuilder; @@ -53,14 +56,11 @@ import org.forgerock.opendj.ldap.SearchScope; import org.forgerock.opendj.ldap.SortKey; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.util.Pair; import org.opends.messages.CoreMessages; import org.forgerock.opendj.config.server.ConfigurationAddListener; import org.forgerock.opendj.config.server.ConfigurationChangeListener; import org.forgerock.opendj.config.server.ConfigurationDeleteListener; import org.forgerock.opendj.server.config.server.BackendIndexCfg; import org.forgerock.opendj.server.config.server.BackendVLVIndexCfg; import org.forgerock.opendj.server.config.server.PluggableBackendCfg; import org.forgerock.util.Pair; import org.opends.messages.CoreMessages; import org.opends.server.api.ClientConnection; import org.opends.server.api.EntryCache; import org.opends.server.api.VirtualAttributeProvider; @@ -89,11 +89,11 @@ import org.opends.server.core.ModifyOperation; import org.opends.server.core.SearchOperation; import org.opends.server.core.ServerContext; import org.opends.server.crypto.CryptoSuite; import org.opends.server.types.Attribute; import org.opends.server.types.Attributes; import org.opends.server.types.CanceledOperationException; import org.opends.server.types.Control; import org.opends.server.crypto.CryptoSuite; import org.opends.server.types.DirectoryException; import org.opends.server.types.Entry; import org.opends.server.types.Modification; @@ -2229,8 +2229,7 @@ // Process in index configuration order. for (AttributeIndex index : attrIndexMap.values()) { // Check whether any modifications apply to this indexed attribute. if (isAttributeModified(index, mods)) if (isAttributeModified(index.getAttributeType(), mods)) { index.modifyEntry(buffer, entryID, oldEntry, newEntry); } @@ -2486,31 +2485,6 @@ return null; } /** * Checks if any modifications apply to this indexed attribute. * @param index the indexed attributes. * @param mods the modifications to check for. * @return true if any apply, false otherwise. */ private static boolean isAttributeModified(AttributeIndex index, List<Modification> mods) { AttributeType indexAttributeType = index.getAttributeType(); List<AttributeType> subTypes = DirectoryServer.getSchema().getSubTypes(indexAttributeType); for (Modification mod : mods) { Attribute modAttr = mod.getAttribute(); AttributeType modAttrType = modAttr.getAttributeDescription().getAttributeType(); if (modAttrType.equals(indexAttributeType) || subTypes.contains(modAttrType)) { return true; } } return false; } boolean isConfidentialityEnabled() { return config.isConfidentialityEnabled(); @@ -2740,4 +2714,16 @@ public String toString() { return treePrefix; } static boolean isAttributeModified(AttributeType attrType, List<Modification> mods) { for (Modification mod : mods) { if (attrType.isSuperTypeOf(mod.getAttribute().getAttributeDescription().getAttributeType())) { return true; } } return false; } } opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java
@@ -417,16 +417,9 @@ for (final SortKey sortKey : sortKeys) { final AttributeDescription attrDesc = AttributeDescription.valueOf(sortKey.getAttributeDescription()); final AttributeType attributeType = attrDesc.getAttributeType(); final List<AttributeType> subTypes = DirectoryServer.getSchema().getSubTypes(attributeType); for (final Modification mod : mods) if (EntryContainer.isAttributeModified(attrDesc.getAttributeType(), mods)) { final AttributeType modAttrType = mod.getAttribute().getAttributeDescription().getAttributeType(); if (modAttrType.equals(attributeType) || subTypes.contains(modAttrType)) { return true; } return true; } } return false; opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -124,11 +124,6 @@ */ private transient Object attachment; /** The schema used to govern this entry. */ private final Schema schema; /** * Creates a new entry with the provided information. * @@ -151,8 +146,6 @@ Map<AttributeType,List<Attribute>> userAttributes, Map<AttributeType,List<Attribute>> operationalAttributes) { schema = DirectoryServer.getSchema(); setDN(dn); this.objectClasses = newMapIfNull(objectClasses); @@ -453,8 +446,6 @@ public boolean hasAttribute(AttributeDescription attributeDescription, boolean includeSubordinates) { AttributeType attributeType = attributeDescription.getAttributeType(); // Handle object class. if (attributeType.isObjectClass()) { return !objectClasses.isEmpty() && !attributeDescription.hasOptions(); @@ -468,40 +459,8 @@ return attribute != null && !attribute.isEmpty(); } // Check all matching attributes. List<Attribute> attributes = getAttributes(attributeType); if (attributes != null) { for (Attribute attribute : attributes) { // It's possible that there could be an attribute without any // values, which we should treat as not having the requested attribute. if (!attribute.isEmpty() && attribute.getAttributeDescription().isSubTypeOf(attributeDescription)) { return true; } } } // Check sub-types. for (AttributeType subType : schema.getSubTypes(attributeType)) { attributes = getAttributes(subType); if (attributes != null) { for (Attribute attribute : attributes) { // It's possible that there could be an attribute without any values, // which we should treat as not having the requested attribute. if (!attribute.isEmpty() && attribute.getAttributeDescription().isSubTypeOf(attributeDescription)) { return true; } } } } return false; return hasAttributeOrSubType(attributeDescription, userAttributes) || hasAttributeOrSubType(attributeDescription, operationalAttributes); } /** @@ -600,15 +559,8 @@ if (includeSubordinates && !attributeType.isObjectClass()) { List<Attribute> attributes = new LinkedList<>(); addAllIfNotNull(attributes, userAttributes.get(attributeType)); addAllIfNotNull(attributes, operationalAttributes.get(attributeType)); for (AttributeType at : schema.getSubTypes(attributeType)) { addAllIfNotNull(attributes, userAttributes.get(at)); addAllIfNotNull(attributes, operationalAttributes.get(at)); } addAttributeTypeOrSubTypeValue(attributes, attributeType, userAttributes); addAttributeTypeOrSubTypeValue(attributes, attributeType, operationalAttributes); return attributes; } @@ -629,23 +581,59 @@ return Collections.emptyList(); } /** * Add to the destination all the elements from a non null source . * * @param dest * the destination where to add * @param source * the source with the elements to be added */ private void addAllIfNotNull(List<Attribute> dest, List<Attribute> source) private void addAttributeTypeOrSubTypeValue(Collection<Attribute> results, AttributeType attrType, Map<AttributeType, List<Attribute>> attrsMap) { if (source != null) for (Map.Entry<AttributeType, List<Attribute>> mapEntry : attrsMap.entrySet()) { dest.addAll(source); if (attrType.isSuperTypeOf(mapEntry.getKey())) { results.addAll(mapEntry.getValue()); } } } private void addAttributeTypeOrSubTypeValue(Collection<Attribute> results, AttributeDescription attrDesc, Map<AttributeType, List<Attribute>> attrsMap) { for (Map.Entry<AttributeType, List<Attribute>> mapEntry : attrsMap.entrySet()) { if (!attrDesc.getAttributeType().isSuperTypeOf(mapEntry.getKey())) { continue; } for (Attribute attribute : mapEntry.getValue()) { if (attrDesc.isSuperTypeOf(attribute.getAttributeDescription())) { results.add(attribute); } } } } private boolean hasAttributeOrSubType(AttributeDescription attrDesc, Map<AttributeType, List<Attribute>> attrsMap) { for (Map.Entry<AttributeType, List<Attribute>> mapEntry : attrsMap.entrySet()) { if (!attrDesc.getAttributeType().isSuperTypeOf(mapEntry.getKey())) { continue; } for (Attribute attribute : mapEntry.getValue()) { // It's possible that there could be an attribute without any values, // which we should treat as not having the requested attribute. if (!attribute.isEmpty() && attrDesc.isSuperTypeOf(attribute.getAttributeDescription())) { return true; } } } return false; } /** * Retrieves the requested attribute element(s) for the attribute @@ -674,7 +662,7 @@ { if (attr.hasNameOrOID(lowerName)) { return getAttribute(attr, true); return getAttribute(attr); } } @@ -682,7 +670,7 @@ { if (attr.hasNameOrOID(lowerName)) { return getAttribute(attr, true); return getAttribute(attr); } } @@ -710,38 +698,32 @@ public List<Attribute> getAttribute(AttributeDescription attributeDescription) { AttributeType attributeType = attributeDescription.getAttributeType(); List<Attribute> attributes = new LinkedList<>(); final List<Attribute> attributes = new LinkedList<>(); if (!attributeType.isObjectClass()) { addAllIfNotNull(attributes, userAttributes.get(attributeType)); addAllIfNotNull(attributes, operationalAttributes.get(attributeType)); for (AttributeType at : schema.getSubTypes(attributeType)) { addAllIfNotNull(attributes, userAttributes.get(at)); addAllIfNotNull(attributes, operationalAttributes.get(at)); } addAttributeTypeOrSubTypeValue(attributes, attributeDescription, userAttributes); addAttributeTypeOrSubTypeValue(attributes, attributeDescription, operationalAttributes); return attributes; } else List<Attribute> attrs = userAttributes.get(attributeType); if (attrs == null) { List<Attribute> attrs = userAttributes.get(attributeType); attrs = operationalAttributes.get(attributeType); if (attrs == null) { attrs = operationalAttributes.get(attributeType); if (attrs == null) if (attributeType.isObjectClass() && !objectClasses.isEmpty() && !attributeDescription.hasOptions()) { if (attributeType.isObjectClass() && !objectClasses.isEmpty() && !attributeDescription.hasOptions()) { attributes.add(getObjectClassAttribute()); return attributes; } return Collections.emptyList(); attributes.add(getObjectClassAttribute()); return attributes; } return Collections.emptyList(); } attributes.addAll(attrs); } attributes.addAll(attrs); onlyKeepAttributesWithAllOptions(attributes, attributeDescription); @@ -805,55 +787,20 @@ return getAttribute(attributeType, userAttributes); } /** * Returns the List of attributes for a given attribute type. * * @param attributeType * the attribute type to be looked for * @param attrs * the attributes Map where to find the attributes * @return the List of attributes */ private List<Attribute> getAttribute(AttributeType attributeType, Map<AttributeType, List<Attribute>> attrs) { List<Attribute> attributes = new LinkedList<>(); addAllIfNotNull(attributes, attrs.get(attributeType)); for (AttributeType at : schema.getSubTypes(attributeType)) { addAllIfNotNull(attributes, attrs.get(at)); } return attributes; List<Attribute> results = new LinkedList<>(); addAttributeTypeOrSubTypeValue(results, attributeType, attrs); return results; } /** * Returns the List of attributes for a given attribute type having all the * required options. * * @param attributeType * the attribute type to be looked for * @param options * the options that must all be present * @param attrs * the attributes Map where to find the attributes * @return the filtered List of attributes */ private List<Attribute> getAttribute(AttributeDescription attributeDescription, Map<AttributeType, List<Attribute>> attrs) { AttributeType attributeType = attributeDescription.getAttributeType(); List<Attribute> attributes = new LinkedList<>(); addAllIfNotNull(attributes, attrs.get(attributeType)); for (AttributeType at : schema.getSubTypes(attributeType)) { addAllIfNotNull(attributes, attrs.get(at)); } onlyKeepAttributesWithAllOptions(attributes, attributeDescription); return attributes; List<Attribute> results = new LinkedList<>(); addAttributeTypeOrSubTypeValue(results, attributeDescription, attrs); return results; } /** @@ -894,19 +841,13 @@ private boolean hasAttribute(Map<AttributeType, List<Attribute>> attributes, AttributeType attributeType) { if (attributes.containsKey(attributeType)) for (AttributeType key : attributes.keySet()) { return true; } for (AttributeType at : schema.getSubTypes(attributeType)) { if (attributes.containsKey(at)) if (attributeType.isSuperTypeOf(key)) { return true; } } return false; } @@ -1708,8 +1649,7 @@ { if (DirectoryServer.getObjectClass(o.getOID()).isPlaceHolder()) { LocalizableMessage message = ERR_ENTRY_SCHEMA_UNKNOWN_OC.get(dn, o.getNameOrOID()); invalidReason.append(message); invalidReason.append(ERR_ENTRY_SCHEMA_UNKNOWN_OC.get(dn, o.getNameOrOID())); return false; } @@ -2150,9 +2090,7 @@ { if (parentStructuralClass == null) { LocalizableMessage message = ERR_ENTRY_SCHEMA_DSR_NO_PARENT_OC.get( dn, parentEntry.getName()); LocalizableMessage message = ERR_ENTRY_SCHEMA_DSR_NO_PARENT_OC.get(dn, parentEntry.getName()); if (structuralPolicy == AcceptRejectWarn.REJECT) { invalidReason.append(message); @@ -2464,8 +2402,7 @@ * @return true if the current entry has the object class or the attribute, * false otherwise */ private boolean hasObjectClassOrAttribute(String objectClassName, String attrTypeName) private boolean hasObjectClassOrAttribute(String objectClassName, String attrTypeName) { ObjectClass oc = DirectoryServer.getObjectClass(objectClassName); if (oc.isPlaceHolder()) @@ -2480,7 +2417,6 @@ return false; } AttributeType attrType = DirectoryServer.getAttributeType(attrTypeName); if (attrType.isPlaceHolder()) { opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java
@@ -22,7 +22,6 @@ import static org.opends.messages.CoreMessages.*; import static org.opends.messages.SchemaMessages.*; import static org.opends.server.config.ConfigConstants.*; import static org.opends.server.util.CollectionUtils.*; import static org.opends.server.util.ServerConstants.*; import static org.opends.server.util.StaticUtils.*; @@ -100,12 +99,6 @@ private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); /** * Provides for each attribute type having at least one subordinate type the complete list of * its descendants. */ private Map<AttributeType, List<AttributeType>> subordinateTypes; /** * The set of ldap syntax descriptions for this schema, mapped the OID and the * ldap syntax description itself. */ @@ -114,7 +107,6 @@ /** The oldest modification timestamp for any schema configuration file. */ private long oldestModificationTime; /** The youngest modification timestamp for any schema configuration file. */ private long youngestModificationTime; @@ -155,7 +147,6 @@ switchSchema(newSchemaNG); ldapSyntaxDescriptions = new ConcurrentHashMap<String,LDAPSyntaxDescription>(); subordinateTypes = new ConcurrentHashMap<AttributeType,List<AttributeType>>(); oldestModificationTime = System.currentTimeMillis(); youngestModificationTime = oldestModificationTime; @@ -448,11 +439,6 @@ builder.addAttributeType(defWithFile, overwrite); } switchSchema(builder.toSchema()); for (String definition : definitions) { updateSubordinateTypes(schemaNG.getAttributeType(parseAttributeTypeOID(definition))); } } catch (ConflictingSchemaElementException | UnknownSchemaElementException e) { @@ -511,8 +497,6 @@ SchemaBuilder builder = new SchemaBuilder(schemaNG); registerAttributeType0(builder, attributeType, schemaFile, overwriteExisting); switchSchema(builder.toSchema()); updateSubordinateTypes(attributeType); } catch (LocalizedIllegalArgumentException e) { @@ -564,13 +548,6 @@ builder.removeAttributeType(existingAttributeType.getNameOrOID()); registerAttributeType0(builder, newAttributeType, schemaFile, false); switchSchema(builder.toSchema()); AttributeType superiorType = existingAttributeType.getSuperiorType(); if (superiorType != null) { deregisterSubordinateType(existingAttributeType, superiorType); } updateSubordinateTypes(newAttributeType); } finally { @@ -669,11 +646,6 @@ SchemaBuilder builder = new SchemaBuilder(schemaNG); if (builder.removeAttributeType(attributeType.getNameOrOID())) { AttributeType superiorType = attributeType.getSuperiorType(); if (superiorType != null) { deregisterSubordinateType(attributeType, superiorType); } switchSchema(builder.toSchema()); } } @@ -683,84 +655,6 @@ } } private void updateSubordinateTypes(AttributeType attributeType) { AttributeType superiorType = attributeType.getSuperiorType(); if (superiorType != null) { registerSubordinateType(attributeType, superiorType); } } /** * Registers the provided attribute type as a subtype of the given * superior attribute type, recursively following any additional * elements in the superior chain. * * @param attributeType The attribute type to be registered as a * subtype for the given superior type. * @param superiorType The superior type for which to register * the given attribute type as a subtype. */ private void registerSubordinateType(AttributeType attributeType, AttributeType superiorType) { List<AttributeType> subTypes = subordinateTypes.get(superiorType); if (subTypes == null) { subordinateTypes.put(superiorType, newLinkedList(attributeType)); } else if (!subTypes.contains(attributeType)) { subTypes.add(attributeType); AttributeType higherSuperior = superiorType.getSuperiorType(); if (higherSuperior != null) { registerSubordinateType(attributeType, higherSuperior); } } } /** * Deregisters the provided attribute type as a subtype of the given * superior attribute type, recursively following any additional * elements in the superior chain. * * @param attributeType The attribute type to be deregistered as a * subtype for the given superior type. * @param superiorType The superior type for which to deregister * the given attribute type as a subtype. */ private void deregisterSubordinateType(AttributeType attributeType, AttributeType superiorType) { List<AttributeType> subTypes = subordinateTypes.get(superiorType); if (subTypes != null && subTypes.remove(attributeType)) { AttributeType higherSuperior = superiorType.getSuperiorType(); if (higherSuperior != null) { deregisterSubordinateType(attributeType, higherSuperior); } } } /** * Retrieves the set of subtypes registered for the given attribute * type. * * @param attributeType The attribute type for which to retrieve * the set of registered subtypes. * * @return The set of subtypes registered for the given attribute * type, or an empty set if there are no subtypes * registered for the attribute type. */ public List<AttributeType> getSubTypes(AttributeType attributeType) { List<AttributeType> subTypes = subordinateTypes.get(attributeType); return subTypes != null ? subTypes : Collections.<AttributeType> emptyList(); } /** * Retrieves the objectclass definitions for this schema. * @@ -1936,7 +1830,6 @@ throw new RuntimeException(unexpected); } dupSchema.subordinateTypes.putAll(subordinateTypes); dupSchema.ldapSyntaxDescriptions.putAll(ldapSyntaxDescriptions); dupSchema.oldestModificationTime = oldestModificationTime; dupSchema.youngestModificationTime = youngestModificationTime; @@ -2365,12 +2258,6 @@ schemaNG = null; } if (subordinateTypes != null) { subordinateTypes.clear(); subordinateTypes = null; } if (extraAttributes != null) { extraAttributes.clear();