aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to configure tomcat for LDAP" Watch "How to configure tomcat for LDAP" New topic
Author

How to configure tomcat for LDAP

Jyoti Dinkar
Greenhorn

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
Roles-->CN=Admin,OU=Roles,OU=tomcat,OU=system,DC=company,DC=com

server.xml file :
<Realm className="org.apache.catalina.realm.JNDIRealm" debug="99"
connectionURL="ldap://SERVER_URL:389"
connectionName="CN=testUser,OU=tomcat,OU=system,DC=company,DC=com"
connectionPassword="**Password**"
userBase="OU=tomcat,OU=system,DC=company,DC=com"
userSearch="(CN={0})"
userSubtree="true"
roleBase="OU=Roles,OU=tomcat,OU=system,DC=company,DC=com"
roleName="Admin"
roleSearch="(member={0})"
roleSubtree="true"
/>

I am using basic authentication in my web.xml:

<security-constraint>
<web-resource-collection>
<web-resource-name>Logging Area</web-resource-name>
<description>
Authentication for registered users.
</description>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>*</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>enter Username</realm-name>
</login-config>

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
    
    1
Hi,
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.


Cheers,

Jyoti Dinkar
Greenhorn

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
    
    1
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
Greenhorn

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: 16145
    
  21

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:

ou=employees,dc=mousetech,dc=com
[ list of CNs of employees, with uid and password attributes]

ou=users,ou=tomcat,ou=services,dc=mousetech,dc=com
[ list of memberUids corresponding to employee uids]

ou=groups,ou=tomcat,ou=services,dc=mousetech,dc=com
ou=administrators,ou=groups,ou=tomcat,ou=services,dc=mousetech,dc=com
[ list of memberUids of authorized administrators ]
ou=auditors,ou=groups,ou=tomcat,ou=services,dc=mousetech,dc=com
[ 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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to configure tomcat for LDAP