如何使用 Spring 和 Java 从 LDAP 获取 userPassword 属性

Dev*_*s85 3 java spring ldap spring-ldap

我想在 java 中使用 spring 从 ldap 获取 userPassword 属性。

当然这不起作用:

context.getStringAttribute("userPassword");
Run Code Online (Sandbox Code Playgroud)

如果我尝试:

context.getObjectAttribute("userPassword");
Run Code Online (Sandbox Code Playgroud)

我可以得到这个属性..但是现在从对象我怎么能得到哈希密码?

Ale*_*lex 5

听起来像context.getObjectAttribute("userPassword")返回一个,Object所以你只需要确定它是什么。

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

Object o = context.getObjectAttribute("userPassword");
byte[] bytes = (byte[]) o;
String hash = new String(bytes);
Run Code Online (Sandbox Code Playgroud)