Yap, it seem that the mess is in : http://svn.apache.org/repos/asf/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java ### protected Connection open() {
try { Context context = null; if (localDataSource) { context = ContextBindings.getClassLoader(); context = (Context) context.lookup("comp/env"); } else { StandardServer server = (StandardServer) ServerFactory.getServer(); context = server.getGlobalNamingContext(); } DataSource dataSource = (DataSource)context.lookup(dataSourceName); return dataSource.getConnection(); } catch (Exception e) { // Log the problem for posterity containerLog.error(sm.getString("dataSourceRealm.exception"), e); } return null; } ### Something strange in the tomcat JNDI Context ... Did you put something in the GlobalNamingContext, if not it perhaps a bug ! So now that you have the workaround you can submit a nice bug report ... that the way open source advance ;-) In the worst case it a feature and the documentation should be patched :-) Don't forget the post the answer in this thread. On 11/22/06, Elliott Murray <[EMAIL PROTECTED]> wrote:
Olivier Brilliant. Good spot and that fixed the problem. Not sure from reading the link why it fixed the problem to be honest (especially why I was getting App A's login page in App B!?) but it is now working as I expect! Many thanks
U welcome.
Elliott -----Original Message----- From: olivier nouguier [mailto:[EMAIL PROTECTED] Sent: 22 November 2006 12:10 To: Tomcat Users List Subject: Re: tomcat 5.5 multiple contexts using same realm bug? Hum, looking back to your previous post I've noticed that you are using context local datasource and that you missed the "localDataSource='true'" attributte in DataSourceRealm, perhaps il can explain this behaviour. Ref: http://tomcat.apache.org/tomcat-5.5-doc/realm-howto.html#DataSourceRealm On 11/22/06, Elliott Murray <[EMAIL PROTECTED]> wrote: > They are both FORM auth methods. I have not specified in web.xml any realm attribute because it relates to BASIC authentication. > > This is a snippet from web.xml and looks like pretty much for both apps. > > <login-config> > <auth-method>FORM</auth-method> > <form-login-config> > <form-login-page>/login.jsp</form-login-page> > </form-login-config> > </login-config> > > > > > -----Original Message----- > From: olivier nouguier [mailto:[EMAIL PROTECTED] > Sent: 21 November 2006 18:20 > To: Tomcat Users List > Subject: Re: tomcat 5.5 multiple contexts using same realm bug? > > > In the web.xml, is the "realm-name" is different ? > BASIC | FORM Auth > > On 11/21/06, Elliott Murray <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I am trying to set up multiple contexts in Tomcat 5.5 but have a problem > > in logging in. I have them both up and running. They both use realms for > > login functionality. I wanted to originally use my own custom data source > > realm (limitations in the use of the Catalina one) This was working fine for > > App A but as soon as I put up App B using the same code but a different > > configuration (different tables, jdbc connections etc) I had some strange > > results. I would get the login page for App A turning up in App B and vice > > versa on what seemed random conditions. Login would only work on one App at > > a time in best case scenario. I then regressed back to using the > > DataSourceRealm but have the same results. If I use one of each it seems to > > work in that the correct login pages appear and I can log into one of the > > sites (though due to my sql requirements can only actually log into one app > > as the DataSourceRealm isn't quite flexible enough for either of my apps) > > > > Help! Is this a bug? I think my config is all correct - all in the correct > > context files/tags and as I say stand alone they work. If I hazarded a guess > > I reckon because the realm code is in server lib under tomcat only one > > instance of the realm is loaded in a parent classloader and sharing its > > state across multiple apps which is really bad and I'd even go so far to say > > this has serious potential security issues depending on your environment. It > > also negates a great potential feature of having realm embedded into > > context. I could go to using JAAS but would rather not as its a rewrite of > > something that's been working just fine for a while now. > > > > Some (edited) sample config below in case someone believes this is wrong. > > As I say I am pretty sure this is a bug but cannot believe I am the first > > person to want to do this? > > > > > > <Context > > docBase="C:/webapps/app1" > > reloadable="true" > > workDir="C:\Java\Tomcat5.5\work"> > > > > <Realm className="org.apache.catalina.realm.DataSourceRealm" debug="99" > > dataSourceName="jdbc/App1MySQLDB" > > userTable="member" userNameCol="email" userCredCol="password" > > userRoleTable="schemes" roleNameCol="name"/> > > > > <Resource > > auth="Container" > > name="jdbc/App1MySQLDB" > > type="javax.sql.DataSource" > > password="xxx" > > driverClassName="com.mysql.jdbc.Driver" > > maxIdle="5" > > maxWait="10000" > > removeAbandoned="true" > > logAbandoned="true" > > username="user" > > url="jdbc:mysql://a-url" > > removeAbandonedTimeout="60" > > factory="org.apache.commons.dbcp.BasicDataSourceFactory" > > maxActive="20"/> > > </Context> > > > > Repeat for App2 with its own data source (and db/config etc) > > > > Should this go to dev mailing list? Or logged as a bug? > > > > Thanks > > Elliott Murray > > > > > > Elliott Murray > > Technical Architect > > > > > > Green Cathedral <http://www.greencathedral.com/images/gc-logo.gif> Green > > Cathedral > > > > > > > > The Old Granary > > Westwick > > Cambridge > > CB4 5AR > > > > [EMAIL PROTECTED] <mailto: > > [EMAIL PROTECTED]> > > m. +44 (C)B243 AR > > > > t. +44 (0)1223 266700 > > f. +44 (0)1223 266701 > > www.greencathedral.com <http://www.greencathedral.com/> > > > > > > > > > > > > > -- > "Souviens-toi qu'au moment de ta naissance tout le monde était dans la joie > et toi dans les pleurs. > Vis de manière qu'au moment de ta mort, tout le monde soit dans les pleurs > et toi dans la joie." > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- "Souviens-toi qu'au moment de ta naissance tout le monde était dans la joie et toi dans les pleurs. Vis de manière qu'au moment de ta mort, tout le monde soit dans les pleurs et toi dans la joie." --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- "Souviens-toi qu'au moment de ta naissance tout le monde était dans la joie et toi dans les pleurs. Vis de manière qu'au moment de ta mort, tout le monde soit dans les pleurs et toi dans la joie." --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]