Link to home
Start Free TrialLog in
Avatar of tsunpo
tsunpo

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, make sure your connect string is in the format:

   jdbc:mysql://localhost:3306/MyDatabaseName

And check catalina.out for JDBC errors on startup...
Avatar of tsunpo
tsunpo

ASKER

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
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?
Oooooh!  Thanks for the points too!!

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

Tim
Avatar of tsunpo

ASKER

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
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)
Avatar of tsunpo

ASKER

any step-by-step articles??  :p  thanks in advance

SNP, microarray, AoD, Sequencing, FP...
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 :-)