Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support custom converters #633

Open
goto1134 opened this issue Apr 9, 2022 · 0 comments
Open

Support custom converters #633

goto1134 opened this issue Apr 9, 2022 · 0 comments
Milestone

Comments

@goto1134
Copy link

goto1134 commented Apr 9, 2022

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants