You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@directory.apache.org by Tom Zeller <tz...@memphis.edu> on 2009/05/12 15:44:37 UTC

1.5.5 convertAttributesFromLdif : An entry must not have two DNs

In trunk, it looks like LdifUtils.convertAttributesFromLdif() throws a
NamingException for ldif containing a dn.

The following

String ldif =
     "dn: ou=foo,dc=example,dc=edu\n" +
     "ou: foo\n" +
     "objectclass: top\n" +
     "objectclass: organizationalUnit\n";

 LdifUtils.convertAttributesFromLdif(ldif);

throws a NamingException

 LdifAttributesReader.parseAttribute(175) - An entry must not have two DNs
 LdifAttributesReader.parseAttributes(294) - Cannot parse the ldif
buffer : A ldif entry should not have two DNs

It looks like the appropriate test in LdifUtilsTest.java, was commented out

    /**
     * Test a conversion of an entry from a LDIF file
     */
    @Test
    public void testConvertToLdif() throws NamingException
    {
        String expected =
            "dn:: Y249U2Fhcm\n" +
            " Jyw7xja2VuLCBk\n" +
            " Yz1leGFtcGxlLC\n" +
            " BkYz1jb20=\n" +
            "changeType: Add\n" +
            "sn: test\n" +
            "cn:: U2FhcmJyw7\n xja2Vu\n" +
            "objectClass: to\n p\n" +
            "objectClass: pe\n rson\n" +
            "objectClass: in\n etorgPerson\n\n";

        LdifEntry entry = new LdifEntry();
        entry.setDn( "cn=Saarbr\u00FCcken, dc=example, dc=com" );
        entry.setChangeType( ChangeType.Add );

        EntryAttribute oc = new DefaultClientAttribute( "objectClass" );
        oc.add( "top", "person", "inetorgPerson" );

        entry.addAttribute( oc );

        entry.addAttribute( "cn", "Saarbr\u00FCcken" );
        entry.addAttribute( "sn", "test" );

        String ldif = LdifUtils.convertToLdif( entry, 15 );
        //Attributes result = LdifUtils.convertFromLdif( ldif );
        //assertEquals( entry, result );
    }

I tried adding "version: 1\n" to the beginning of the ldif to no avail.

Perhaps http://issues.apache.org/jira/browse/DIRSHARED-22 introduced
this behavior.

Thanks,
Tom

Re: 1.5.5 convertAttributesFromLdif : An entry must not have two DNs

Posted by Emmanuel Lecharny <el...@apache.org>.
Tom Zeller wrote:
> In trunk, it looks like LdifUtils.convertAttributesFromLdif() throws a
> NamingException for ldif containing a dn.
>   
Plain normal, but might be confusing. What happens is that this method 
tries to convert something stored using a LDIF format to an Attributes 
(JNDI). Attributes objects don't contain a DN, only attributes.

This method is a bit confusing, as it does not state that it does not 
try to convert only the attributes.

If you want to parse a LDIF to get an Attributes object, you have to use 
the LdifReader.parseLdif( String ), you'll get a List of Entry objects, 
and loop on the entry's attributes to convert them to Attribute, and 
store them into an Attributes.

FYI, we have defined a new set of classes to manage LDAP elements, based 
on the Entry element (basically, an entry is a DN plus a set of attributes).

Hope it helps.

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org