Examples of EqualityMatchingRule


Examples of org.nasutekds.server.api.EqualityMatchingRule

     */
    public ByteString getNormalizedValue() throws DirectoryException
    {
      if (normalizedValue == null)
      {
        EqualityMatchingRule equalityMatchingRule = attributeType
            .getEqualityMatchingRule();
        if (equalityMatchingRule == null)
        {
          Message message = ERR_ATTR_TYPE_NORMALIZE_NO_MR.get(String
              .valueOf(value), attributeType.getNameOrOID());
          throw new DirectoryException(
              ResultCode.INAPPROPRIATE_MATCHING, message);
        }

        normalizedValue = equalityMatchingRule.normalizeValue(value);
      }

      return normalizedValue;
    }
View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

    /**
     * {@inheritDoc}
     */
    public int hashCode()
    {
      EqualityMatchingRule equalityMatchingRule = attributeType
          .getEqualityMatchingRule();

      ByteString valueToHash;
      try
      {
        valueToHash = getNormalizedValue();
      }
      catch (Exception e)
      {
        if (debugEnabled())
        {
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }

        valueToHash = value;
      }

      if (equalityMatchingRule != null)
      {
        return equalityMatchingRule.generateHashCode(valueToHash);
      }
      else
      {
        return valueToHash.hashCode();
      }
View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

    /**
     * Use the default equality index in two conditions:
     * 1. There is no matching rule provided
     * 2. The matching rule specified is actually the default equality.
     */
    EqualityMatchingRule eqRule =
            indexConfig.getAttribute().getEqualityMatchingRule();
    if(nOID ==null || nOID.equals(eqRule.getOID()) ||
            nOID.equalsIgnoreCase(eqRule.getName()))
    {
      //No matching rule is defined; use the default equality matching rule.
      if(equalityIndex == null)
      {
        // There is no index on this matching rule.
View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

    List<String> typeNames = new LinkedList<String>();
    String description = null;
    AttributeType superiorType = null;
    AttributeSyntax syntax = DirectoryServer.getDefaultAttributeSyntax();
    ApproximateMatchingRule approximateMatchingRule = null;
    EqualityMatchingRule equalityMatchingRule = null;
    OrderingMatchingRule orderingMatchingRule = null;
    SubstringMatchingRule substringMatchingRule = null;
    AttributeUsage attributeUsage = AttributeUsage.USER_APPLICATIONS;
    boolean isCollective = false;
    boolean isNoUserModification = false;
    boolean isObsolete = false;
    boolean isSingleValue = false;
    HashMap<String,List<String>> extraProperties =
         new LinkedHashMap<String,List<String>>();


    while (true)
    {
      StringBuilder tokenNameBuffer = new StringBuilder();
      pos = readTokenName(valueStr, tokenNameBuffer, pos);
      String tokenName = tokenNameBuffer.toString();
      String lowerTokenName = toLowerCase(tokenName);
      if (tokenName.equals(")"))
      {
        // We must be at the end of the value.  If not, then that's a problem.
        if (pos < length)
        {
          Message message =
            ERR_ATTR_SYNTAX_ATTRTYPE_UNEXPECTED_CLOSE_PARENTHESIS.
                get(valueStr, (pos-1));
          throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                       message);
        }

        break;
      }
      else if (lowerTokenName.equals("name"))
      {
        // This specifies the set of names for the attribute type.  It may be a
        // single name in single quotes, or it may be an open parenthesis
        // followed by one or more names in single quotes separated by spaces.
        c = valueStr.charAt(pos++);
        if (c == '\'')
        {
          StringBuilder userBuffer  = new StringBuilder();
          StringBuilder lowerBuffer = new StringBuilder();
          pos = readQuotedString(valueStr, lowerStr, userBuffer, lowerBuffer,
                                 (pos-1));
          primaryName = userBuffer.toString();
          typeNames.add(primaryName);
        }
        else if (c == '(')
        {
          StringBuilder userBuffer  = new StringBuilder();
          StringBuilder lowerBuffer = new StringBuilder();
          pos = readQuotedString(valueStr, lowerStr, userBuffer, lowerBuffer,
                                 pos);
          primaryName = userBuffer.toString();
          typeNames.add(primaryName);


          while (true)
          {
            if (valueStr.charAt(pos) == ')')
            {
              // Skip over any spaces after the parenthesis.
              pos++;
              while ((pos < length) && ((c = valueStr.charAt(pos)) == ' '))
              {
                pos++;
              }

              break;
            }
            else
            {
              userBuffer  = new StringBuilder();
              lowerBuffer = new StringBuilder();

              pos = readQuotedString(valueStr, lowerStr, userBuffer,
                                     lowerBuffer, pos);
              typeNames.add(userBuffer.toString());
            }
          }
        }
        else
        {
          // This is an illegal character.
          Message message =
              ERR_ATTR_SYNTAX_ATTRTYPE_ILLEGAL_CHAR.get(
                      valueStr, String.valueOf(c), (pos-1));
          throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                       message);
        }
        //RFC 2251: A specification may also assign one or more textual names
        //for an attribute type.  These names MUST begin with a letter, and
        //only contain ASCII letters, digit characters and hyphens.

        //The global config hasn't been read so far. Allow the name exceptions
        //during startup.
        boolean allowExceptions = DirectoryServer.isRunning()?
                           DirectoryServer.allowAttributeNameExceptions():true;
        //Iterate over all the names and throw an exception if it is invalid.
        for(String name : typeNames)
        {
          for(int index=0; index < name.length(); index++)
          {
            char ch = name.charAt(index);
            switch(ch)
            {
              case '-':
              //hyphen is allowed but not as the first byte.
                if (index==0)
                {
                  Message msg = ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_DASH.
                        get(value.toString());
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                break;
              case '_':
              // This will never be allowed as the first character.  It
              // may be allowed for subsequent characters if the attribute
              // name exceptions option is enabled.
                if (index==0)
                {
                  Message msg =
                          ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_UNDERSCORE.
                        get(value.toString(),
                            ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                else if (!allowExceptions)
                {
                  Message msg = ERR_ATTR_SYNTAX_ATTR_ILLEGAL_UNDERSCORE_CHAR.
                        get(value.toString(),
                            ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                               msg);
                }
                break;

              default:
              //Only digits and ascii letters are allowed but the first byte
              //can not be a digit.
                if(index ==0 && isDigit(ch) && !allowExceptions)
                {
                  Message message = ERR_ATTR_SYNTAX_ATTR_ILLEGAL_INITIAL_DIGIT.
                    get(value.toString(), ch,
                        ATTR_ALLOW_ATTRIBUTE_NAME_EXCEPTIONS);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                             message);
                }
                else if(!((ch>='0' && ch<='9') || (ch>='A' && ch<='Z') ||
                        (ch>='a' && ch<='z')))
                {
                  Message msg = ERR_ATTR_SYNTAX_ATTR_ILLEGAL_CHAR.get(
                            value.toString(), ch, index);
                  throw new DirectoryException(
                          ResultCode.INVALID_ATTRIBUTE_SYNTAX,
                                       msg);
                }
                break;
            }
          }

        }

      }
      else if (lowerTokenName.equals("desc"))
      {
        // This specifies the description for the attribute type.  It is an
        // arbitrary string of characters enclosed in single quotes.
        StringBuilder descriptionBuffer = new StringBuilder();
        pos = readQuotedString(valueStr, descriptionBuffer, pos);
        description = descriptionBuffer.toString();
      }
      else if (lowerTokenName.equals("obsolete"))
      {
        // This indicates whether the attribute type should be considered
        // obsolete.  We do not need to do any more parsing for this token.
        isObsolete = true;
      }
      else if (lowerTokenName.equals("sup"))
      {
        // This specifies the name or OID of the superior attribute type from
        // which this attribute type should inherit its properties.
        StringBuilder woidBuffer = new StringBuilder();
        pos = readWOID(lowerStr, woidBuffer, pos);
        superiorType = schema.getAttributeType(woidBuffer.toString());
        if (superiorType == null)
        {
          if (allowUnknownElements)
          {
            superiorType = DirectoryServer.getDefaultAttributeType(
                                                woidBuffer.toString());
          }
          else
          {
            // This is bad because we don't know what the superior attribute
            // type is so we can't base this attribute type on it.
            Message message = WARN_ATTR_SYNTAX_ATTRTYPE_UNKNOWN_SUPERIOR_TYPE.
                get(String.valueOf(oid), String.valueOf(woidBuffer));
            throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
                                         message);
          }
        }


        // Use the information in the superior type to provide defaults for the
        // rest of the components in this attribute type description.
        // Technically, the definition of the superior type should be provided
        // before the matching rule, syntax, single-value, collective,
        // no-user-modification, and usage components, and in that case we won't
        // undo something else that has already been set by an earlier
        // definition.  However, if the information is provided out-of-order,
        // then it is possible that this could overwrite some desired setting
        // that is different from that of the supertype.
        approximateMatchingRule = superiorType.getApproximateMatchingRule();
        equalityMatchingRule    = superiorType.getEqualityMatchingRule();
        orderingMatchingRule    = superiorType.getOrderingMatchingRule();
        substringMatchingRule   = superiorType.getSubstringMatchingRule();
        syntax                  = superiorType.getSyntax();
        isSingleValue           = superiorType.isSingleValue();
        isCollective            = superiorType.isCollective();
        isNoUserModification    = superiorType.isNoUserModification();
        attributeUsage          = superiorType.getUsage();
      }
      else if (lowerTokenName.equals("equality"))
      {
        // This specifies the name or OID of the equality matching rule to use
        // for this attribute type.
        StringBuilder woidBuffer = new StringBuilder();
        pos = readWOID(lowerStr, woidBuffer, pos);
        EqualityMatchingRule emr =
             schema.getEqualityMatchingRule(woidBuffer.toString());
        if (emr == null)
        {
          // This is bad because we have no idea what the equality matching
          // rule should be.
View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

      else
      {
        ByteString thisNormValue =
            type.getEqualityMatchingRule().normalizeValue(pattern.get(0));
        ByteString thatNormValue = value.getNormalizedValue();
        EqualityMatchingRule mr = type.getEqualityMatchingRule();
        return mr.areEqual(thisNormValue, thatNormValue);
      }
    }
    catch (DirectoryException e)
    {
      return false;
View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

   */
  @Test(dataProvider= "equalitymatchingrules")
  public void equalityMatchingRules(String value1,
                             String value2, Boolean result) throws Exception
  {
    EqualityMatchingRule rule = getRule();

    // normalize the 2 provided values and check that they are equals
    ByteString normalizedValue1 =
      rule.normalizeValue(ByteString.valueOf(value1));
    ByteString normalizedValue2 =
      rule.normalizeValue(ByteString.valueOf(value2));

    Boolean liveResult = rule.areEqual(normalizedValue1, normalizedValue2);
    assertEquals(result, liveResult);
  }
View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

   */
  @Test(dataProvider= "equalityMatchingRuleInvalidValues")
  public void equalityMatchingRulesInvalidValues(String value) throws Exception
    {
    // Get the instance of the rule to be tested.
    EqualityMatchingRule rule = getRule();

    // normalize the 2 provided values
    boolean success = false;
    try
    {
      rule.normalizeValue(ByteString.valueOf(value));
    } catch (DirectoryException e) {
      success = true;
    }

    if (!success)
    {
      fail("The matching rule : " + rule.getName() +
           " should detect that value \"" + value + "\" is invalid");
    }
  }
View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

   */
  @Test(dataProvider= "valuesMatch")
  public void testValuesMatch(String value1,
                             String value2, Boolean result) throws Exception
  {
    EqualityMatchingRule rule = getRule();

    // normalize the 2 provided values and check that they are equals
    ByteString normalizedValue1 =
      rule.normalizeValue(ByteString.valueOf(value1));
    ByteString normalizedValue2 =
      rule.normalizeValue(ByteString.valueOf(value2));

    ConditionResult liveResult =
      rule.valuesMatch(normalizedValue1, normalizedValue2);
    if (result == true)
      assertEquals(ConditionResult.TRUE, liveResult);
    else
      assertEquals(ConditionResult.FALSE, liveResult);

View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

            configAcceptable = false;
            continue;
          }

          EqualityMatchingRule emr = at.getEqualityMatchingRule();
          if ((emr != null) && oid.equals(emr.getOID()))
          {
            Message message =
                    WARN_CONFIG_SCHEMA_CANNOT_DELETE_MR_IN_USE_BY_AT.get(
                            matchingRule.getName(),
                            at.getNameOrOID());
View Full Code Here

Examples of org.nasutekds.server.api.EqualityMatchingRule

              configAcceptable = false;
              continue;
            }

            EqualityMatchingRule emr = at.getEqualityMatchingRule();
            if ((emr != null) && oid.equals(emr.getOID()))
            {
              Message message =
                      WARN_CONFIG_SCHEMA_CANNOT_DISABLE_MR_IN_USE_BY_AT.get(
                              matchingRule.getName(),
                              at.getNameOrOID());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.