I has problems try go search groups on LDAP using spring-ldap search with parallelism.
I am make a batch processing to load data from SQL database to LDAP. I use spring-boot and spring-ldap.
My algorithm tries search for a group at ldap using its gidNumber. It works fine when run without parallelism (stream.parallelStream). But when I iterate a list with parallelStream I catch sometimes this exception:
java.lang.ClassCastException: class com.sun.jndi.ldap.LdapCtx cannot be cast to class org.springframework.ldap.core.DirContextAdapter (com.sun.jndi.ldap.LdapCtx is in module java.naming of loader 'bootstrap'; org.springframework.ldap.core.DirContextAdapter is in unnamed module of loader java.net.URLClassLoader @4f0f76b4)
I has cast the object from ContextMapper#mapFromContext to DirContextAdapter. Spring-ldap reference says this method should return a instance of DirContextAdapter if I does not change DirObjectFactory LdapContextSource.
My code is similar to:
ldapTemplate.search(
query().base(groupName()).where("gidNumber").is(Long.toString(gid)),
(ContextMapper<GroupLdap>) ctx -> {
DirContextAdapter context = (DirContextAdapter) ctx;
return new GroupLdap(context, true);
})
My application is a batch processing to load data from SQL database to LDAP. I use spring-boot and spring-ldap.
I'm using spring-boot 2.1.4, OpenLdap and ORACLE to SQL-DB. And open-jdk-zulu 11.
My algorithm tries search for a group at ldap using its gidNumber. It works fine when run without parallelism (stream.parallelStream). But when I iterate a list with parallelStream() and I catch sometimes a ClassCastException:
I put a ldap pool conection but it does not work.
My code is similar to:
ldapTemplate.search(
query().base(groupName()).where("gidNumber").is(Long.toString(gid)),
(ContextMapper<GroupLdap>) ctx -> {
DirContextAdapter context = (DirContextAdapter) ctx;
return new GroupLdap(context, true);
})
groupName is a Name with references to "ou=groups,dc=fff,dc=br";
gid is a number with gitNumber of searched group.
GroupLdap is a internal representation of group on LDAP.
With parallelism, i receive sometimes the exception:
java.lang.ClassCastException: class com.sun.jndi.ldap.LdapCtx cannot be cast to class org.springframework.ldap.core.DirContextAdapter (com.sun.jndi.ldap.LdapCtx is in module java.naming of loader 'bootstrap'; org.springframework.ldap.core.DirContextAdapter is in unnamed module of loader java.net.URLClassLoader @4f0f76b4)
I has cast the object from ContextMapper#mapFromContext to DirContextAdapter. Spring-ldap reference says this method should return a instance of DirContextAdapter if I does not change DirObjectFactory LdapContextSource.