问题描述
我试图获取,存储并依次使用objectGUID查询Active Directory.要获取用户属性,我正在使用以下
I am trying to fetch, store and in turn use objectGUID to query Active directory.To get user attributes i am using following
public static class MyDnKeyValueAttMapper implements AttributesMapper<Object> {
@Override
public List<LdapKeyValueList> mapFromAttributes(Attributes attributes)
throws NamingException, javax.naming.NamingException {
List<LdapKeyValueList> attributeKeyValMap = new ArrayList<LdapKeyValueList>();
NamingEnumeration<String> namingEnumeration = attributes.getIDs();
while (namingEnumeration.hasMoreElements()) {
String attributeName = (String) namingEnumeration.nextElement();
String AttributeValue = attributes.get(attributeName).get().toString();
attributeKeyValMap.add(new LdapKeyValueList(attributeName, AttributeValue));
}
return attributeKeyValMap;
}
}
objectGuid似乎总是以字符串格式返回.我也尝试过-
objectGuid always seems to be returned in string format.I have also tried -
UUID guid = (UUID) attributes.get("objectGUID").get();
这会引发无法将字符串转换为uuid"的错误
This throws error of "cannot convert string to uuid"
好像在我可以做任何事情之前一样,ldaptemplate搜索总是以字符串格式返回属性.
Seems like before i can do anything ldaptemplate search always return attributes in string format.
如何获取"objectGUID"的格式,以便我可以存储它并在ldapTemplate搜索查询中使用.
How can i get hold of "objectGUID" in its format, so that i can store it and use in ldapTemplate search queries.
提前谢谢.
推荐答案
如果您不希望将二进制属性(objectGUID具有Octet String语法)检索为字符串,则必须这样说.使用Spring,您必须在上下文环境中添加<entry key="java.naming.ldap.attributes.binary" value="objectGUID"/>
.
If you don't want a binary attribute (objectGUID has Octet String syntax) to be retrieved as a string, you must say so. With Spring you'll have to add <entry key="java.naming.ldap.attributes.binary" value="objectGUID"/>
to your context environment.
byte[] guid = (byte[]) namingEnumeration.getAttributes().get("objectGUID").get();
上的最新版本应返回您要查找的内容.
Later on byte[] guid = (byte[]) namingEnumeration.getAttributes().get("objectGUID").get();
should return what you're looking for.
仅输入,未经测试.
这篇关于使用objectGUID进行查询-Spring LDAP模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!