当前位置:   article > 正文

java通过ldap获取安全组属性乱码问题_java.naming.ldap.attributes.binary

java.naming.ldap.attributes.binary

安全组属性objectSid、objectGUID直接转为string会出现乱码,需要将其先转为byte再转为string
具体实现

  1. 连接ldap添加环境
env.put("java.naming.ldap.attributes.binary", "objectSid objectGUID");
  • 1
  1. 转换属性
byte[] sidBytes = (byte[]) attributes.get("objectSid").get();
String objectSid = bytesToHexString(sidBytes));
  • 1
  • 2
  1. 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();
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  1. objectGUID同理
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/905723
推荐阅读
相关标签
  

闽ICP备14008679号