Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat Custom Realm

 
Carlos Lacerda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, some knows where meeting an example of as to create a JDBCrealm or DataSourceRealm or one Realm custom ?
I have my rules to effect login in a necessary DB therefore to customize.


Help!!!
 
Muhammed Patel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to do the same thing.

Have a look at the following link:

http://lekkimworld.com/2005/07/29/1122648646441.html

cheers ,
Moe
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat comes along with excellent documentation.

Start here: http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html
 
Muhammed Patel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bauke.

I had a look at that documentation first. Only problem was i was developing a custom implementation of the RealmBase class as our authentication structure is a little different and did not find my answer there.

Buts it's ok now i have just figured it out.

Thanks again
 
Ofri Dagan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to write my own Realm to authenticate my users. I have written a class extending org.apache.catalina.realm.RealmBase, compiled to a .jar file and put it in the /lib directory. Then I added this to server.xml:

<Realm className="wstest.tomcat.security.MyRealm"
resourceName="myrealm"/>

Tomcat doesn't seem to "see" my new jar... When I start Tomcat I get ClassNotFoundException

Can someone tell me what is the reason Tomcat can't find MyRealm?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat does not have a "/lib" directory, so where did you put the jar file? If you meant the WEB-INF/lib directory of a web app, then be aware that Realm implementations need to go into Tomcat's classpath, not your web app's classpath. Try the "common" or "shared" directories instead.
 
Ofri Dagan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mmm actually tomcat 6 does ships with a lib folder.
I finally figured I had something wrong with the way I created my jar. It works now.
Thanks, and sorry...
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18214
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And another zombie lurches back to life!

Ulf, you're thinking Tomcat 5 and earlier. They got rid of all that common/shared lib stuff in Tomcat6. now it's just TOMCAT_HOME/lib.

For the benefit of anyone wondering, by the way, it's easy to subclass the Tomcat database realm class. I did it because I needed Windows-style authentication (case-insensitive user name, case-sensitive password). My subclass folds the userid to lower case before querying the database.
 
Zarkasih Adlan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for this thread! I had to extend the DataSourceRealm just to change one line in the digest() method because my organisation uses a very obscure encoding method. I followed all the instructions on the manual (and in this thread), but was stuck for days due to a ClassNotFoundError. But, alas it's my own stupid mistake. I added this to my context.xml:

<Realm className="com.mycompany.CustomDataSourceRealm" debug="0"
dataSourceName="jdbc/mydb" digest="MD5" localDataSource="true"
userTable="table1" userNameCol="id" userCredCol="cred"
userRoleTable="table2" roleNameCol="role" />

I'm a newbie and never had to create a jar before. So, what I did was jar -cvf CustomDataSourceRealm.jar CustomDataSourceRealm.class. This didn't capture the class package information, hence the class not found. So what resolved the issue was simply to jar -cvf CustomDataSourceRealm com, where com is the package folder such that the class is in com/mycompany/CustomDataSource.class. Yes, a very basic mistake, I'm putting it out here so other people won't repeat my mistake.

Next, up I'm trying to configure the container in such a way that it takes in a third parameter for authentication. I know I need to mess with mbeans-descriptor.xml abit, I'm not to sure if I need to extend GenericPrincipal. But that's another question for another thread. Any pointers would help too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic