This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Tomcat Custom Realm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat Custom Realm" Watch "Tomcat Custom Realm" New topic
Author

Tomcat Custom Realm

Carlos Lacerda
Ranch Hand

Joined: Apr 09, 2003
Posts: 34
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!!!


Carlos Lacerda, Brasil
[SCJP 1.4-5.0] [SCJD] [SCWCD] [SCEA] [OCA-OAS 10g]
Muhammed Patel
Greenhorn

Joined: Feb 26, 2009
Posts: 5
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


In my world they are all ponies and eat rainbows and poop butterflies
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Tomcat comes along with excellent documentation.

Start here: http://tomcat.apache.org/tomcat-6.0-doc/realm-howto.html
Muhammed Patel
Greenhorn

Joined: Feb 26, 2009
Posts: 5
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

Joined: Mar 21, 2010
Posts: 10
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
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
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.


Ping & DNS - my free Android networking tools app
Ofri Dagan
Greenhorn

Joined: Mar 21, 2010
Posts: 10
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

Joined: Jun 25, 2001
Posts: 16020
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Zarkasih Adlan
Greenhorn

Joined: Mar 24, 2011
Posts: 1
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Tomcat Custom Realm