File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes How to configure tomcat for LDAP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to configure tomcat for LDAP" Watch "How to configure tomcat for LDAP" New topic

How to configure tomcat for LDAP

Jyoti Dinkar

Joined: Apr 23, 2013
Posts: 3
Hi friends,

I'm having a really hard time configuring my tomcat to authenticate a user by AD .

My server structure is :
users -->CN=testUser,OU=tomcat,OU=system,DC=company,DC=com

server.xml file :
<Realm className="org.apache.catalina.realm.JNDIRealm" debug="99"

I am using basic authentication in my web.xml:

<web-resource-name>Logging Area</web-resource-name>
Authentication for registered users.
<realm-name>enter Username</realm-name>

Problem is :When i try to login with userName: testUser ,I am getting error message :javax.naming.InvalidNameException.
But when i login with userName:CN=testUser,OU=tomcat,OU=system,DC=company,DC=com,I can login .
I dont understand why I am not able to login with just userName only???
Or what changes i need to do ,to make it work correctly

Carles Gasques
Ranch Hand

Joined: Apr 19, 2013
Posts: 199
you have to login with your distinguished name "CN=testUser,OU=tomcat,OU=system,DC=company,DC=com" not with your user name "testUser".
You have a bind user to connect with ldap and your full dn is how the ldap recognizes you, the user name alone mean nothing to ldap.

No changes to do, because is the expected behaviour.


Jyoti Dinkar

Joined: Apr 23, 2013
Posts: 3
thanks Carles for your reply.

but I want to login with userName only,Is that possible??
If yes,then how??
Carles Gasques
Ranch Hand

Joined: Apr 19, 2013
Posts: 199
Sorry I was misleading you,
My mistake messing the login of the ldap bind user with the login of the tomcat users.

Have you tested

instead of

Best reggards and my appologies,
Jyoti Dinkar

Joined: Apr 23, 2013
Posts: 3
I tried this also..

it doesn't help
to login I still need to give the complete pattern:

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

One of the biggest mistakes that people make when setting up LDAP is trying to mirror the corporate structure as directories in LDAP. It doesn't work well, and when people move around, it's a real pain for maintenance.

So my LDAP directory is organized more like this:

[ list of CNs of employees, with uid and password attributes]

[ list of memberUids corresponding to employee uids]

[ list of memberUids of authorized administrators ]
[ list of memberUids of authorized auditors ]

There are also 2 different ways to test authorization using the LDAP realm. One is to configure it so that the Realm will attempt to connect to the LDAP server using the user-supplied id and password from the login form. Successful connection means successful login.

The other way to test authorization is to use a general query connection userid/password to connect to LDAP and have the LDAP server do searches for the actual userid/password. You must provide the search query.

The search query under the scheme I outlined above would be more like this:

I didn't have a working example handy, so this isn't a full and authoritative solution, but it's the basic plan that I use. The Tomcat LDAP Realm docs are more complete and accurate.

Note that if your "LDAP" is actually Active Directory and you want to use the user's Windows login credentials, they have their own particular format.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: How to configure tomcat for LDAP
It's not a secret anymore!