Issue 4116 :Provide implementation for regex syntax
| | |
| | | MILD_WARN_ATTR_SYNTAX_LDAPSYNTAX_UNKNOWN_EXT_306=The provided value "%s" \ |
| | | could not be parsed as an ldap syntax because it contains an unrecognized \ |
| | | extension %s at position %d |
| | | |
| | | MILD_WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_INVALID_VALUE_307=The provided value \ |
| | | "%s" cannot be parsed as a valid regex syntax because it does not match \ |
| | | the pattern "%s" |
| | | MILD_WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_NO_PATTERN_308=The provided value "%s" \ |
| | | could not be parsed as a regex syntax because it does not contain a regex pattern |
| | | MILD_WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_INVALID_PATTERN_309=The provided value \ |
| | | "%s" could not be parsed as a regex syntax because the provided regex \ |
| | | pattern "%s" is invalid |
| | |
| | | LinkedHashSet<String> newDCRs = new LinkedHashSet<String>(); |
| | | LinkedHashSet<String> newDSRs = new LinkedHashSet<String>(); |
| | | LinkedHashSet<String> newMRUs = new LinkedHashSet<String>(); |
| | | LinkedHashSet<String> newLSDs = new LinkedHashSet<String>(); |
| | | Schema.genConcatenatedSchema(newATs, newOCs, newNFs, newDCRs, newDSRs, |
| | | newMRUs); |
| | | newMRUs,newLSDs); |
| | | |
| | | // Next, generate lists of elements from the previous concatenated schema. |
| | | // If there isn't a previous concatenated schema, then use the base |
| | |
| | | LinkedHashSet<String> oldDCRs = new LinkedHashSet<String>(); |
| | | LinkedHashSet<String> oldDSRs = new LinkedHashSet<String>(); |
| | | LinkedHashSet<String> oldMRUs = new LinkedHashSet<String>(); |
| | | LinkedHashSet<String> oldLSDs = new LinkedHashSet<String>(); |
| | | Schema.readConcatenatedSchema(concatFilePath, oldATs, oldOCs, oldNFs, |
| | | oldDCRs, oldDSRs, oldMRUs); |
| | | oldDCRs, oldDSRs, oldMRUs,oldLSDs); |
| | | |
| | | // Create a list of modifications and add any differences between the old |
| | | // and new schema into them. |
| | |
| | | mods); |
| | | Schema.compareConcatenatedSchema(oldMRUs, newMRUs, matchingRuleUsesType, |
| | | mods); |
| | | Schema.compareConcatenatedSchema(oldLSDs, newLSDs, ldapSyntaxesType, |
| | | mods); |
| | | if (! mods.isEmpty()) |
| | | { |
| | | DirectoryServer.setOfflineSchemaChanges(mods); |
| | |
| | | // Start with an empty schema entry. |
| | | Entry schemaEntry = createEmptySchemaEntry(); |
| | | |
| | | /** |
| | | * Add all of the ldap syntax descriptions to the schema entry. We do |
| | | * this only for the real part of the ldapsyntaxes attribute. The real part |
| | | * is read and write to/from the schema files. |
| | | */ |
| | | LinkedHashSet<AttributeValue> values = new LinkedHashSet<AttributeValue>(); |
| | | for (LDAPSyntaxDescription ldapSyntax : |
| | | schema.getLdapSyntaxDescriptions().values()) |
| | | { |
| | | if(schemaFile.equals(ldapSyntax.getSchemaFile())) |
| | | { |
| | | values.add(AttributeValues.create(ldapSyntaxesType, |
| | | ldapSyntax.getDefinition())); |
| | | } |
| | | } |
| | | |
| | | if (! values.isEmpty()) |
| | | { |
| | | ArrayList<Attribute> attrList = new ArrayList<Attribute>(1); |
| | | AttributeBuilder builder = new AttributeBuilder(ldapSyntaxesType); |
| | | builder.addAll(values); |
| | | attrList.add(builder.toAttribute()); |
| | | schemaEntry.putAttribute(ldapSyntaxesType, attrList); |
| | | } |
| | | |
| | | // Add all of the appropriate attribute types to the schema entry. We need |
| | | // to be careful of the ordering to ensure that any superior types in the |
| | | // same file are written before the subordinate types. |
| | | HashSet<AttributeType> addedTypes = new HashSet<AttributeType>(); |
| | | LinkedHashSet<AttributeValue> values = new LinkedHashSet<AttributeValue>(); |
| | | values = new LinkedHashSet<AttributeValue>(); |
| | | for (AttributeType at : schema.getAttributeTypes().values()) |
| | | { |
| | | if (schemaFile.equals(at.getSchemaFile())) |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Add all of the ldap syntax descriptions to the schema entry. We do |
| | | * this only for the real part of the ldapsyntaxes attribute. The real part |
| | | * is read and write to/from the schema files. |
| | | */ |
| | | values = new LinkedHashSet<AttributeValue>(); |
| | | for (LDAPSyntaxDescription ldapSyntax : |
| | | schema.getLdapSyntaxDescriptions().values()) |
| | | { |
| | | if(schemaFile.equals(ldapSyntax.getSchemaFile())) |
| | | { |
| | | values.add(AttributeValues.create(ldapSyntaxesType, |
| | | ldapSyntax.getDefinition())); |
| | | } |
| | | } |
| | | |
| | | if (! values.isEmpty()) |
| | | { |
| | | ArrayList<Attribute> attrList = new ArrayList<Attribute>(1); |
| | | AttributeBuilder builder = new AttributeBuilder(ldapSyntaxesType); |
| | | builder.addAll(values); |
| | | attrList.add(builder.toAttribute()); |
| | | schemaEntry.putAttribute(attributeTypesType, attrList); |
| | | } |
| | | |
| | | |
| | | if (schemaFile.equals(FILE_USER_SCHEMA_ELEMENTS)) |
| | | { |
| | | Map<String, Attribute> attributes = schema.getExtraAttributes(); |
| | |
| | | |
| | | // Get the attributeTypes attribute from the entry. |
| | | LinkedList<Modification> mods = new LinkedList<Modification>(); |
| | | //parse the syntaxes first because attributes rely on these. |
| | | LDAPSyntaxDescriptionSyntax ldapSyntax; |
| | | try |
| | | { |
| | | ldapSyntax = (LDAPSyntaxDescriptionSyntax) schema.getSyntax( |
| | | SYNTAX_LDAP_SYNTAX_OID); |
| | | if (ldapSyntax == null) |
| | | { |
| | | ldapSyntax = new LDAPSyntaxDescriptionSyntax(); |
| | | ldapSyntax.initializeSyntax(null); |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | ldapSyntax = new LDAPSyntaxDescriptionSyntax(); |
| | | ldapSyntax.initializeSyntax(null); |
| | | } |
| | | |
| | | AttributeType ldapSyntaxAttrType = |
| | | schema.getAttributeType(ATTR_LDAP_SYNTAXES_LC); |
| | | if (ldapSyntaxAttrType == null) |
| | | { |
| | | ldapSyntaxAttrType = |
| | | DirectoryServer.getDefaultAttributeType(ATTR_LDAP_SYNTAXES, |
| | | ldapSyntax); |
| | | } |
| | | |
| | | List<Attribute> ldapSyntaxList = entry.getAttribute(ldapSyntaxAttrType); |
| | | if ((ldapSyntaxList != null) && (! ldapSyntaxList.isEmpty())) |
| | | { |
| | | for (Attribute a : ldapSyntaxList) |
| | | { |
| | | mods.add(new Modification(ModificationType.ADD, a)); |
| | | } |
| | | } |
| | | |
| | | AttributeTypeSyntax attrTypeSyntax; |
| | | try |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | // Get the ldapsyntaxes attribute from the entry. |
| | | LDAPSyntaxDescriptionSyntax ldapSyntax; |
| | | // Loop on all the attribute of the schema entry to |
| | | // find the extra attribute that shoule be loaded in the Schema. |
| | | for (Attribute attribute : entry.getAttributes()) |
| | | { |
| | | if (!isSchemaAttribute(attribute)) |
| | | { |
| | | schema.addExtraAttribute(attribute.getName(), attribute); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // Parse the ldapsyntaxes definitions if there are any. |
| | | if (ldapSyntaxList != null) |
| | | { |
| | | for (Attribute a : ldapSyntaxList) |
| | | { |
| | | for (AttributeValue v : a) |
| | | { |
| | | LDAPSyntaxDescription syntaxDescription = null; |
| | | try |
| | | { |
| | | ldapSyntax = (LDAPSyntaxDescriptionSyntax) schema.getSyntax( |
| | | SYNTAX_LDAP_SYNTAX_OID); |
| | | if (ldapSyntax == null) |
| | | syntaxDescription = LDAPSyntaxDescriptionSyntax.decodeLDAPSyntax( |
| | | v.getValue(),schema,false); |
| | | syntaxDescription.setExtraProperty( |
| | | SCHEMA_PROPERTY_FILENAME, (String) null); |
| | | syntaxDescription.setSchemaFile(schemaFile); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | ldapSyntax = new LDAPSyntaxDescriptionSyntax(); |
| | | ldapSyntax.initializeSyntax(null); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | } |
| | | |
| | | Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get( |
| | | schemaFile, |
| | | de.getMessageObject()); |
| | | |
| | | if (failOnError) |
| | | { |
| | | throw new ConfigException(message, de); |
| | | } |
| | | else |
| | | { |
| | | logError(message); |
| | | continue; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | ldapSyntax = new LDAPSyntaxDescriptionSyntax(); |
| | | ldapSyntax.initializeSyntax(null); |
| | | } |
| | | Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get( |
| | | schemaFile, |
| | | v.getValue().toString() + ": " + getExceptionMessage(e)); |
| | | |
| | | AttributeType ldapSyntaxAttrType = |
| | | schema.getAttributeType(ATTR_LDAP_SYNTAXES_LC); |
| | | if (ldapSyntaxAttrType == null) |
| | | if (failOnError) |
| | | { |
| | | ldapSyntaxAttrType = |
| | | DirectoryServer.getDefaultAttributeType(ATTR_LDAP_SYNTAXES, |
| | | ldapSyntax); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | |
| | | List<Attribute> ldapSyntaxList = entry.getAttribute(ldapSyntaxAttrType); |
| | | if ((ldapSyntaxList != null) && (! ldapSyntaxList.isEmpty())) |
| | | else |
| | | { |
| | | for (Attribute a : ldapSyntaxList) |
| | | { |
| | | mods.add(new Modification(ModificationType.ADD, a)); |
| | | logError(message); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | // Loop on all the attribute of the schema entry to |
| | | // find the extra attribute that shoule be loaded in the Schema. |
| | | for (Attribute attribute : entry.getAttributes()) |
| | | // Register it with the schema. We will allow duplicates, with the |
| | | // later definition overriding any earlier definition, but we want |
| | | // to trap them and log a warning. |
| | | try |
| | | { |
| | | if (!isSchemaAttribute(attribute)) |
| | | schema.registerLdapSyntaxDescription( |
| | | syntaxDescription, failOnError); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | schema.addExtraAttribute(attribute.getName(), attribute); |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | } |
| | | |
| | | Message message = WARN_CONFIG_SCHEMA_CONFLICTING_LDAP_SYNTAX.get( |
| | | schemaFile, de.getMessageObject()); |
| | | logError(message); |
| | | |
| | | try |
| | | { |
| | | schema.registerLdapSyntaxDescription(syntaxDescription, true); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | // This should never happen. |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // Parse the ldapsyntaxes definitions if there are any. |
| | | if (ldapSyntaxList != null) |
| | | { |
| | | for (Attribute a : ldapSyntaxList) |
| | | { |
| | | for (AttributeValue v : a) |
| | | { |
| | | LDAPSyntaxDescription syntaxDescription = null; |
| | | try |
| | | { |
| | | syntaxDescription = LDAPSyntaxDescriptionSyntax.decodeLDAPSyntax( |
| | | v.getValue(),schema,false); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | } |
| | | |
| | | Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get( |
| | | schemaFile, |
| | | de.getMessageObject()); |
| | | |
| | | if (failOnError) |
| | | { |
| | | throw new ConfigException(message, de); |
| | | } |
| | | else |
| | | { |
| | | logError(message); |
| | | continue; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | Message message = WARN_CONFIG_SCHEMA_CANNOT_PARSE_LDAP_SYNTAX.get( |
| | | schemaFile, |
| | | v.getValue().toString() + ": " + getExceptionMessage(e)); |
| | | |
| | | if (failOnError) |
| | | { |
| | | throw new ConfigException(message, e); |
| | | } |
| | | else |
| | | { |
| | | logError(message); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | // Register it with the schema. We will allow duplicates, with the |
| | | // later definition overriding any earlier definition, but we want |
| | | // to trap them and log a warning. |
| | | try |
| | | { |
| | | schema.registerLdapSyntaxDescription( |
| | | syntaxDescription, failOnError); |
| | | } |
| | | catch (DirectoryException de) |
| | | { |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, de); |
| | | } |
| | | |
| | | Message message = WARN_CONFIG_SCHEMA_CONFLICTING_LDAP_SYNTAX.get( |
| | | schemaFile, de.getMessageObject()); |
| | | logError(message); |
| | | |
| | | try |
| | | { |
| | | schema.registerLdapSyntaxDescription(syntaxDescription, true); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | // This should never happen. |
| | | if (debugEnabled()) |
| | | { |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | return mods; |
| | | } |
| | | |
| | |
| | | attributeOid.equals("1.3.6.1.4.1.1466.101.120.16") || |
| | | attributeOid.equals("attributetypes-oid") || |
| | | attributeOid.equals("objectclasses-oid") || |
| | | attributeOid.equals("matchingRules-oid") || |
| | | attributeOid.equals("matchingRuleUse-oid") || |
| | | attributeOid.equals("NameFormDescription-oid") || |
| | | attributeOid.equals("dITContentRules-oid") || |
| | | attributeOid.equals("dITStructureRules") || |
| | | attributeOid.equals("ldapSyntaxes-oid") |
| | | attributeOid.equals("matchingrules-oid") || |
| | | attributeOid.equals("matchingruleuse-oid") || |
| | | attributeOid.equals("nameformdescription-oid") || |
| | | attributeOid.equals("ditcontentrules-oid") || |
| | | attributeOid.equals("ditstructurerules-oid") || |
| | | attributeOid.equals("ldapsyntaxes-oid") |
| | | |
| | | ) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | import java.util.regex.Pattern; |
| | | |
| | | import org.opends.server.admin.std.server.AttributeSyntaxCfg; |
| | | import org.opends.server.api.ApproximateMatchingRule; |
| | | import org.opends.server.api.AttributeSyntax; |
| | |
| | | String oid = oidBuffer.toString(); |
| | | String description = descriptionBuffer.toString(); |
| | | StringBuilder extBuffer = new StringBuilder(); |
| | | //Attribute syntax which will sustitute the syntax with oid. |
| | | AttributeSyntax subSyntax = null; |
| | | LDAPSyntaxDescriptionSyntax syntax = null; |
| | | |
| | | pos = readTokenName(valueStr, extBuffer, pos); |
| | | String lowerTokenName = toLowerCase(extBuffer.toString()); |
| | |
| | | StringBuilder woidBuffer = new StringBuilder(); |
| | | pos = readQuotedString(lowerStr, woidBuffer, pos); |
| | | String syntaxOID = woidBuffer.toString(); |
| | | subSyntax = schema.getSyntax(syntaxOID); |
| | | AttributeSyntax subSyntax = schema.getSyntax(syntaxOID); |
| | | if(subSyntax == null) |
| | | { |
| | | Message message = WARN_ATTR_SYNTAX_ATTRTYPE_UNKNOWN_SYNTAX.get( |
| | |
| | | throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION, |
| | | message); |
| | | } |
| | | syntax = new SubstitutionSyntax(subSyntax,description,oid); |
| | | } |
| | | else if(lowerTokenName.equals("x-pattern")) |
| | | { |
| | | StringBuilder regexBuffer = new StringBuilder(); |
| | | pos = readQuotedString(valueStr, regexBuffer, pos); |
| | | String regex = regexBuffer.toString(); |
| | | if(regex == null) |
| | | { |
| | | Message message = WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_NO_PATTERN.get( |
| | | valueStr); |
| | | throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, |
| | | message); |
| | | } |
| | | |
| | | try |
| | | { |
| | | Pattern pattern = Pattern.compile(regex); |
| | | syntax = new RegexSyntax(pattern,description,oid); |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | Message message = WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_INVALID_PATTERN.get |
| | | (valueStr,regex); |
| | | throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, |
| | | message); |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | LDAPSyntaxDescription syntaxDesc = null; |
| | | //Since we reached here it means everything is OK. |
| | | if(subSyntax !=null) |
| | | { |
| | | //A SubstitutionSyntax is requested. |
| | | syntaxDesc = new LDAPSyntaxDescription(valueStr, |
| | | new SubstitutionSyntax(subSyntax,description,oid), |
| | | description,null); |
| | | } |
| | | return syntaxDesc; |
| | | return new LDAPSyntaxDescription(valueStr,syntax,description,null); |
| | | } |
| | | |
| | | |
| | |
| | | return subSyntax.getApproximateMatchingRule(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class provides a regex mechanism where a new syntax and its |
| | | * corresponding matching rules can be created on-the-fly. A regex |
| | | * syntax is an LDAPSyntaxDescriptionSyntax with X-PATTERN extension. |
| | | */ |
| | | private static class RegexSyntax extends |
| | | LDAPSyntaxDescriptionSyntax |
| | | { |
| | | // The Pattern associated with the regex. |
| | | private Pattern pattern; |
| | | |
| | | // The description of this syntax. |
| | | private String description; |
| | | |
| | | //The oid of this syntax. |
| | | private String oid; |
| | | |
| | | //The equality matching rule. |
| | | private EqualityMatchingRule equalityMatchingRule; |
| | | |
| | | //The substring matching rule. |
| | | private SubstringMatchingRule substringMatchingRule; |
| | | |
| | | //The ordering matching rule. |
| | | private OrderingMatchingRule orderingMatchingRule; |
| | | |
| | | //The approximate matching rule. |
| | | private ApproximateMatchingRule approximateMatchingRule; |
| | | |
| | | |
| | | //Creates a new instance of this syntax. |
| | | private RegexSyntax(Pattern pattern, |
| | | String description, |
| | | String oid) |
| | | { |
| | | super(); |
| | | this.pattern = pattern; |
| | | this.description = description; |
| | | this.oid = oid; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getSyntaxName() |
| | | { |
| | | // There is no name for a regex syntax. |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getOID() |
| | | { |
| | | return oid; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public String getDescription() |
| | | { |
| | | return description; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean valueIsAcceptable(ByteSequence value, |
| | | MessageBuilder invalidReason) |
| | | { |
| | | String strValue = value.toString(); |
| | | boolean matches = pattern.matcher(strValue).matches(); |
| | | if(!matches) |
| | | { |
| | | Message message = WARN_ATTR_SYNTAX_LDAPSYNTAX_REGEX_INVALID_VALUE.get( |
| | | strValue,pattern.pattern()); |
| | | invalidReason.append(message); |
| | | } |
| | | return matches; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the default equality matching rule that will be used for |
| | | * attributes with this syntax. |
| | | * |
| | | * @return The default equality matching rule that will be used for |
| | | * attributes with this syntax, or <CODE>null</CODE> if equality |
| | | * matches will not be allowed for this type by default. |
| | | */ |
| | | @Override |
| | | public EqualityMatchingRule getEqualityMatchingRule() |
| | | { |
| | | if(equalityMatchingRule == null) |
| | | { |
| | | //This has already been verified. |
| | | equalityMatchingRule = |
| | | DirectoryServer.getEqualityMatchingRule(EMR_CASE_IGNORE_OID); |
| | | } |
| | | return equalityMatchingRule; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the default ordering matching rule that will be used for |
| | | * attributes with this syntax. |
| | | * |
| | | * @return The default ordering matching rule that will be used for |
| | | * attributes with this syntax, or <CODE>null</CODE> if ordering |
| | | * matches will not be allowed for this type by default. |
| | | */ |
| | | @Override |
| | | public OrderingMatchingRule getOrderingMatchingRule() |
| | | { |
| | | if(orderingMatchingRule == null) |
| | | { |
| | | orderingMatchingRule = |
| | | DirectoryServer.getOrderingMatchingRule(OMR_CASE_IGNORE_OID); |
| | | } |
| | | return orderingMatchingRule; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the default substring matching rule that will be used for |
| | | * attributes with this syntax. |
| | | * |
| | | * @return The default substring matching rule that will be used for |
| | | * attributes with this syntax, or <CODE>null</CODE> if substring |
| | | * matches will not be allowed for this type by default. |
| | | */ |
| | | @Override |
| | | public SubstringMatchingRule getSubstringMatchingRule() |
| | | { |
| | | if(substringMatchingRule == null) |
| | | { |
| | | substringMatchingRule = |
| | | DirectoryServer.getSubstringMatchingRule(SMR_CASE_IGNORE_OID); |
| | | } |
| | | return substringMatchingRule; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the default approximate matching rule that will be used for |
| | | * attributes with this syntax. |
| | | * |
| | | * @return The default approximate matching rule that will be used for |
| | | * attributes with this syntax, or <CODE>null</CODE> if approximate |
| | | * matches will not be allowed for this type by default. |
| | | */ |
| | | @Override |
| | | public ApproximateMatchingRule getApproximateMatchingRule() |
| | | { |
| | | if(approximateMatchingRule == null) |
| | | { |
| | | approximateMatchingRule = |
| | | DirectoryServer.getApproximateMatchingRule( |
| | | AMR_DOUBLE_METAPHONE_OID); |
| | | } |
| | | return approximateMatchingRule; |
| | | } |
| | | } |
| | | } |
| | |
| | | new LinkedHashSet<String>(); |
| | | LinkedHashSet<String> matchingRuleUses = |
| | | new LinkedHashSet<String>(); |
| | | LinkedHashSet<String> ldapSyntaxes = |
| | | new LinkedHashSet<String>(); |
| | | genConcatenatedSchema(attributeTypes, objectClasses, nameForms, |
| | | ditContentRules, ditStructureRules, |
| | | matchingRuleUses); |
| | | matchingRuleUses,ldapSyntaxes); |
| | | |
| | | |
| | | File configFile = new File(DirectoryServer.getConfigFile()); |
| | |
| | | writer.newLine(); |
| | | } |
| | | |
| | | |
| | | for (String line : ldapSyntaxes) |
| | | { |
| | | writer.write(ATTR_LDAP_SYNTAXES); |
| | | writer.write(": "); |
| | | writer.write(line); |
| | | writer.newLine(); |
| | | } |
| | | |
| | | writer.close(); |
| | | |
| | | if (concatFile.exists()) |
| | |
| | | * @param matchingRuleUses The set into which to place the |
| | | * matching rule uses read from the |
| | | * schema files. |
| | | * @param ldapSyntaxes The set into which to place the |
| | | * ldap syntaxes read from the |
| | | * schema files. |
| | | * |
| | | * @throws IOException If a problem occurs while reading the |
| | | * schema file elements. |
| | |
| | | LinkedHashSet<String> nameForms, |
| | | LinkedHashSet<String> ditContentRules, |
| | | LinkedHashSet<String> ditStructureRules, |
| | | LinkedHashSet<String> matchingRuleUses) |
| | | LinkedHashSet<String> matchingRuleUses, |
| | | LinkedHashSet<String> ldapSyntaxes) |
| | | throws IOException |
| | | { |
| | | // Get a sorted list of the files in the schema directory. |
| | |
| | | ATTR_MATCHING_RULE_USE.length()+1).trim(); |
| | | matchingRuleUses.add(value); |
| | | } |
| | | else if(lowerLine.startsWith(ATTR_LDAP_SYNTAXES_LC)) |
| | | { |
| | | value = line.substring( |
| | | ATTR_LDAP_SYNTAXES.length()+1).trim(); |
| | | ldapSyntaxes.add(value); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | * @param matchingRuleUses The set into which to place the |
| | | * matching rule uses read from the |
| | | * concatenated schema file. |
| | | * @param ldapSyntaxes The set into which to place the |
| | | * ldap syntaxes read from the |
| | | * concatenated schema file. |
| | | * |
| | | * @throws IOException If a problem occurs while reading the |
| | | * schema file elements. |
| | |
| | | LinkedHashSet<String> nameForms, |
| | | LinkedHashSet<String> ditContentRules, |
| | | LinkedHashSet<String> ditStructureRules, |
| | | LinkedHashSet<String> matchingRuleUses) |
| | | LinkedHashSet<String> matchingRuleUses, |
| | | LinkedHashSet<String> ldapSyntaxes) |
| | | throws IOException |
| | | { |
| | | BufferedReader reader = |
| | |
| | | ATTR_MATCHING_RULE_USE.length()+1).trim(); |
| | | matchingRuleUses.add(value); |
| | | } |
| | | else if (lowerLine.startsWith(ATTR_LDAP_SYNTAXES_LC)) |
| | | { |
| | | value = line.substring( |
| | | ATTR_LDAP_SYNTAXES.length()+1).trim(); |
| | | ldapSyntaxes.add(value); |
| | | } |
| | | } |
| | | |
| | | reader.close(); |
| | |
| | | extensibleMatchingRules = null; |
| | | } |
| | | |
| | | if(ldapSyntaxDescriptions != null) |
| | | { |
| | | ldapSyntaxDescriptions.clear(); |
| | | ldapSyntaxDescriptions = null; |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | import java.util.List; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.api.AttributeSyntax; |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.DereferencePolicy; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.ResultCode; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.types.SearchScope; |
| | |
| | | @Test() |
| | | public void testSubstitutionSyntaxForInvalidSubstitution() throws Exception |
| | | { |
| | | |
| | | try |
| | | { |
| | | //Test if we can substitute a directory string syntax by itself. |
| | |
| | | * |
| | | * @throws java.lang.Exception |
| | | */ |
| | | @Test() |
| | | public void testSubsitutionSyntaxAddValues() throws Exception |
| | | { |
| | | try |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests whether it is possible to add values after a regex syntax |
| | | * has been added. |
| | | * |
| | | * @throws java.lang.Exception |
| | | */ |
| | | @Test() |
| | | public void testRegexSyntaxAddValues() throws Exception |
| | | { |
| | | try |
| | | { |
| | | addRegexSyntax(); |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | //This addition should fail because it doesn't match the pattern. |
| | | Entry entry = TestCaseUtils.makeEntry( |
| | | "dn: cn=syntax-test,o=test", |
| | | "objectclass: person", |
| | | "objectclass: testOC", |
| | | "cn: syntax-test", |
| | | "sn: xyz", |
| | | "test-attr-regex: invalid regex"); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | AddOperation addOperation = conn.processAdd(entry.getDN(), |
| | | entry.getObjectClasses(), |
| | | entry.getUserAttributes(), |
| | | entry.getOperationalAttributes()); |
| | | assertEquals(addOperation.getResultCode(), |
| | | ResultCode.INVALID_ATTRIBUTE_SYNTAX); |
| | | |
| | | //This addition should go through. |
| | | TestCaseUtils.addEntry( |
| | | "dn: cn=syntax-test,o=test", |
| | | "objectclass: person", |
| | | "objectclass: testOC", |
| | | "cn: syntax-test", |
| | | "sn: xyz", |
| | | "test-attr-regex: host:0.0.0"); |
| | | } |
| | | finally |
| | | { |
| | | deleteRegexSyntax(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the search using regex syntax. |
| | | * |
| | | * @throws java.lang.Exception |
| | | */ |
| | | @Test() |
| | | public void testRegexSyntaxSearch() throws Exception |
| | | { |
| | | try |
| | | { |
| | | addRegexSyntax(); |
| | | //This addition should go through. |
| | | TestCaseUtils.addEntry( |
| | | "dn: cn=test,o=test", |
| | | "objectclass: person", |
| | | "objectclass: testOC", |
| | | "cn: test", |
| | | "sn: xyz", |
| | | "test-attr-regex: host:0.0.0"); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | null, |
| | | ByteString.valueOf("cn=test,o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferencePolicy.NEVER_DEREF_ALIASES, |
| | | Integer.MAX_VALUE, |
| | | Integer.MAX_VALUE, |
| | | false, |
| | | LDAPFilter.decode("test-attr-regex=host:0.0.0"), |
| | | null, null); |
| | | |
| | | searchOperation.run(); |
| | | assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); |
| | | List<SearchResultEntry> entries = searchOperation.getSearchEntries(); |
| | | SearchResultEntry e = entries.get(0); |
| | | //An entry must be returned. |
| | | assertNotNull(e); |
| | | } |
| | | finally |
| | | { |
| | | deleteRegexSyntax(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | //Parses the OID from the syntax defitions. |
| | | private String getOIDFromLdapSyntax(String valueStr) |
| | | { |
| | |
| | | } |
| | | int oidStartPos = pos; |
| | | |
| | | boolean lastWasPeriod = false; |
| | | while ((pos < length) && ((c = valueStr.charAt(pos)) != ' ') |
| | | && (c = valueStr.charAt(pos)) != ')') |
| | | { |
| | | if (c == '.') |
| | | { |
| | | lastWasPeriod = true; |
| | | } |
| | | else |
| | | { |
| | | lastWasPeriod = false; |
| | | } |
| | | pos++; |
| | | } |
| | | return valueStr.substring(oidStartPos, pos); |
| | |
| | | |
| | | assertTrue(resultCode==0); |
| | | } |
| | | |
| | | |
| | | //Adds a regex syntax to the schema. |
| | | private void addRegexSyntax() throws Exception |
| | | { |
| | | //Add the substitution syntax for an unimplemented syntax. |
| | | int resultCode = TestCaseUtils.applyModifications(true, |
| | | "dn: cn=schema", |
| | | "changetype: modify", |
| | | "add: ldapsyntaxes", |
| | | "ldapSyntaxes: ( 1.1.1 DESC 'Host and Port in the format of HOST:PORT' " + |
| | | "X-PATTERN '^[a-z-A-Z]+:[0-9.]+\\d$' )"); |
| | | assertTrue(resultCode==0); |
| | | |
| | | resultCode = TestCaseUtils.applyModifications(true, |
| | | "dn: cn=schema", |
| | | "changetype: modify", |
| | | "add: attributetypes", |
| | | "attributetypes: ( test-attr-oid NAME 'test-attr-regex' SYNTAX 1.1.1 )", |
| | | "-", |
| | | "add: objectclasses", |
| | | "objectclasses: ( oc-oid NAME 'testOC' SUP top AUXILIARY MUST test-attr-regex)" |
| | | ); |
| | | assertTrue(resultCode == 0); |
| | | } |
| | | |
| | | |
| | | |
| | | //Deletes the regex syntax from the schema. |
| | | private void deleteRegexSyntax() throws Exception |
| | | { |
| | | //delete the substitution syntax. |
| | | int resultCode = TestCaseUtils.applyModifications(true, |
| | | "dn: cn=schema", |
| | | "changetype: modify", |
| | | "delete: objectclasses", |
| | | "objectclasses: ( oc-oid NAME 'testOC' SUP top AUXILIARY MUST test-attr-regex)", |
| | | "-", |
| | | "delete: attributetypes", |
| | | "attributetypes: ( test-attr-oid NAME 'test-attr-regex' SYNTAX 1.1.1 )" |
| | | ); |
| | | |
| | | assertTrue(resultCode==0); |
| | | |
| | | resultCode = TestCaseUtils.applyModifications(true, |
| | | "dn: cn=schema", |
| | | "changetype: modify", |
| | | "delete: ldapsyntaxes", |
| | | "ldapSyntaxes: ( 1.1.1 DESC 'Host and Port in the format of HOST:PORT' " + |
| | | "X-PATTERN '^[a-z-A-Z]+:[0-9.]+\\d$' )"); |
| | | |
| | | assertTrue(resultCode==0); |
| | | } |
| | | } |