PDA

View Full Version : BadLdapGrammarException


lumpynose
Aug 29th, 2006, 05:11 PM
I'm using a ContextMapper with search() and in it I have a println for debugging. After being called 9 times (it prints 9 lines) it bombs with a BadLdapGrammarException.

Is it possible that the cn value it's complaining about is malformed because it has a slash in it? All of the previous ones which it prints out don't have a slash in them.

private class
AffilsContextMapper implements ContextMapper {
public Object
mapFromContext(final Object context) {
final DirContextAdapter ctx = (DirContextAdapter) context;
System.out.println("ctx: " + ctx);
final String affil = ctx.getStringAttribute(attrNameAffilsName);

return(affil);
}
}
Operation failed; nested exception is javax.naming.NamingException: problem generating object using object factory [Root exception is net.sf.ldaptemplate.BadLdapGrammarException: Not a proper name (such as key=value): "cn=LBL/DOE Postdoc]; remaining name 'ou=affiliations'
net.sf.ldaptemplate.UncategorizedLdapException: Operation failed; nested exception is javax.naming.NamingException: problem generating object using object factory [Root exception is net.sf.ldaptemplate.BadLdapGrammarException: Not a proper name (such as key=value): "cn=LBL/DOE Postdoc]; remaining name 'ou=affiliations'
Caused by: javax.naming.NamingException: problem generating object using object factory [Root exception is net.sf.ldaptemplate.BadLdapGrammarException: Not a proper name (such as key=value): "cn=LBL/DOE Postdoc]; remaining name 'ou=affiliations'
at com.sun.jndi.ldap.LdapSearchEnumeration.createItem (LdapSearchEnumeration.java:111)
at com.sun.jndi.ldap.LdapNamingEnumeration.nextAux(Ld apNamingEnumeration.java:256)
at com.sun.jndi.ldap.LdapNamingEnumeration.nextImpl(L dapNamingEnumeration.java:236)
at com.sun.jndi.ldap.LdapNamingEnumeration.next(LdapN amingEnumeration.java:184)
at net.sf.ldaptemplate.LdapTemplate.search(LdapTempla te.java:201)
at net.sf.ldaptemplate.LdapTemplate.search(LdapTempla te.java:167)
at net.sf.ldaptemplate.LdapTemplate.search(LdapTempla te.java:355)
at net.sf.ldaptemplate.LdapTemplate.search(LdapTempla te.java:293)
at net.sf.ldaptemplate.LdapTemplate.search(LdapTempla te.java:315)
at waitlistd.ldap.LdapAffiliationsImpl.getAffiliation s(LdapAffiliationsImpl.java:36)
at test.Ldap3Test.testGetAffiliations(Ldap3Test.java: 18)
at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:69)
Caused by: net.sf.ldaptemplate.BadLdapGrammarException: Not a proper name (such as key=value): "cn=LBL/DOE Postdoc
at net.sf.ldaptemplate.support.LdapRdn.parseLdap(Ldap Rdn.java:118)
at net.sf.ldaptemplate.support.LdapRdn.<init>(LdapRdn.java:64)
at net.sf.ldaptemplate.support.DistinguishedName.pars e(DistinguishedName.java:133)
at net.sf.ldaptemplate.support.DistinguishedName.<init>(DistinguishedName.java:89)
at net.sf.ldaptemplate.support.DefaultDirObjectFactor y.stripBasePath(DefaultDirObjectFactory.java:90)
at net.sf.ldaptemplate.support.DefaultDirObjectFactor y.getObjectInstance(DefaultDirObjectFactory.java:5 4)
at javax.naming.spi.DirectoryManager.createObjectFrom Factories(DirectoryManager.java:218)
at javax.naming.spi.DirectoryManager.getObjectInstanc e(DirectoryManager.java:197)
at com.sun.jndi.ldap.LdapSearchEnumeration.createItem (LdapSearchEnumeration.java:105)

lumpynose
Aug 29th, 2006, 07:19 PM
Looks like it might be a bug in Sun's software?

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4307193

rasky
Aug 30th, 2006, 04:28 AM
Well, it's not a bug in sun's software but indeed something similar to the problem referred in sun's bug report (which was btw discarded as not being a bug).

The problem here seems to be that JNDI treats a forward slash ('/') as a meta character, causing the entire DN to be enclosed in quotes (") by sun's CompositeName when one is present. The quotes don't work with our LdapName implementation, causing the parsing to break. We'll need to figure something out to handle it.

In the mean time I can think of a couple of workarounds:
* Don't use a base path on your ContextSource, as this will eliminate the need for us to parse the DN.
* Implement your own DirObjectFactory that removes any enclosing quotes or doesn't use our LdapName.
* Use AttributesMapper instead, as this will ignore the DN.

lumpynose
Aug 30th, 2006, 04:25 PM
Great, thanks. I'll try using AttributesMapper first and see how that works.