Skip to content

Support custom converters #633

Closed
Closed
@goto1134

Description

@goto1134

Active Directory LDAP stores objectGUID (a unique id) as a 32 byte array.

@Entry(objectClasses = ["top", "person", "user"], base = "ou=users")
class LdapUser {

    @Id
    lateinit var id: Name

    @Attribute(name = "objectGUID", type = Attribute.Type.BINARY, readonly = true)
    lateinit var guid: UUID
}

When I use the mentioned class LdapUser with java.util.UUID guid I get the following error:

...
Caused by: org.springframework.ldap.odm.core.impl.InvalidEntryException: Missing converter from class [B to class java.util.UUID, this is needed for field guid on Entry class ru.tinkoff.helicopter.user_info.repository.AlternativeLdapUser
	at org.springframework.ldap.odm.core.impl.DefaultObjectDirectoryMapper.verifyConversion(DefaultObjectDirectoryMapper.java:189)
	at org.springframework.ldap.odm.core.impl.DefaultObjectDirectoryMapper.addManagedClass(DefaultObjectDirectoryMapper.java:165)
	at org.springframework.ldap.odm.core.impl.DefaultObjectDirectoryMapper.getEntityData(DefaultObjectDirectoryMapper.java:108)
	at org.springframework.ldap.odm.core.impl.DefaultObjectDirectoryMapper.attributeFor(DefaultObjectDirectoryMapper.java:483)
	at org.springframework.data.ldap.repository.query.LdapQueryCreator.getAttribute(LdapQueryCreator.java:138)
	at org.springframework.data.ldap.repository.query.LdapQueryCreator.create(LdapQueryCreator.java:89)
	at org.springframework.data.ldap.repository.query.LdapQueryCreator.create(LdapQueryCreator.java:43)
	at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:119)
	at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95)
	at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81)
	at org.springframework.data.ldap.repository.query.PartTreeLdapRepositoryQuery.createQuery(PartTreeLdapRepositoryQuery.java:81)
	at org.springframework.data.ldap.repository.query.AbstractLdapRepositoryQuery.execute(AbstractLdapRepositoryQuery.java:80)
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
	at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:159)
	at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:138)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.data.repository.core.support.MethodInvocationValidator.invoke(MethodInvocationValidator.java:98)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
	at jdk.proxy3/jdk.proxy3.$Proxy102.findByUsername(Unknown Source)
...

I added the needed converter to the spring context, but nothing changed.

Next, I added the following configuration class to make the conversion work:

@Configuration
class LdapConverterConfig {
    @Autowired
    fun converter(conversionService: GenericConversionService, ldapTemplate: LdapTemplate) {
        val conversionServiceConverterManager = ConversionServiceConverterManager(conversionService)
        (ldapTemplate.objectDirectoryMapper as DefaultObjectDirectoryMapper).setConverterManager(conversionServiceConverterManager)
    }
}

Please, support the global conversion service or add a more feasible way to specify converters.
Also please add related documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions