I am not sure myself where is the second thread coming from. I'll try to
figure that one out. But in priniciple, Greg is right, using ThreadLocal
for security association is improper in this environment. Again, as Greg
pointed out, we would have to authenticate every request. Here is a
snippet from my log:

2001-12-27 17:46:57,710 INFO [Default] RequestToEventTranslator:
url=/formbasedloginscreen 2001-12-27 17:47:01,796 INFO [Default] Did not
find the UCL resource sun/tools/javac/resources/javac_en.properties
2001-12-27 17:47:01,856 INFO [Default] Did not find the UCL resource
sun/tools/javac/resources/javac_en_US.properties 2001-12-27 17:47:03,078
INFO [org.jboss.jetty.Jetty] JSP: init 2001-12-27 17:47:03,769 INFO
[org.jboss.jetty.Jetty] JSP: init 2001-12-27 17:47:04,259 INFO
[org.jboss.jetty.Jetty] JSP: init 2001-12-27 17:47:05,031 INFO
[org.jboss.jetty.Jetty] JSP: init 2001-12-27 17:47:05,431 INFO
[org.jboss.jetty.Jetty] JSP: init 2001-12-27 17:47:08,295 INFO
[org.jboss.jetty.JBossUserRealm#default] JBossUserPrincipal: j2ee
2001-12-27 17:47:08,295 INFO [org.jboss.jetty.JBossUserRealm#default]
ensureUser:  
2001-12-27 17:47:08,295 INFO
[org.jboss.jetty.JBossUserRealm#default] Curr thread:
SocketListener-3|0|Socket[addr=127.0.0.1/127.0.0.1,port=3796,localport=8080]
2001-12-27 17:47:08,295 ERROR [Default] java.lang.Throwable 2001-12-27
17:47:08,295 ERROR [Default] at
org.jboss.jetty.JBossUserRealm.ensureUser(JBossUserRealm.java:198)
2001-12-27 17:47:08,295 ERROR [Default] at
org.jboss.jetty.JBossUserRealm.getUser(JBossUserRealm.java:214) 2001-12-27
17:47:08,295 ERROR [Default] at
org.mortbay.jetty.servlet.ServletHandler.formAuthenticated(ServletHandler.java:721)
2001-12-27 17:47:08,295 ERROR [Default] at
org.mortbay.http.handler.SecurityHandler.handle(SecurityHandler.java:311)
2001-12-27 17:47:08,315 ERROR [Default] at
org.mortbay.http.HttpContext.handle(HttpContext.java:1145) 2001-12-27
17:47:08,315 ERROR [Default] at
org.mortbay.http.HttpContext.handle(HttpContext.java:1099) 2001-12-27
17:47:08,315 ERROR [Default] at
org.mortbay.http.HttpServer.service(HttpServer.java:725) 2001-12-27
17:47:08,315 ERROR [Default] at
org.mortbay.http.HttpConnection.service(HttpConnection.java:745)
2001-12-27 17:47:08,315 ERROR [Default] at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:918)
2001-12-27 17:47:08,315 ERROR [Default] at
org.mortbay.http.HttpConnection.handle(HttpConnection.java:760) 2001-12-27
17:47:08,345 ERROR [Default] at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:138)
2001-12-27 17:47:08,345 ERROR [Default] at
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:287) 2001-12-27
17:47:08,345 ERROR [Default] at
org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:715) 2001-12-27
17:47:08,345 ERROR [Default] at java.lang.Thread.run(Unknown Source)
2001-12-27 17:47:08,365 INFO [org.jboss.jetty.JBossUserRealm#default]
created JBossUserRealm::JBossUserPrincipal: j2ee 2001-12-27 17:47:08,365
INFO [org.jboss.jetty.JBossUserRealm#default] authenticating: Name:j2ee
Password:j2ee 2001-12-27 17:47:08,506 INFO [Default] Did not find the UCL
resource com/sun/security/auth/Resources_en.properties 2001-12-27
17:47:08,566 INFO [Default] Did not find the UCL resource
com/sun/security/auth/Resources_en_US.properties 2001-12-27 17:47:08,746
INFO [Default] User 'j2ee' authenticated. 2001-12-27 17:47:08,746 INFO
[Default] **** UsersRolesModule roles found: customer,gold_customer
2001-12-27 17:47:08,756 INFO
[org.jboss.security.plugins.JaasSecurityManager.other]
JaasSecurityManager: authenticated, setting active subject: Subject:
        Principal: j2ee
        Principal: Roles 
 for thread
SocketListener-3|0|Socket[addr=127.0.0.1/127.0.0.1,port=3796,localport=8080]
2001-12-27 17:47:08,786 INFO [org.jboss.jetty.JBossUserRealm#default]
JBossUserPrincipal: j2ee is authenticated 2001-12-27 17:47:08,786 INFO
[org.jboss.jetty.JBossUserRealm#default] Current thread:
SocketListener-3|0|Socket[addr=127.0.0.1/127.0.0.1,port=3796,localport=8080]
2001-12-27 17:47:08,786 INFO [org.jboss.jetty.JBossUserRealm#default]
JBossUserPrincipal: getting curr subj: Subject:
        Principal: j2ee
        Principal: Roles
2001-12-27 17:47:08,796 INFO  [org.jboss.jetty.JBossUserRealm#default]
JBossUserPrincipal: j2ee
2001-12-27 17:47:08,796 INFO  [org.jboss.jetty.JBossUserRealm#default]
ensureUser: 
2001-12-27 17:47:08,796 INFO  [org.jboss.jetty.JBossUserRealm#default]
Curr
thread: SocketListener-1|0|Socket[addr=127.0.0.1/127.0.0.1,port=3791,localport=8080]
2001-12-27 17:47:08,796 ERROR [Default] java.lang.Throwable
2001-12-27 17:47:08,796 ERROR [Default]         at
org.jboss.jetty.JBossUserRealm.ensureUser(JBossUserRealm.java:198)
2001-12-27 17:47:08,796 ERROR [Default]         at
org.jboss.jetty.JBossUserRealm.getUser(JBossUserRealm.java:214)
2001-12-27 17:47:08,796 ERROR [Default]         at
org.mortbay.jetty.servlet.ServletHandler.formAuthenticated(ServletHandler.java:752)
2001-12-27 17:47:08,796 ERROR [Default]         at
org.mortbay.http.handler.SecurityHandler.authenticatedInRole(SecurityHandler.java:338)
2001-12-27 17:47:08,796 ERROR [Default]         at
org.mortbay.http.handler.SecurityHandler.handle(SecurityHandler.java:285)
2001-12-27 17:47:08,796 ERROR [Default]         at
org.mortbay.http.HttpContext.handle(HttpContext.java:1145)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.http.HttpContext.handle(HttpContext.java:1099)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.http.HttpServer.service(HttpServer.java:725)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.http.HttpConnection.service(HttpConnection.java:745)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:918)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.http.HttpConnection.handle(HttpConnection.java:760)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:138)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:287)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:715)
2001-12-27 17:47:08,846 ERROR [Default]         at
java.lang.Thread.run(Unknown Source)
2001-12-27 17:47:08,846 INFO  [org.jboss.jetty.JBossUserRealm#default]
isUserInRole: 
2001-12-27 17:47:08,846 ERROR [Default] java.lang.Throwable
2001-12-27 17:47:08,846 ERROR [Default]         at
org.jboss.jetty.JBossUserRealm$JBossUserPrincipal.isUserInRole(JBossUserRealm.java:120)
2001-12-27 17:47:08,846 ERROR [Default]         at
org.mortbay.http.handler.SecurityHandler.authenticatedInRole(SecurityHandler.java:360)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.handler.SecurityHandler.handle(SecurityHandler.java:285)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.HttpContext.handle(HttpContext.java:1145)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.HttpContext.handle(HttpContext.java:1099)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.HttpServer.service(HttpServer.java:725)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.HttpConnection.service(HttpConnection.java:745)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:918)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.HttpConnection.handle(HttpConnection.java:760)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:138)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:287)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:715)
2001-12-27 17:47:08,856 ERROR [Default]         at
java.lang.Thread.run(Unknown Source)
2001-12-27 17:47:08,856 INFO
[org.jboss.security.plugins.JaasSecurityManager.other]
JaasSecurityManager: checking roles for active subject: null for thread
SocketListener-1|0|Socket[addr=127.0.0.1/127.0.0.1,port=3791,localport=8080]
2001-12-27 17:47:08,856 INFO  [Default] JaasSecurityManager: checking
role null
2001-12-27 17:47:08,856 WARN  [org.jboss.jetty.JBossUserRealm#default]
JBossUserPrincipal: j2ee is NOT in Role: gold_customer
2001-12-27 17:47:08,856 INFO  [org.jboss.jetty.JBossUserRealm#default]
JBossUserPrincipal: getting curr subj: null
2001-12-27 17:47:08,856 INFO  [org.jboss.jetty.JBossUserRealm#default]
Current
thread: SocketListener-1|0|Socket[addr=127.0.0.1/127.0.0.1,port=3791,localport=8080]
2001-12-27 17:47:08,856 INFO  [org.jboss.jetty.JBossUserRealm#default]
isUserInRole: 
2001-12-27 17:47:08,856 ERROR [Default] java.lang.Throwable
2001-12-27 17:47:08,856 ERROR [Default]         at
org.jboss.jetty.JBossUserRealm$JBossUserPrincipal.isUserInRole(JBossUserRealm.java:120)
2001-12-27 17:47:08,856 ERROR [Default]         at
org.mortbay.http.handler.SecurityHandler.authenticatedInRole(SecurityHandler.java:360)
2001-12-27 17:47:08,986 ERROR [Default]         at
org.mortbay.http.handler.SecurityHandler.handle(SecurityHandler.java:285)
2001-12-27 17:47:08,986 ERROR [Default]         at
org.mortbay.http.HttpContext.handle(HttpContext.java:1145)
2001-12-27 17:47:08,986 ERROR [Default]         at
org.mortbay.http.HttpContext.handle(HttpContext.java:1099)
2001-12-27 17:47:08,986 ERROR [Default]         at
org.mortbay.http.HttpServer.service(HttpServer.java:725)
2001-12-27 17:47:08,986 ERROR [Default]         at
org.mortbay.http.HttpConnection.service(HttpConnection.java:745)
2001-12-27 17:47:08,986 ERROR [Default]         at
org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:918)
2001-12-27 17:47:08,996 ERROR [Default]         at
org.mortbay.http.HttpConnection.handle(HttpConnection.java:760)
2001-12-27 17:47:08,996 ERROR [Default]         at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:138)
2001-12-27 17:47:08,996 ERROR [Default]         at
org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:287)
2001-12-27 17:47:08,996 ERROR [Default]         at
org.mortbay.util.ThreadPool$JobRunner.run(ThreadPool.java:715)
2001-12-27 17:47:08,996 ERROR [Default]         at
java.lang.Thread.run(Unknown Source)
2001-12-27 17:47:08,996 INFO
[org.jboss.security.plugins.JaasSecurityManager.other]
JaasSecurityManager: checking roles for active subject: null for thread
SocketListener-1|0|Socket[addr=127.0.0.1/127.0.0.1,port=3791,localport=8080]
2001-12-27 17:47:08,996 INFO  [Default] JaasSecurityManager: checking
role null
2001-12-27 17:47:08,996 WARN  [org.jboss.jetty.JBossUserRealm#default]
JBossUserPrincipal: j2ee is NOT in Role: customer
2001-12-27 17:47:08,996 INFO  [org.jboss.jetty.JBossUserRealm#default]
JBossUserPrincipal: getting curr subj: null
2001-12-27 17:47:08,996 INFO  [org.jboss.jetty.JBossUserRealm#default]
Current
thread: SocketListener-1|0|Socket[addr=127.0.0.1/127.0.0.1,port=3791,localport=8080]
2001-12-27 17:47:08,996 WARN  [org.jboss.jetty.Jetty] WARNING: AUTH
FAILURE: role for j2ee

As you can see, SocketListener 3 did authentication, while SocketListener1
is doing role checking. Does it make sense to store the user credentials
is the JBossUserPrincipal and in isUserInRole() do authentication
again? This will set the thread association with proper security
context. I don't know, though, how to unset this once the thread is done
processing the request.

>
> Well firstly I'm going to say that we have been having problems
> > with jboss role based authentication for some time.     It is not
> > something that we want to get wrong, so I think the time has long
> > since passed where we need a good set of regression tests for
> > this.
> >
> > Now, while I can see that subsequent requests will be in different
> > threads - I cannot see where the second thread is coming from
> > within the same request????
> >
> > Nowhere in the Jetty handling or the JBoss adaptor is a new thread
> > created, let alone for a call to the authentication API?
> 
> Likewise, I do not create any extra threads in the integration code. Perhaps the
> Servlet itself is creating it ? Is it demonstrating programmatic security rather
> than declarative ? If so, then this is a problem, unless security info attached to
> primary request threads can be transparently inherited, in user code, by it's
> child threads....
> 
> 
> Jules
> 
> >
> >
> > As the JBoss JaasSecurityManager class appears to use ThreadLocals
> > to store authentication results then the solution may have to be to
> > authenticate every request rather than just relying on the contents
> > of a session to show that it has previously been authenticated.
> >
> > Note this probably means that we also have to deauthenticate threads when
> > they are returned to the thread pool.    I can't see how Jetty can help
> > much here, as ThreadLocals are beyond it's control and can't
> > be cleared by it.     I would say that adorning Threads with security
> > priviledges does not sound too robust in any environment that uses
> > thread pools (Ie almost any servlet container).
> >
> > I don't know enough about the jboss authentication mechanism to really
> > comment more - but I'll repeat that we should make security issues top
> > priority.
> >
> > regards
> >
> > Julian Gosnell wrote:
> >
> > > Anatoly,
> > >
> > > Thanks for the precise description of the problem. I shall take a look at
> > > this as soon as I find the time. Probably during the first week of Jan or so.
> > >
> > > Greg,
> > >
> > > Any thoughts about this before I plunge in ?
> > >
> > > Jules
> > >
> > >
> > > Anatoly Akkerman wrote:
> > >
> > >
> > >>Hi, guys
> > >>
> > >>I am running into problems with Jetty + JBoss 3.0alpha
> > >>
> > >>After some debugging here is what I have.
> > >>
> > >>Setup:
> > >>Jetty + JBoss 3.0
> > >>Sun's Petstore 1.1.1 deployed piecewise (meaning each EJB and WAR are
> > >>packaged separately and deployed in a J2eeScopedDeployer)
> > >>JBossSX configured to pick up usernames, password and roles from files
> > >>
> > >>Here is what happens:
> > >>
> > >>1) a servlet in Petstore takes username and password from a Web form and
> > >>sets "j_username" and "j_password" in the session. Jetty seems to pick
> > >>this stuff up and pass it to JBossUserRealm to authenticate the user.
> > >>JbossUserPrincipal gets created and then proceeds to authenticate with
> > >>with _securityMgr (which is JaasSecurityManager "java:/jaas/other").
> > >>Authentication succeeds, I see a log and I did doublecheck that
> > >>JaasSecurityManager sets activeSubject to this authenticated subject.
> > >>
> > >>2) Then, it seems, Jetty proceeds to check that this user has required
> > >>roles. It first calls JbossUserRealm.getUser(name) to obtain the
> > >>JBossUserPricipal and then calls isUserInRole(String role). This is where
> > >>the stuff fails miserably. The reason being that Jetty dispatched a
> > >>different thread to do role checking than the one that did
> > >>authentication. Because of this, JaasSecurityManager sees a null
> > >>activeSubject and says that the user does not have required roles.
> > >>
> > >>Now, this happens in a _single_ http request from a web client (just
> > >>clicked 'login' button on a form). I can try hacking a workaround just for
> > >>my demo to work but would like to help fixing this if it is a bug.
> > >>
> > >>-------------------------------------------------------------------------
> > >>Anatoly Akkerman
> > >>Computer Science Dept.
> > >>Courant Institute of Mathematical Sciences, NYU
> > >>715 Broadway, #719                      Tel: 212 998-3493
> > >>New York, NY 10003                      Fax: 212 995-4123
> > >>-------------------------------------------------------------------------
> > >>
> > >>_______________________________________________
> > >>Jboss-development mailing list
> > >>[EMAIL PROTECTED]
> > >>https://lists.sourceforge.net/lists/listinfo/jboss-development
> > >>
> > >
> > >
> > > _________________________________________________________
> > > Do You Yahoo!?
> > > Get your free @yahoo.com address at http://mail.yahoo.com
> > >
> > >
> > >
> > > For the latest information about Jetty, please see http://jetty.mortbay.
> > >
> > > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
> > >
> > >
> >
> > --
> > Greg Wilkins<[EMAIL PROTECTED]>          GB  Phone: +44-(0)7092063462
> > Mort Bay Consulting Australia and UK.    Mbl Phone: +61-(0)4 17786631
> > http://www.mortbay.com                   AU  Phone: +61-(0)2 98107029
> >
> > ------------------------ Yahoo! Groups Sponsor ---------------------~-->
> > FREE COLLEGE MONEY
> > CLICK HERE to search
> > 600,000 scholarships!
> > http://us.click.yahoo.com/G_L2TD/4m7CAA/ySSFAA/CefplB/TM
> > ---------------------------------------------------------------------~->
> >
> > For the latest information about Jetty, please see http://jetty.mortbay.
> >
> > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
> 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> _______________________________________________
> Jboss-development mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-development
> 


_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to