• 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

LDAP connection through JNDI WAS 5

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get a connection to a LDAP server through JNDI.
I don't need the LDAPContext as a true JNDI context and store objects, but I do want to change LDAP entries, like user attributes.
I regard the LDAP connection as a "DataSource" (which differs in a test or production system).
Where in WAS5 do I create such an entry? I've tried putting it in
"Resource Environment Providers", but can't use it.
In my code, I'd like to do something like
InitialContext initialCtx = new InitialContext();
LdapContext ctx = (LdapContext)initialCtx.lookup("ldap/myserver");
ctx.getAttributes("");
...
So the JNDI name "ldap/myserver" is a LDAP connection, not the initialcontext. The initial context is WAS's.
Every example I find is about how to put the JNDI context as LDAP. I guess I could do that, but how would I add that in WAS?
Regards,
/Tom
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, this idea won't work. For LDAP, you don't create a datasource, you create an entirely different InitialContext (not the default) using a different InitialContext Factory. It's the InitialContext itself that's the connection into LDAP, and not something you get from the InitialContext like a DataSource.
I advise you to read the LDAP examples in the JNDI documentation on Sun's website to understand how this works.
Kyle
 
Thomas Olausson
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgive me for the bad explanation.
I understand that Ldap isn't a datasource,
but I'd like the connection to a LDAP database to be written to the context.
I don't use LDAP for any JNDI referanceable objects.
I use the default WAS JNDI context.
Since you can specify datasources, mail sessions, mq connections etc, why can't a connection to a LDAP database be stored the same way?
When you get a Datasource, you do something like
Context ctx = new InitialContext();
Datasource ds = (Datasource) ctx.lookup("jdbc/mydatasource");
(jdbc/mydatasource is configured through the WAS admin console.)
I'm after someting like
Context ctx = new InitialContext();
LDAPconnection ldap = (LDAPconnection) ctx.lookup("ldap/myldapdatabase");
Regards,
/Tom
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Listen to the explanation. JNDI is the ONLY API for connecting to LDAP. There is no other API for it. This is the way that the JNDI specification is written, and it's the way everyone else uses LDAP. There's no problem in creating a second InitialContext.
I understand you want some sort of consistency, but you're not going to get it. This is not a WebSphere issue -- this is the way the specification is written.
Kyle
 
Thomas Olausson
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, got it. Another context would work.
Something like this?

I was hoping I could put the URL to the LDAP server in the JNDI context,
I tried using the URL provider, but it doesn't take ldap://, so I guess
I have to write my own.
Thanks!
/Tom
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code above is exactly what you need to do. And yes, you should be able to use a URL provider if you choose.
Kyle
 
    Bookmark Topic Watch Topic
  • New Topic