| | |
| | | import org.forgerock.opendj.ldap.schema.CoreSchema; |
| | | import org.forgerock.opendj.ldap.schema.MatchingRule; |
| | | import org.forgerock.opendj.ldap.schema.MatchingRuleUse; |
| | | import org.forgerock.opendj.ldap.schema.NameForm; |
| | | import org.forgerock.opendj.ldap.schema.ObjectClass; |
| | | import org.forgerock.opendj.ldap.schema.ObjectClassType; |
| | | import org.forgerock.opendj.ldap.schema.SchemaElement; |
| | |
| | | import org.opends.server.schema.DITContentRuleSyntax; |
| | | import org.opends.server.schema.DITStructureRuleSyntax; |
| | | import org.opends.server.schema.GeneralizedTimeSyntax; |
| | | import org.opends.server.schema.NameFormSyntax; |
| | | import org.opends.server.schema.ServerSchemaElement; |
| | | import org.opends.server.schema.SomeSchemaElement; |
| | | import org.opends.server.types.Attribute; |
| | |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.types.LDIFImportResult; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.NameForm; |
| | | import org.opends.server.types.Privilege; |
| | | import org.opends.server.types.RestoreConfig; |
| | | import org.opends.server.types.Schema; |
| | |
| | | */ |
| | | buildSchemaAttribute(schema.getSyntaxes(), userAttrs, |
| | | operationalAttrs, ldapSyntaxesType, includeSchemaFile, false, true); |
| | | buildSchemaAttribute(schema.getNameFormsByNameOrOID().values(), userAttrs, |
| | | buildSchemaAttribute(schema.getNameForms(), userAttrs, |
| | | operationalAttrs, nameFormsType, includeSchemaFile, false, true); |
| | | buildSchemaAttribute(schema.getDITContentRules().values(), userAttrs, |
| | | operationalAttrs, ditContentRulesType, includeSchemaFile, false, true); |
| | |
| | | { |
| | | for (ByteString v : a) |
| | | { |
| | | NameForm nf; |
| | | try |
| | | { |
| | | nf = NameFormSyntax.decodeNameForm(v, newSchema, false); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | logger.traceException(de); |
| | | |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_CANNOT_DECODE_NAME_FORM.get( |
| | | v, de.getMessageObject()); |
| | | throw new DirectoryException( |
| | | ResultCode.INVALID_ATTRIBUTE_SYNTAX, message, de); |
| | | } |
| | | |
| | | NameForm nf = newSchema.parseNameForm(v.toString()); |
| | | addNameForm(nf, newSchema, modifiedSchemaFiles); |
| | | } |
| | | } |
| | |
| | | { |
| | | for (ByteString v : a) |
| | | { |
| | | NameForm nf; |
| | | try |
| | | { |
| | | nf = NameFormSyntax.decodeNameForm(v, newSchema, false); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | logger.traceException(de); |
| | | |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_CANNOT_DECODE_NAME_FORM.get( |
| | | v, de.getMessageObject()); |
| | | throw new DirectoryException( |
| | | ResultCode.INVALID_ATTRIBUTE_SYNTAX, message, de); |
| | | } |
| | | |
| | | NameForm nf = newSchema.parseNameForm(v.toString()); |
| | | removeNameForm(nf, newSchema, mods, pos, modifiedSchemaFiles); |
| | | } |
| | | } |
| | |
| | | // Otherwise, we're replacing an existing one. |
| | | if (existingType.isPlaceHolder()) |
| | | { |
| | | String schemaFile = addNewSchemaElement(modifiedSchemaFiles, new SomeSchemaElement(attributeType)); |
| | | String schemaFile = addNewSchemaElement(modifiedSchemaFiles, new ServerSchemaElement(attributeType)); |
| | | schema.registerAttributeType(attributeType, schemaFile, false); |
| | | } |
| | | else |
| | | { |
| | | String schemaFile = replaceExistingSchemaElement( |
| | | modifiedSchemaFiles, new SomeSchemaElement(attributeType), new SomeSchemaElement(existingType)); |
| | | modifiedSchemaFiles, new ServerSchemaElement(attributeType), new ServerSchemaElement(existingType)); |
| | | schema.replaceAttributeType(attributeType, existingType, schemaFile); |
| | | } |
| | | } |
| | |
| | | modifiedSchemaFiles.add(schemaFile); |
| | | } |
| | | |
| | | /** Update list of modified files and return the schema file to use for the added element (may be null). */ |
| | | private String addNewSchemaElement(Set<String> modifiedSchemaFiles, SomeSchemaElement elem) |
| | | { |
| | | String schemaFile = elem.getSchemaFile(); |
| | | String finalFile = schemaFile != null ? schemaFile : FILE_USER_SCHEMA_ELEMENTS; |
| | | modifiedSchemaFiles.add(finalFile); |
| | | return schemaFile == null ? finalFile : null; |
| | | } |
| | | |
| | | /** |
| | | * Update list of modified files and return the schema file to use for the |
| | | * added element (may be null). |
| | |
| | | } |
| | | } |
| | | |
| | | /** Update list of modified files and return the schema file to use for the new element (may be null). */ |
| | | private String replaceExistingSchemaElement( |
| | | Set<String> modifiedSchemaFiles, SomeSchemaElement newElem, SomeSchemaElement existingElem) |
| | | { |
| | | String newSchemaFile = newElem.getSchemaFile(); |
| | | String oldSchemaFile = existingElem.getSchemaFile(); |
| | | if (newSchemaFile == null) |
| | | { |
| | | if (oldSchemaFile == null) |
| | | { |
| | | oldSchemaFile = FILE_USER_SCHEMA_ELEMENTS; |
| | | } |
| | | modifiedSchemaFiles.add(oldSchemaFile); |
| | | return oldSchemaFile; |
| | | } |
| | | else if (oldSchemaFile == null || oldSchemaFile.equals(newSchemaFile)) |
| | | { |
| | | modifiedSchemaFiles.add(newSchemaFile); |
| | | } |
| | | else |
| | | { |
| | | modifiedSchemaFiles.add(newSchemaFile); |
| | | modifiedSchemaFiles.add(oldSchemaFile); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * Update list of modified files and return the schema file to use for the new |
| | | * element (may be null). |
| | |
| | | } |
| | | } |
| | | |
| | | // Make sure that the attribute type isn't used as a required or optional |
| | | // attribute type in any objectclass. |
| | | for (ObjectClass oc : schema.getObjectClasses()) |
| | | { |
| | | if (oc.getDeclaredRequiredAttributes().contains(removeType) || |
| | | (oc.getDeclaredOptionalAttributes().contains(removeType) && !oc.isExtensible())) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_REMOVE_AT_IN_OC.get( |
| | | removeType.getNameOrOID(), oc.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | } |
| | | |
| | | // Make sure that the attribute type isn't used as a required or optional |
| | | // attribute type in any name form. |
| | | for (List<NameForm> mappedForms : |
| | | schema.getNameFormsByObjectClass().values()) |
| | | { |
| | | for(NameForm nf : mappedForms) |
| | | { |
| | | if (nf.getRequiredAttributes().contains(removeType) || |
| | | nf.getOptionalAttributes().contains(removeType)) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_REMOVE_AT_IN_NF.get( |
| | | removeType.getNameOrOID(), nf.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, |
| | | message); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // Make sure that the attribute type isn't used as a required, optional, or |
| | | // prohibited attribute type in any DIT content rule. |
| | | for (DITContentRule dcr : schema.getDITContentRules().values()) |
| | |
| | | // If we've gotten here, then it's OK to remove the attribute type from |
| | | // the schema. |
| | | schema.deregisterAttributeType(removeType); |
| | | String schemaFile = new SomeSchemaElement(removeType).getSchemaFile(); |
| | | String schemaFile = new ServerSchemaElement(removeType).getSchemaFile(); |
| | | if (schemaFile != null) |
| | | { |
| | | modifiedSchemaFiles.add(schemaFile); |
| | |
| | | // Otherwise, we're replacing an existing one. |
| | | if (existingClass.isPlaceHolder()) |
| | | { |
| | | String schemaFile = addNewSchemaElement(modifiedSchemaFiles, new SomeSchemaElement(objectClass)); |
| | | String schemaFile = addNewSchemaElement(modifiedSchemaFiles, new ServerSchemaElement(objectClass)); |
| | | schema.registerObjectClass(objectClass, schemaFile, false); |
| | | } |
| | | else |
| | | { |
| | | final String schemaFile = replaceExistingSchemaElement( |
| | | modifiedSchemaFiles, new SomeSchemaElement(objectClass), new SomeSchemaElement(existingClass)); |
| | | modifiedSchemaFiles, new ServerSchemaElement(objectClass), new ServerSchemaElement(existingClass)); |
| | | schema.replaceObjectClass(objectClass, existingClass, schemaFile); |
| | | } |
| | | } |
| | |
| | | |
| | | // Make sure that the objectclass isn't used as the structural class for |
| | | // any name form. |
| | | List<NameForm> mappedForms = schema.getNameForm(removeClass); |
| | | if (mappedForms != null) |
| | | Collection<NameForm> mappedForms = schema.getNameForm(removeClass); |
| | | if (!mappedForms.isEmpty()) |
| | | { |
| | | StringBuilder buffer = new StringBuilder(); |
| | | for(NameForm nf : mappedForms) |
| | |
| | | Set<String> modifiedSchemaFiles) |
| | | throws DirectoryException |
| | | { |
| | | // First, see if the specified name form already exists. We'll check the |
| | | // OID and all of the names, which means that it's possible there could be |
| | | // more than one match (although if there is, then we'll refuse the |
| | | // operation). |
| | | NameForm existingNF = |
| | | schema.getNameForm(nameForm.getOID()); |
| | | for (String name : nameForm.getNames().keySet()) |
| | | { |
| | | NameForm nf = schema.getNameForm(name); |
| | | if (nf == null) |
| | | { |
| | | continue; |
| | | } |
| | | else if (existingNF == null) |
| | | { |
| | | existingNF = nf; |
| | | } |
| | | else if (existingNF != nf) |
| | | { |
| | | // NOTE: We really do want to use "!=" instead of "! t.equals()" |
| | | // because we want to check whether it's the same object instance, not |
| | | // just a logical equivalent. |
| | | LocalizableMessage message = |
| | | ERR_SCHEMA_MODIFY_MULTIPLE_CONFLICTS_FOR_ADD_NAME_FORM |
| | | .get(nameForm.getNameOrOID(), existingNF.getNameOrOID(), |
| | | nf.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | } |
| | | |
| | | // Make sure that the new name form doesn't reference an undefined |
| | | // structural class, or an undefined required or optional attribute type, or |
| | | // that any of them are marked OBSOLETE. |
| | | // Make sure that the new name form doesn't reference an objectclass |
| | | // or attributes that are marked OBSOLETE. |
| | | ObjectClass structuralClass = nameForm.getStructuralClass(); |
| | | if (! schema.hasObjectClass(structuralClass.getOID())) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_NF_UNDEFINED_STRUCTURAL_OC.get( |
| | | nameForm.getNameOrOID(), structuralClass.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | if (structuralClass.getObjectClassType() != ObjectClassType.STRUCTURAL) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_NF_OC_NOT_STRUCTURAL.get( |
| | | nameForm.getNameOrOID(), structuralClass.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | if (structuralClass.isObsolete()) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_NF_OC_OBSOLETE.get( |
| | |
| | | |
| | | for (AttributeType at : nameForm.getRequiredAttributes()) |
| | | { |
| | | if (! schema.hasAttributeType(at.getOID())) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_NF_UNDEFINED_REQUIRED_ATTR.get( |
| | | nameForm.getNameOrOID(), at.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | else if (at.isObsolete()) |
| | | if (at.isObsolete()) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_NF_OBSOLETE_REQUIRED_ATTR.get( |
| | | nameForm.getNameOrOID(), at.getNameOrOID()); |
| | |
| | | |
| | | for (AttributeType at : nameForm.getOptionalAttributes()) |
| | | { |
| | | if (! schema.hasAttributeType(at.getOID())) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_NF_UNDEFINED_OPTIONAL_ATTR.get( |
| | | nameForm.getNameOrOID(), at.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | else if (at.isObsolete()) |
| | | if (at.isObsolete()) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_NF_OBSOLETE_OPTIONAL_ATTR.get( |
| | | nameForm.getNameOrOID(), at.getNameOrOID()); |
| | |
| | | |
| | | // If there is no existing class, then we're adding a new name form. |
| | | // Otherwise, we're replacing an existing one. |
| | | if (existingNF == null) |
| | | if (!schema.hasNameForm(nameForm.getNameOrOID())) |
| | | { |
| | | schema.registerNameForm(nameForm, false); |
| | | addNewSchemaElement(modifiedSchemaFiles, nameForm); |
| | | String schemaFile = addNewSchemaElement(modifiedSchemaFiles, new ServerSchemaElement(nameForm)); |
| | | schema.registerNameForm(nameForm, schemaFile, false); |
| | | } |
| | | else |
| | | { |
| | | NameForm existingNF = schema.getNameForm(nameForm.getNameOrOID()); |
| | | schema.deregisterNameForm(existingNF); |
| | | schema.registerNameForm(nameForm, false); |
| | | String schemaFile = replaceExistingSchemaElement( |
| | | modifiedSchemaFiles, new ServerSchemaElement(nameForm), new ServerSchemaElement(existingNF)); |
| | | schema.registerNameForm(nameForm, schemaFile, false); |
| | | schema.rebuildDependentElements(existingNF); |
| | | replaceExistingSchemaElement(modifiedSchemaFiles, nameForm, existingNF); |
| | | } |
| | | } |
| | | |
| | |
| | | Set<String> modifiedSchemaFiles) |
| | | throws DirectoryException |
| | | { |
| | | // See if the specified name form is actually defined in the server schema. |
| | | // If not, then fail. |
| | | NameForm removeNF = schema.getNameForm(nameForm.getOID()); |
| | | if (removeNF == null || !removeNF.equals(nameForm)) |
| | | if (!schema.hasNameForm(nameForm.getOID())) |
| | | { |
| | | LocalizableMessage message = ERR_SCHEMA_MODIFY_REMOVE_NO_SUCH_NAME_FORM.get( |
| | | nameForm.getNameOrOID()); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, |
| | | ERR_SCHEMA_MODIFY_REMOVE_NO_SUCH_NAME_FORM.get(nameForm.getNameOrOID())); |
| | | } |
| | | |
| | | NameForm removeNF = schema.getNameForm(nameForm.getOID()); |
| | | |
| | | // See if there is another modification later to add the name form back |
| | | // into the schema. If so, then it's a replace and we should ignore the |
| | | // remove because adding it back will handle the replace. |
| | |
| | | NameForm nf; |
| | | try |
| | | { |
| | | nf = NameFormSyntax.decodeNameForm(v, schema, true); |
| | | nf = schema.parseNameForm(v.toString()); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | // Make sure that the name form isn't referenced by any DIT structure |
| | | // rule. |
| | | // Make sure that the name form isn't referenced by any DIT structure rule. |
| | | DITStructureRule dsr = schema.getDITStructureRule(removeNF); |
| | | if (dsr != null) |
| | | { |
| | |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | } |
| | | |
| | | // If we've gotten here, then it's OK to remove the name form from the |
| | | // schema. |
| | | // If we've gotten here, then it's OK to remove the name form from the schema. |
| | | schema.deregisterNameForm(removeNF); |
| | | String schemaFile = getSchemaFile(removeNF); |
| | | if (schemaFile != null) |
| | |
| | | values = new LinkedHashSet<>(); |
| | | for (AttributeType at : schema.getAttributeTypes()) |
| | | { |
| | | String atSchemaFile = new SomeSchemaElement(at).getSchemaFile(); |
| | | String atSchemaFile = new ServerSchemaElement(at).getSchemaFile(); |
| | | if (schemaFile.equals(atSchemaFile)) |
| | | { |
| | | addAttrTypeToSchemaFile(schema, schemaFile, at, values, addedTypes, 0); |
| | |
| | | // is no hierarchical relationship between name forms, we don't need to |
| | | // worry about ordering. |
| | | values = new LinkedHashSet<>(); |
| | | for (List<NameForm> forms : schema.getNameFormsByObjectClass().values()) |
| | | for (NameForm nf : schema.getNameForms()) |
| | | { |
| | | for(NameForm nf : forms) |
| | | if (schemaFile.equals(getSchemaFile(nf))) |
| | | { |
| | | if (schemaFile.equals(getSchemaFile(nf))) |
| | | { |
| | | values.add(ByteString.valueOfUtf8(nf.toString())); |
| | | } |
| | | values.add(ByteString.valueOfUtf8(nf.toString())); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | AttributeType superiorType = attributeType.getSuperiorType(); |
| | | if (superiorType != null && |
| | | schemaFile.equals(new SomeSchemaElement(attributeType).getSchemaFile()) && |
| | | schemaFile.equals(new ServerSchemaElement(attributeType).getSchemaFile()) && |
| | | !addedTypes.contains(superiorType)) |
| | | { |
| | | addAttrTypeToSchemaFile(schema, schemaFile, superiorType, values, |
| | |
| | | { |
| | | // Parse the attribute type. |
| | | AttributeType attrType = schema.parseAttributeType(v.toString()); |
| | | String schemaFile = new SomeSchemaElement(attrType).getSchemaFile(); |
| | | String schemaFile = new ServerSchemaElement(attrType).getSchemaFile(); |
| | | if (CONFIG_SCHEMA_ELEMENTS_FILE.equals(schemaFile)) |
| | | { |
| | | // Don't import the file containing the definitions of the |