Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to get this specific list from an LDAP Server?

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

We are connected to an LDAP Server with this structure:
Under OU=OUs as the root tree we have all our units, each unit is represented by a folder.
Inside each unit are the departments, each unit can have 1 or more departments. Again, each department is represented by a folder.
Inside each department are the actual users.
Let's assume that the unit and department names are represented at the description property.
I would like to get a list of of all the units names, meaning I would like to get a list of the properties of the folders sitting only at the first level below OUs.
I am familiar with the javax.naming package API and code yet I was unable to achieve this.
If I use SearchControls.SUBTREE_SCOPE it goes over the entire directory, including nested folders and users and get me the description of each one of them: This is not good since we have 5000 users and I need to get the unique units by code (For example using a SET collection) and the performance hit is very large since all I need are the folders at the first level only, which sums up to no more than 50 names.
If I use SearchControls.ONELEVEL_SCOPE or SearchControls.OBJECT_SCOPE I receive an empty list back.
Perhaps I am using ONELEVEL_SCOPE and OBJECT_SCOPE wrong or perhaps there is a different method to achieve what I need.
Can someone please show me a code example to get the exact folders I need (lists of the units)?

Thank you in advance,
Roy
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roy,

I saw this post and wondered if you had any luck? I also have a problem accessing properties but further on down the tree. It seems I can not retrieve and Numerics (MS - Integer8, I think)... specifically the pwdLastSet value...have you ever had success accessing a similar value?

Here is our code, not sure if it helps your case

[CODE]
InitialDirContext ctx = new InitialDirContext(props);
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
String[] attrIDs = {"cn", "distinguishedName", "description"};
String filt = "cn="+userid;
constraints.setReturningAttributes(attrIDs);
NamingEnumeration results = ctx.search("ou=Foo,DC=foo,DC=foo,DC=foo,DC=foo", filt, constraints);

if (results != null && results.hasMore()){
status = 1;
SearchResult si = (SearchResult)results.next();
Attributes attrs = si.getAttributes();
if (attrs != null) {
for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements() {
Attribute attr = (Attribute)ae.next();
String attrId = attr.getID();
if (attrId.equals("distinguishedName")){
{
for (Enumeration vals = attr.getAll(); vals.hasMoreElements() {
str = str + vals.nextElement();

etc., etc.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic