Clarification: from my previous post I would like to argue that the DistinguishedName parser is indeed performing as expected.
Clarification: from my previous post I would like to argue that the DistinguishedName parser is indeed performing as expected.
Ahhhh... yes... right. *thumps himself in the head*. Thanks
Appreciate you taking the time to look into it!
Dan
hi,
i am having issue with LdapTemplate.search(). If the result list contains DNs with escaped backslashes, then exception occurs. Example CN=ABC\\Something causing problem. Does anyone having work around to elliminate? or at least expand my query filter to exclude those items?
many thanks,
exception :Code:failed org.springframework.ldap.UncategorizedLdapException: Operation failed; nested exception is javax.naming.NamingException: problem generating object using object factory Root exception is org.springframework.ldap.BadLdapGrammarException: Failed to parse DN; nested exception is org.springframework.ldap.support.TokenMgrError: Lexical error at line 1, column 18. Encountered: "\\" (92), after : ""]; remaining name '' Caused by: javax.naming.NamingException: problem generating object using object factory Root exception is org.springframework.ldap.BadLdapGrammarException: Failed to parse DN; nested exception is org.springframework.ldap.support.TokenMgrError: Lexical error at line 1, column 18. Encountered: "\\" (92), after : ""]; remaining name '' at com.sun.jndi.ldap.LdapSearchEnumeration.createItem(LdapSearchEnumeration.java:111) at com.sun.jndi.ldap.LdapNamingEnumeration.nextAux(LdapNamingEnumeration.java:256) at com.sun.jndi.ldap.LdapNamingEnumeration.nextImpl(LdapNamingEnumeration.java:236) at com.sun.jndi.ldap.LdapNamingEnumeration.next(LdapNamingEnumeration.java:184) at org.springframework.ldap.LdapTemplate.search(LdapTemplate.java:271) at org.springframework.ldap.LdapTemplate.search(LdapTemplate.java:231) at org.springframework.ldap.LdapTemplate.search(LdapTemplate.java:561) at org.springframework.ldap.LdapTemplate.search(LdapTemplate.java:475) at org.springframework.ldap.LdapTemplate.search(LdapTemplate.java:423)
The following test case succeeds:
We encountered a similar problem earlier, and that was quite thoroughly investigated here.Code:public void testEscapedBackslash() throws Exception { DistinguishedName dn = new DistinguishedName("cn=ABC\\\\Something"); assertEquals("cn", dn.getLdapRdn(0).getKey()); assertEquals("ABC\\Something", dn.getLdapRdn(0).getValue()); }
It seems like the DN supplied to Spring LDAP by the underlying code is invalid, and there's not much we can do about it.
You should be able to modify your filter to exclude these entries.:
Code:Filter originalFilter = <your original filter> AndFilter newFilter = new AndFilter(); newFilter.and(originalFilter); newFilter.and(new WhitespaceWildcardsFilter("cn", "\\"));