0

I am trying to dynamically assign users and their roles using MYSQL database, and use it in Tomcat users configuration file (tomcat-users.xml)

All the example I have gone through on internet shows to statically add username, password and role. Like this:

<role rolename="admin-gui"/>
  <role rolename="admin-script"/>

  <user username="probe" password="probe" roles="probeuser,poweruser,manager,manager-gui,poweruserplus" />
  <user username="tomcat" password="s3cret" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

But I want to fetch the credentials from database.

I tried using JDBC Realm in server.xml config file, and created database conection through it. By following this tutorial

<Realm  className="org.apache.catalina.realm.JDBCRealm"
        driverName="org.gjt.mm.mysql.Driver"
        connectionURL="jdbc:mysql://localhost:3306/tomcat_realm"
        connectionName="root" connectionPassword="12345678"
        userTable="users" userNameCol="user_name" userCredCol="user_pass"
        userRoleTable="user_roles" roleNameCol="role_name" 
/>

I don't know I am doing right or not. If I am right, then where to run SQL queries and how to insert the result to tomcat-users.xml configuration file.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
bizprat
  • 11
  • 2

0 Answers0