java – 如何从ldap DirContextOperations获取memberOf属性

我想获得一个用户所属的组列表,目前我可以获得如下的大多数属性

CustomLdapUserDetails.Essence essence = new CustomLdapUserDetails.Essence();
essence.setDn(dn);
Object passwordValue = ctx.getObjectAttribute(passwordAttributeName);
String givennameValue = (String)ctx.getObjectAttribute("givenname");
String snValue = (String)ctx.getObjectAttribute("sn");
String titleValue = (String)ctx.getObjectAttribute("title");
essence.setFirstname(givennameValue);
essence.setLastname(snValue);

但我无法弄清楚如何获取memberOf属性.如果我将整个DirContextOperations输出为String,我会得到以下内容

org.springframework.ldap.core.DirContextAdapter: dn=uid=emp123 {rdn=uid=emp123,
whenCreated=20110816063203.0Z,
objectCategory=CN=fompanyPerson,CN=Schema,CN=Configuration,CN={9F17F445-56C4-42D9-
B7C6-B630FFEA7F07}, badPwdCount=0, otherTelephone=123-456789, businessUnit=IREIRE BU, 
ntAccount=DMN1\emp123, managerID=emp987, objectGUID=5?
?e6A??????/, mail=emp123@somewhere.com, uid=emp123, companyWorkRelationship=EMP, 
memberOf[0]=CN=ABC IREIRE,OU=AutoGroups,DC=entdir,DC=gtn,DC=com, 
memberOf[1]=CN=azgEntJazzUsers,OU=AutoGroups,DC=entdir,DC=gtn,DC=com, companySite=DBL, 
companyCostCenter=91827, companyBusinessGroup=IREIRE BG, ntDomain=DMN1, instanceType=4, 
corpID=emp123, objectSid=  I???&?C?k?J???????, st=XX, badPasswordTime=0, vdejoindn=P-
ENTDIRXXX-1:uid=emp123,DC=entdirXXX,DC=gtn,DC=com, companySourceSystem=C-WORKSYSTEM, 
objectClass[0]=top, objectClass[1]=person, objectClass[2]=organizationalPerson, 
objectClass[3]=user, objectClass[4]=inetOrgPerson, objectClass[5]=fompanyPerson, 
company=ABC DEV, name=emp123, sn=Smith, exchangeAlias=emp123, telephoneNumber=1-987-6543, 
ntDomainRelative=DMN1, uSNChanged=999111, physicalDeliveryOfficeName=DXI, 
ntAccountRelative=DMN1\emp123, cn=Smith, John, exchangeServer=someServer, 
documentumUserName=Smith JOHN emp123, title=SOFTWARE ENGINEER/DEVELOPER, 
otherCertMailbox=emp123@xyz.somewhere.com, msDS-UserAccountDisabled=TRUE, 
managerName=Bloggs, Joe, givenName=John, uSNCreated=18418957, displayName=Smith, John, 
pwdLastSet=629579433359695509, fompanyPersonStatus=A, whenChanged=20120266070711.0Z, 
o=IREIRE BU, distinguishedName=uid=emp123,DC=entdirXXX,DC=gtn,DC=com, eDARevoke=N, 
division=SEF-GL , manager=uid=emp987,DC=entdirXXX,DC=gtn,DC=com, 
exchangeDirectory=SMXZG1DB, samAccountName=emp123, sametimeServer=cvxcluster}

我需要得到的是每个memberOf的CN值到一个字符串数组中,我试过:

ctx.getObjectAttribute("memberOf[1]"))
ctx.getObjectAttribute("memberOf"))
ctx.getObjectAttribute("memberOf=CN")) 

我在网上看过设置的例子,但是我找不到任何获取的例子,是否真的比获得其他属性要复杂得多?

任何建议将不胜感激

解决方法:

你可能只会从最后错过一个“s”.尝试:

ctx.getObjectAttributes("memberOf")

javadoc澄清了singularplural表单方法之间的区别. (前者仅返回第一个值,即使给定属性是多值的.)

上一篇:java-如何执行Spring LDAP和JPA事务


下一篇:PHP-什么是LDAP_sort()方法的替代品?