I have an ldap server that I'm using to authenticate users within a tomcat web application. I'm using the JNDIRealm and it's configured within a context file and this works great.
I'll also need to search the ldap for user information. I've figured out how to do this with the "jndi method" and I have it working fine outside of tomcat by creating my own jndi context using a hashtable. However, instead of configuring the jndi properties in code, I'd like to create a JNDI Rsource in my context file right next to the Realm configuration.
I'm thinking I would do something like this:
<Resource
name="ldap"
auth="Container"
type="com.sun.jndi.ldap.LdapCtxFactory"
java.naming.factory.initial="com.sun.jndi.ldap.LdapCtxFactory"
java.naming.provider.url="ldap://localhost:389"
java.naming.security.authentication="simple"
java.naming.security.principal="uid=rjcarr,dc=example"
java.naming.security.credentials="abc123"
/>
But either tomcat tells me the resource can't be created or when I try to initialize it with something like this:
Context initctx = new InitialContext();
DirContext ctx = (DirContext) initctx.lookup("java:comp/env/ldap");
Tomcat tells me the "Cannot create resource instance". I've also added the correct resource-ref in my web.xml file, so I don't think that's the problem.
Since LDAP is being used with the JNDI method I'm assuming it should be able to be configured as a Resource, right? What am I missing?
See Question&Answers more detail:os