spring-ldap
spring-ldap copied to clipboard
Provide a way to search in multiple base DNs
In my ldap the users are located in DN=(ou=users,dc=example,dc=com), and service accounts in DN=(ou=sa,dc=example,dc=com). The size of LDAP is huge and it is crucial to limit the search scope to these org. units.
But I have the same entity to be retrieved from these ous:
@Entry(objectClasses = ["top", "person", "user"])
class LdapUser {
@Id
lateinit var id: Name
@Attribute(name = "objectGUID", type = Attribute.Type.BINARY)
lateinit var objectGUID: ByteArray
}
Therefore I have to perform the following code to search for the only record by objectGUID:
val ldapUser = ldapTemplate.find(
query().base("ou=users").filter(guidFilter),
LdapUser::class.java
).firstOrNull() ?: ldapTemplate.find(
query().base("ou=sa").filter(guidFilter),
LdapUser::class.java
).firstOrNull()
Please, provide a way to search multiple organizational units in one query.
@goto1134, thanks for the suggestion. It looks like in your case you are wanting to search for one and then if no results, then search for the other. Others want a union, while others may want duplicates to be resolved in another way.
I think the framework can perform a union of the results. That allows you in your use case to take the first result and others to perform their own de-duping logic.
Are you interested in providing a PR that adds LdapQueryBuilder#base(String...) and changes DefaultLdapClient#search to perform the same search per-base and union the results?
@jzheaux , sure, it seems fun for me to contribute to spring.
Yet there are problems I am already facing: I can't build the project due to 401 while trying to retrieve a project dependency.
A problem occurred configuring root project 'spring-ldap'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve io.spring.gradle:spring-io-plugin:0.0.8.RELEASE.
Required by:
project :
> Could not resolve io.spring.gradle:spring-io-plugin:0.0.8.RELEASE.
> Could not get resource 'https://repo.spring.io/plugins-release/io/spring/gradle/spring-io-plugin/0.0.8.RELEASE/spring-io-plugin-0.0.8.RELEASE.pom'.
> Could not GET 'https://repo.spring.io/plugins-release/io/spring/gradle/spring-io-plugin/0.0.8.RELEASE/spring-io-plugin-0.0.8.RELEASE.pom'. Received status code 401 from server:
Could you provide a fix for this issue?