0
votes

I have an attribute in my LDAP server that contains special characters like letters with accents.

enter image description here

This is my code to recover that attribute:

public class LdapUser implements AttributesMapper {

    @Override public Object mapFromAttributes(Attributes attributes) throws NamingException{
        if(attributes == null)
            return null;

        Presenter presenter = new Presenter();
        if(attributes.get("cn") != null)
            presenter.setFullName(attributes.get("cn").get().toString());

        if(attributes.get("uid") != null)
            presenter.setId(attributes.get("uid") .get().toString());

        return presenter;
    }
}

The problem is that in Java the value of the cn attribute is:

enter image description here

With values:

enter image description here

There is some way to set the character encoding to recover ldap attributes?

Thanks in advance!

65533 is also U+FFFD, the unicode replacement character. That means the characters have been lost. What were the original accented characters encoded as? Cp1252? ISO-8859-1? UTF-8? If unicode, were they precomposed characters or did they use combining accents? - David Conrad
LDAP uses UTF-8 character encoding with LDAP V3 clients when returning results with special chars, so if you set it explicitly with env.put('java.naming.ldap.version', '3'); and set spring charset to UTF-8 it should work. - EricLavault