我正在从 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
如您所见,高位和低位字节被交换为左边的八个字节,但在右侧相同。这是为什么?这似乎很奇怪......
。R M