I encounter this issue with spring LDAP:
class javax.naming.ldap.LdapName cannot be cast to class java.lang.String (javax.naming.ldap.LdapName is in module java.naming of loader 'bootstrap'; java.lang.String is in module java.base of loader 'bootstrap')
Here is the piece of codes where the issue occurs
private void createUser(LdapAttributes ldapAttributes) {
LdapName dn = LdapNameBuilder
.newInstance()
.add("ou", "users")
.add("cn", ldapAttributes.getName())
.build();
DirContextAdapter context = new DirContextAdapter(dn);
context.setAttributeValues(
"objectclass",
new String[]
{ "top",
"person",
"organizationalPerson",
"inetOrgPerson" });
context.setAttributeValue("cn", ldapAttributes.getName());
context.setAttributeValue("sn", ldapAttributes.getName());
context.setAttributeValue("userPassword", ldapAttributes.get("userPassword"));
ldapTemplate.bind(context);
}
I am using spring org.springframework.ldap:spring-ldap-core and org.springframework.ldap:spring-ldap-ldif-core both in version 2.4.1
Springboot is in version 2.7.12
did you try
ldapAttributes.getName().toString()?Here is the code that i test with Spring