LDAP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesLDAP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 26th, 2004, 09:20 PM
jeremyo jeremyo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 jeremyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
JNDI ldap search problems

Does anyone have any idea why a search using DirContents.search() would return duplicate records where no duplicates exist. Code below.

public Vector getListByName(String inName)
{
vecList = new Vector();
env= new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://lftdev01:389");
env.put(Context.SECURITY_PRINCIPAL, "cn=admin,dc=rah,dc=sa,dc=gov,dc=au");
env.put(Context.SECURITY_CREDENTIALS, "secret");


try {
// Create the initial context
DirContext ctx = new InitialDirContext(env);
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
matchAttrs.put(new BasicAttribute("cn", inName));
String[] attrIDs = {"cn", "uid",};
SearchControls ctls = new SearchControls();
NamingEnumeration answer = ctx.search("ou=staff,dc=rah,dc=sa,dc=gov,dc=au", "cn=*"+inName+"*",ctls);
Vector tmpuid = new Vector();
Vector tmpcn = new Vector();
Attribute attr;
while (answer.hasMore())
{
SearchResult sr = (SearchResult)answer.next();
Attributes att = sr.getAttributes();
for (NamingEnumeration ae = att.getAll(); ae.hasMore()
{
attr = (Attribute)ae.next();
if(attr.getID().equals("uid"))
{
for (NamingEnumeration e = attr.getAll(); e.hasMore(); tmpuid.addElement(String.valueOf(e.next())));
}
else
if(attr.getID().equals("cn"))
{
for (NamingEnumeration e = attr.getAll(); e.hasMore(); tmpcn.addElement(String.valueOf(e.next())));
}

}
int i = 0;
while(i < tmpuid.size())
{
vecList.addElement(tmpuid.elementAt(i)+"|"+tmpcn.elementAt(i));
i++;
}
}

// Close the context when we're done
ctx.close();
} catch (NamingException e) {System.out.println("List failed: " + e);}
return vecList;
}

Thanks in advance,
Jeremy

Reply With Quote
  #2  
Old September 27th, 2004, 10:34 AM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,845 Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 20 h 16 m 27 sec
Reputation Power: 634
I'd assume it has something to do with your while (which language is this? java?)
while (answer.hasMore())
try it outside the loop

Reply With Quote
  #3  
Old September 27th, 2004, 06:24 PM
jeremyo jeremyo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 jeremyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yep its java, I dont think the loop is the problem though, the duplicates appear throughout the resultset ie 1,2,3,1,4,5,1,2.
There are no duplicate entries in the ldap however.
Very Strange.

This one has me puzzled.


Think ill move on and come back to it later on in the project.

Reply With Quote
  #4  
Old September 27th, 2004, 08:16 PM
jeremyo jeremyo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 jeremyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Opps, i feel like such a tool, you were right.
Staring at a computer screen 12 hours a day mst be taking its toll.

Thanks Viper

Reply With Quote
  #5  
Old September 27th, 2004, 10:05 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,845 Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level)Viper_SB User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 20 h 16 m 27 sec
Reputation Power: 634
glad I could help

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesLDAP Programming > JNDI ldap search problems

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap