我想在Java中使用Spring从ldap获取userPassword属性。

当然这不起作用:

context.getStringAttribute("userPassword");

如果我尝试:
context.getObjectAttribute("userPassword");

我可以获取此属性..但是现在如何从Object获取哈希密码?

最佳答案

听起来context.getObjectAttribute("userPassword")返回了Object,所以您只需要确定它是什么即可。

根据评论,它是一个byte[]数组,它表示一个String,因此您基本上可以这样做:

Object o = context.getObjectAttribute("userPassword");
byte[] bytes = (byte[]) o;
String hash = new String(bytes);

09-28 02:14