Ejemplo n.º 1
0
  private void encodeV2Attributes(
      ByteStringBuilder buffer,
      Map<AttributeType, List<Attribute>> attributes,
      EntryEncodeConfig config)
      throws DirectoryException {
    int numAttributes = 0;

    // First count how many attributes are there to encode.
    for (List<Attribute> attrList : attributes.values()) {
      for (Attribute a : attrList) {
        if (a.isVirtual() || a.isEmpty()) {
          continue;
        }

        numAttributes++;
      }
    }

    // Encoded one-to-five byte number of attributes
    buffer.appendBERLength(numAttributes);

    if (config.compressAttributeDescriptions()) {
      for (List<Attribute> attrList : attributes.values()) {
        for (Attribute a : attrList) {
          if (a.isVirtual() || a.isEmpty()) {
            continue;
          }

          ByteStringBuilder bsb = new ByteStringBuilder();
          config.getCompressedSchema().encodeAttribute(bsb, a);
          buffer.appendBERLength(bsb.length());
          buffer.append(bsb);
        }
      }
    } else {
      // The attributes will be encoded as a sequence of:
      // - A UTF-8 byte representation of the attribute name.
      // - A zero delimiter
      // - A one-to-five byte number of values for the attribute
      // - A sequence of:
      //   - A one-to-five byte length for the value
      //   - A UTF-8 byte representation for the value
      for (List<Attribute> attrList : attributes.values()) {
        for (Attribute a : attrList) {
          byte[] nameBytes = getBytes(a.getNameWithOptions());
          buffer.append(nameBytes);
          buffer.append((byte) 0x00);

          buffer.appendBERLength(a.size());
          for (AttributeValue v : a) {
            buffer.appendBERLength(v.getValue().length());
            buffer.append(v.getValue());
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
 private Integer getIntegerUserAttribute(
     Entry userEntry,
     String attributeTypeName,
     Arg1<Object> nonUniqueAttributeMessage,
     Arg2<Object, Object> cannotProcessAttributeMessage) {
   AttributeType attrType = DirectoryServer.getAttributeTypeOrDefault(attributeTypeName);
   List<Attribute> attrList = userEntry.getAttribute(attrType);
   if (attrList != null && attrList.size() == 1) {
     Attribute a = attrList.get(0);
     if (a.size() == 1) {
       ByteString v = a.iterator().next();
       try {
         return Integer.valueOf(v.toString());
       } catch (Exception e) {
         logger.traceException(e);
         logger.error(cannotProcessAttributeMessage.get(v, userEntry.getName()));
       }
     } else if (a.size() > 1) {
       logger.error(nonUniqueAttributeMessage.get(userEntry.getName()));
     }
   }
   return null;
 }
Ejemplo n.º 3
0
  /**
   * The attributes will be encoded as a sequence of: - A UTF-8 byte representation of the attribute
   * name. - A zero delimiter - A one-to-five byte number of values for the attribute - A sequence
   * of: - A one-to-five byte length for the value - A UTF-8 byte representation for the value
   */
  private void append(ByteStringBuilder buffer, Map<AttributeType, List<Attribute>> attributes) {
    for (List<Attribute> attrList : attributes.values()) {
      for (Attribute a : attrList) {
        byte[] nameBytes = getBytes(a.getNameWithOptions());
        buffer.appendBytes(nameBytes);
        buffer.appendByte(0x00);

        buffer.appendBERLength(a.size());
        for (ByteString v : a) {
          buffer.appendBERLength(v.length());
          buffer.appendBytes(v);
        }
      }
    }
  }