Skip to content

@Query repository methods are unable to parse special characters in base (spring-data-ldap:3.5.3) #572

@floringolintchi

Description

@floringolintchi

Seems like Query methods in LdapRepository cannot handle RDNs with special characters.

@Repository
public interface OrganizationRepository extends LdapRepository<Organization> {

    @Query(base = "ou=:ou,dc=spring,dc=org", searchScope = SearchScope.OBJECT, value = "(|(objectclass=top)(objectclass=organizationalUnit))")
    Organization findWithMyCustomQueryWithBase(String ou);

    @Query(base = "dc=spring,dc=org", searchScope = SearchScope.ONELEVEL, value = "(ou=:ou)")
    Organization findWithMyCustomQueryWithFilter(String ou);
}

Then trying to search with base for entry "ou=people*!(/#$%,dc=spring,dc=org":

org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - Unable to perform the search because base entry 'ou=people\2a!\28/\5c#$%,dc=spring,dc=org' does not exist in the server.]
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:185)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:383)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:321)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:649)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:585)
at org.springframework.ldap.core.LdapTemplate.find(LdapTemplate.java:1768)
at org.springframework.ldap.core.LdapTemplate.find(LdapTemplate.java:1789)
at org.springframework.ldap.core.LdapTemplate.findOne(LdapTemplate.java:1797)
at org.springframework.data.ldap.repository.query.LdapQueryExecution$FindOneExecution.execute(LdapQueryExecution.java:62)
at org.springframework.data.ldap.repository.query.LdapQueryExecution$ResultProcessingExecution.execute(LdapQueryExecution.java:128)
at org.springframework.data.ldap.repository.query.AbstractLdapRepositoryQuery.execute(AbstractLdapRepositoryQuery.java:86)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:170)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:158)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:170)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:149)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:69)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
at jdk.proxy3/jdk.proxy3.$Proxy51.findWithMyCustomQueryWithBase(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:360)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
at jdk.proxy3/jdk.proxy3.$Proxy51.findWithMyCustomQueryWithBase(Unknown Source)
at com.nsn.query_bug_demo.QueryBugDemoApplication.startup(QueryBugDemoApplication.java:33)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:383)
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:255)
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:174)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:454)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:387)
at org.springframework.boot.context.event.EventPublishingRunListener.ready(EventPublishingRunListener.java:109)
at org.springframework.boot.SpringApplicationRunListeners.lambda$ready$6(SpringApplicationRunListeners.java:80)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
at org.springframework.boot.SpringApplicationRunListeners.ready(SpringApplicationRunListeners.java:80)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:332)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
at com.nsn.query_bug_demo.QueryBugDemoApplication.main(QueryBugDemoApplication.java:20)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50)
Caused by: javax.naming.NameNotFoundException: [LDAP: error code 32 - Unable to perform the search because base entry 'ou=people\2a!\28/\5c#$%,dc=spring,dc=org' does not exist in the server.]; remaining name '"ou=people\2a!\28/\5c#$%,dc=spring,dc=org"'
at java.naming/com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3285)
at java.naming/com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3206)
at java.naming/com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2997)
at java.naming/com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1875)
at java.naming/com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1798)
at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:392)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:358)
at java.naming/javax.naming.directory.InitialDirContext.search(InitialDirContext.java:305)
at org.springframework.ldap.core.LdapTemplate.lambda$search$2(LdapTemplate.java:315)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:370)
... 57 more

I've included a demo with an embedded LDAP server showcasing this issue.

query_bug_demo.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions