Tomcat issue: How to get a realm stored in a database rather than from a file

hi all,

how to get a realm stored in a database rather than from a file
i m using struts 1.1, tomcat 5.0.28, mysql...

1. so far this works fine for me (with basic j_security_check)

    <Resource name="MyUsers" auth="Container"
                      type="org.apache.catalina.UserDatabase"
            description="User database that can be updated and saved">
    </Resource>
    <ResourceParams name="MyUsers">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/my-users.xml</value>
      </parameter>
    </ResourceParams>

2. but i prefer to get the username and password from the datebase,
    after refer to the document, i did sth like this in serverl.xml (but it doesnt work)... please help

<!-- (Comment out!!)
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                 debug="0" resourceName="UserDatabase"/>
-->
      <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="0"
             driverName="org.gjt.mm.mysql.Driver"
          connectionURL="jdbc:mysql://xxx.xxx.xxx.xxx/xxx"
         connectionName="xxx" connectionPassword="xxx"
              userTable="user" userNameCol="username" userCredCol="password"
          userRoleTable="user" roleNameCol="depname" />


cheers,
george
tsunpoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
Does this step-by-step guide help any?

http://sxs.thexdershome.com/internet_serving/c619.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TimYatesCommented:
Also, make sure your connect string is in the format:

   jdbc:mysql://localhost:3306/MyDatabaseName

And check catalina.out for JDBC errors on startup...
0
tsunpoAuthor Commented:
Hi TimYates,

Thats what I refered to... but doesnt work...  :p

Accidentally found the solution by wild guess... knackered

        <Context path="/bioinfo" docBase="bioinfo" debug="0" reloadable="true">
          <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="0"
                 driverName="com.mysql.jdbc.Driver"
              connectionURL="jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxx"
             connectionName="xxx" connectionPassword="xxx"
                  userTable="users" userNameCol="user_name" userCredCol="user_pass"
              userRoleTable="user_roles" roleNameCol="role_name"/>
        </Context>

Me is doing bioinfomatics as well, hope to ask you other questions somedays.


Thanks anyway,
George
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

TimYatesCommented:
Ahhh...wrong driver class eh?  Yeah, it's confusing as there are 2 out there...  and it's hard to tell which one you have (I have even seen them combined) ;-)

Yay!  Bioinformatics :-) whereabouts are you doing it?
0
TimYatesCommented:
Oooooh!  Thanks for the points too!!

I'll have to help extra hard with your next question ;-)

Tim
0
tsunpoAuthor Commented:
Hi Tim,

no no no no... did u see the <Context> part, thats the right place to put <Realm> :p
it seems either port number or driver is not the main issue of this problem...

i don know if it is the proper way to do with Struts. Say, what will u do to cope with
the login logout via a database rather than MemoryUserDatabaseFactory  :)


my company is doing genotyping, mapping and all the SNP things
george
0
TimYatesCommented:
Ooooh, SNP :-)

Ahhh, the way I do it is with my own classes and table of users and encrypted passwords (then using the session to store the user's details), and not via the Tomcat realm...

Your way would work just as well (afaik)
0
tsunpoAuthor Commented:
any step-by-step articles??  :p  thanks in advance

SNP, microarray, AoD, Sequencing, FP...
0
TimYatesCommented:
I do my login "kinda" like this:

http://www.onjava.com/pub/a/onjava/2001/11/14/jsp_servlets.html?page=2

Heh, as you can see, I currently use Struts (though I am now looking into JSF, which seems like an immprovement, but I'll know more after I read my 200 page book I just bought) ;-)

I store the passwords as MD5 hashes in the database, so they cannot be extracted if anyone just views the table...

Basically, take username, encrypt password, send to business layer, if that returns a user, then add that user object to the session (so I can then display information like fullname, address, etc ;-)

But as I said, your way is cool too :-)

> SNP, microarray, AoD, Sequencing, FP...

We do similar stuff to you from the sound of it :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.