By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,737 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,737 IT Pros & Developers. It's quick & easy.

java and ldap

P: n/a
Hi there,

i have a few problems accessing a ldap server with the java api JNDI.
I am able to get attributes with the following code:

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.j ndi.ldap.LdapCtxFact
env.put(Context.PROVIDER_URL, "ldap://server:10389/");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "user=benutzer, ou=irgendwas,
o=nochwas, c=de");
env.put(Context.SECURITY_CREDENTIALS, "passwort");
try {

// Create the initial directory context
DirContext ctx = new InitialDirContext(env);
// Ask for all attributes of the object
Attributes attrs =
ctx.getAttributes("apc=einAPC,ou=irgendwas,o=nochw as,c=de");
// Find the ip adress and print
System.out.println("ip: " + attrs.get("IP").get());
} catch (NamingException e) {
System.err.println("Problem getting attribute:" + e);

But what to do, if i don't know the name of the APC?
I tried with searching, but i don't get any results:

try {
SearchControls ctls = new SearchControls();
// Specify the search filter to match
String filter = "(apc=*)";
DirContext ctx = new InitialDirContext(env);
// Search for objects using the filter
NamingEnumeration answer ="", filter, ctls);
System.out.println("sind antworten
while (answer.hasMore()) {
SearchResult sr = (SearchResult);
System.out.println(">>>" + sr.getName());
} catch (Exception err) {
System.out.println("fehler: " + err);

Structure of the directory:
|- o=nochwas, c=de
|-ou=irgendwas, o=nochwas, c=de
o=nochwas, c=de, apc=someAPC
o=nochwas, c=de, apc=anotherAPC

All apc's have an attribute apc.

Where is the problem?

Thx in advance

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.