Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Spring和Java从LDAP获取userPassword属性_Java_Spring_Ldap_Spring Ldap - Fatal编程技术网

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

如何使用Spring和Java从LDAP获取userPassword属性,java,spring,ldap,spring-ldap,Java,Spring,Ldap,Spring Ldap,我想在java中使用spring从ldap获取userPassword属性 当然,这不起作用: context.getStringAttribute("userPassword"); 如果我尝试: context.getObjectAttribute("userPassword"); 我可以得到这个属性。但是现在从Object如何得到哈希密码呢?听起来像是上下文。getObjectAttribute(“userPassword”)返回一个对象,所以你只需要确定它是什么 根据注释,它是一个表示

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

当然,这不起作用:

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

context.getObjectAttribute("userPassword");

我可以得到这个属性。但是现在从Object如何得到哈希密码呢?

听起来像是上下文。getObjectAttribute(“userPassword”)返回一个
对象,所以你只需要确定它是什么

根据注释,它是一个表示字符串的
字节[]
数组,因此基本上可以执行以下操作:

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

它是什么类型的
对象
?不太可能是
java.lang.Object
。你应该找出它到底是什么类型的
对象
并将其转换为那种类型。我不知道如何获得这个属性。。可能方法getObjectAttribute是错误的。userPassword属性类似于:userPassword:{MD5}AFxCqn99F5XK4RfSxu1Ldg==您说的
getObjectAttribute(“userPassword”)
返回一个
对象,听起来不错。如果您有调试器,请查看它是什么类型的对象,如果没有,请使用
System.out.println(object.getClass().getName())
查找它是什么类型的
对象。一旦你知道了,就把它转换成正确的类型。如果我尝试你的代码,我会打印以下内容:[b听起来像
byte[]
数组,所以试试这个:
String pwHash=newstring((byte[])theObject);
,这是把
对象转换成
byte[]
数组,并从中创建一个新的
String
(使用默认编码)