【问题标题】:Endianness of Active Directory objectUUID Attributes in Java / Apache Directory StudioJava / Apache Directory Studio中Active Directory对象UUID属性的字节序
【发布时间】:2017-07-28 10:46:00
【问题描述】:

我正在从 Java 连接到 Active Directory 服务器。我添加属性:

 env.put("java.naming.ldap.attributes.binary", "objectGUID");

然后我像这样读取 objecUUID:

Attribute a = result.getAttributes().get("objectUUID");
byte[] b = (byte[])a.get();

并像这样格式化:

String id = Hex.
    encodeHexString(b).
    replaceAll(
       "(.{8})(.{4})(.{4})(.{4})(.{12})", 
       "$1-$2-$3-$4-$5"
    )
);

结果是一个格式很好的 UUID。当我想通过 UUID 查找条目时,我删除了破折号:

id = id.replaceAll("[^a-zA-Z0-9]+", "");

然后插入反斜杠:

id = id.replaceAll("([a-zA-Z0-9]{2,2})", "\\\\$1");

这一切都很好。我遇到的问题是 Apache Directory Studio 显示(例如)我用户的 UUID 为:

 8e591e3a-35ab-45cc-8dca-c5e451adc975

而我的代码显示与以下相同条目的 UUID:

 3a1e598e-ab35-cc45-8dca-c5e451adc975

如您所见,高位和低位字节被交换为左边的 8 个字节,但右侧相同。这是为什么?这看起来很奇怪……

.rm

【问题讨论】:

    标签: java active-directory uuid apache-directory


    【解决方案1】:

    如果你看这里:

    https://en.wikipedia.org/wiki/Universally_unique_identifier

    Name                               Length (Bytes) Length (Hex Digits) Contents
    time_low                           4              8                   integer giving the low 32 bits of the time
    time_mid                           2              4                   integer giving the middle 16 bits of the time
    time_hi_and_version                2              4                   4-bit "version" in the most significant bits, followed by the high 12 bits of the time
    clock_seq_hi_and_res clock_seq_low 2              4                   1-3 bit "variant" in the most significant bits, followed by the 13-15 bit clock sequence
    node                               6              12                  the 48-bit node id
    

    您可以看到前 3 段是与“时间”数据相关的整数/短字节,因此具有字节顺序,而其他部分只是二进制数据,因此没有。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多