问题描述
我正在尝试获取、存储并反过来使用 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 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!