使用Active Directory中的特殊字符获取组名的组属性

问题描述:

我有一个包含特殊字符的组名。使用Active Directory中的特殊字符获取组名的组属性

CN=IN&T DC Gebnn/Dohn,OU=ABGroups,OU=Hammers,DC=MyCompany,DC=int 

我尝试使用下面的代码来获得这个组的属性:

String lstrFullGpName = CN=IN&T DC Gebnn/Dohn,OU=ABGroups,OU=Hammers,DC=MyCompany,DC=int; 
Attributes groupAttributes = actxDir.getAttributes(lstrFullGpName); 

这引发以下错误:

Exception in thread "main" javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-031006CC, problem 5012 (DIR_ERROR), data 0 ]; remaining name ' CN=IN&T DC Gebnn/Dohn,OU=ABGroups,OU=Hammers,DC=MyCompany,DC=int'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3081)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2987)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2794)
at com.sun.jndi.ldap.LdapCtx.c_lookup(LdapCtx.java:1011)
at com.sun.jndi.toolkit.ctx.ComponentContext.c_resolveIntermediate_nns(ComponentContext.java:152)
at com.sun.jndi.toolkit.ctx.AtomicContext.c_resolveIntermediate_nns(AtomicContext.java:342)
at com.sun.jndi.toolkit.ctx.ComponentContext.p_resolveIntermediate(ComponentContext.java:381)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:205)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:121)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:109)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:99)
at LDAPApp.main(LDAPApp.java:68)

我试图逃避特殊字符,但那没用。任何想法为什么这个错误可能发生?

+0

确实很奇怪。这是什么[MSDN siste](http://msdn.microsoft.com/en-us/library/windows/desktop/ms681390%28v=vs.85%29.aspx)说:ERROR_DS_MISSING_SUPREF 8406(0x20D6) \t 目录服务没有配置上级参考。因此目录服务无法发布引用到此目录林以外的对象。 – 2012-03-16 10:45:22

我终于能够找到解决这个问题的办法。问题出现在用户名中的DC上。

+0

我猜“/”是你的问题?为什么,你是如何逃避区议会解决它的? – RobertG 2015-09-29 07:29:25

这是一个已知JNDI限制:

"If the LDAP entry's name contains [a forward slash], then you need to escape it (using the backslash character ('\'))."

http://docs.oracle.com/javase/tutorial/jndi/ldap/jndi.html

即代替Java字符串"/",必须在字符串常量中使用"\\/",逃避这样的字符串

distinguishedName = distinguishedName.replace("/", "\\/")