I
I
IvanN7772020-12-28 15:57:49
Java
IvanN777, 2020-12-28 15:57:49

How can I get the organizationalUnit tree in ldap (Open ldap) or at least the organizationalUnit tree directly from the parent?

Let's have categories

-Worker
--Forestry worker --It
industry worker
---
Frontend ---Backend
--Fishing worker

Wrote the code

List<String> nameList = ldapTemplate.search("", "(objectClass=organizationalUnit)",
    new AttributesMapper<String>() {
    @Override
    public String mapFromAttributes(Attributes attributes) throws NamingException {
      String group = "";
      Attribute groupAttr = attributes.get("ou");
      Attribute userAttr = attributes.get("cn");
      if (groupAttr != null) {
        group = groupAttr.get() + "\n";
      }
      return group;
    }

In general, it works fine, it displays all groups, but the hierarchy is lost, that is, the tree degenerates into a list.
If I could somehow shoot or the whole tree, but with the ability to find out the hierarchy
Or add in the filter that it is necessary to search only directly for the child, but I would have to pull the ldap more, but not critical.
(objectClass=organizationalUnit)
This filter will select all groups, and if I could select only child groups and not deeper, I could make a hierarchy

I looked at the instructions
https://social.technet.microsoft.com/wiki/contents...
But I did not find an opportunity there, maybe someone - will be useful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Bezrukov, 2020-12-28
@IvanN777

Use SearchBase (where to start searching) and SearchScope (search scope - Base, OneLevel or SubTree)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question