You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dan Barron <db...@ddive.com> on 2004/06/19 00:46:02 UTC

Allow user to change password in JDBCRealm

Hello,

I've looked around for some time now for a clear answer on this topic, but 
have not had much luck.

I have user authentication setup using JDBCRealm w/ MySQL and am able to 
login/logout and authenticate users just fine.  My question is, once a user 
is logged in, is the user's login information (uname/pass) available 
somewhere where I can easily grab it and modify it so I can allow my users 
to change their password?

Thanks,

Dan


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Allow user to change password in JDBCRealm

Posted by Robert Harper <ro...@iat-cti.com>.
I think this is all kept in the server's beans. To access this you need to us
the JMX mess.

I have finally figured out how to do it using the normal tomcat-users.xml
database. To load the bean server try this:

MBeanServer m_BeanServer;

if(MBeanServerFactory.findMBeanServer(null).size() > 0)
{
   m_BeanServer = (MBeanServer)BeanServerFactory.findMBeanServer(null).get(0);
}
else
{
   m_BeanServer = MBeanServerFactory.createMBeanServer();
}

then to add a user:

// build the initial name of the bean to act upon
ObjectName oname = 
  new ObjectName("Users:type=UserDatabase,database=UserDatabase" );
// next call one of the methods of the bean. I'll show how to add one
// set up the parameters
String params[] = new String[3];
String types[] = new String[3];

params[0] = strID;
params[1] = strPassword;
params[2] = strName;
types[0] = "java.lang.String";
types[1] = "java.lang.String";
types[2] = "java.lang.String";

// invoke the method
m_BeanServer.invoke( oname, "createUser", params, types );
// note this does not return the user bean as the docs say

// find the user and add a role to the user
String param[] = new String[1];
String type[] = new String[1];
param[0] = strID;
type[0] = "java.lang.String";

String userBean = (String)m_BeanServer.invoke( oname, "findUser", param, type );
// now if you have the user
if( userBean != null )
{
String param[] = new String[1];
String type[] = new String[1];
param[0] = strRole;
type[0] = "java.lang.Sring";
ObjectName oname = new ObjectName( userBean );
m_BeanServer.invoke( oname, "addRole", param, type );
}

You will have to add some exception handling but this should get you on your way
if you are using Tomcat's user authentication. I hope this helps.


Robert S. Harper

> -----Original Message-----
> From: Dan Barron [mailto:dbarron@ddive.com]
> Sent: Friday, June 18, 2004 4:46 PM
> To: Tomcat Users List
> Subject: Allow user to change password in JDBCRealm
> 
> Hello,
> 
> I've looked around for some time now for a clear answer on this topic, but
> have not had much luck.
> 
> I have user authentication setup using JDBCRealm w/ MySQL and am able to
> login/logout and authenticate users just fine.  My question is, once a user
> is logged in, is the user's login information (uname/pass) available
> somewhere where I can easily grab it and modify it so I can allow my users
> to change their password?
> 
> Thanks,
> 
> Dan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org