安全组属性objectSid、objectGUID直接转为string会出现乱码,需要将其先转为byte再转为string
具体实现
- 连接ldap添加环境
env.put("java.naming.ldap.attributes.binary", "objectSid objectGUID");
- 转换属性
byte[] sidBytes = (byte[]) attributes.get("objectSid").get();
String objectSid = bytesToHexString(sidBytes));
- bytesToHexString实现
public static String bytesToHexString(byte[] bytes) {
StringBuilder hexString = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(0xFF & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
- objectGUID同理