<div dir="ltr">Hi,<br><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 28, 2014 at 1:37 AM, Stuart Douglas <span dir="ltr">&lt;<a href="mailto:sdouglas@redhat.com" target="_blank">sdouglas@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I think I have fixes for both these issues.<br>
<br>
<a href="https://github.com/wildfly/wildfly/pull/6539/files" target="_blank">https://github.com/wildfly/<u></u>wildfly/pull/6539/files</a><br>
<br>
Should fix the NPE (I was not sure what security domain config your example needed in order to reproduce).<br></blockquote><div><br></div><div>Okay great, I&#39;ll give it a shot. The security domain configured in standalone.xml is a dummy one that&#39;s unfortunately needed to trick Undertow into activating JASPIC (it shouldn&#39;t be needed, but for now it is). It&#39;s the following one that&#39;s used I think in pretty much all WildFly JASPIC examples:<br>
<br>&lt;security-domain name=&quot;jaspitest&quot; cache-type=&quot;default&quot;&gt;<br>    &lt;authentication-jaspi&gt;<br>        &lt;login-module-stack name=&quot;dummy&quot;&gt;<br>            &lt;login-module code=&quot;Dummy&quot; flag=&quot;optional&quot;/&gt;<br>
        &lt;/login-module-stack&gt;<br>        &lt;auth-module code=&quot;Dummy&quot;/&gt;<br>    &lt;/authentication-jaspi&gt;<br>&lt;/security-domain&gt;<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

The timeout issues should be fixed in Undertow upstream, it looks like there was two issues:<br>
- The timeout was running in an IO thread<br>
- ThreadLocals where not being properly set up before dispatching to the error page<br></blockquote><div><br></div><div>This sounds like it could well be the issue I was seeing. Timeout was indeed running in an IO thread and it for some reason didn&#39;t see that the response was committed and/or dispatched, even when asyncContext.complete() had been called.<br>
<br></div><div>Regards,<br>Arjan<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Stuart<br>
<br>
arjan tijms wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5">
Hi,<br>
<br>
When using a basic async servlet, where the request processing is<br>
transferred to an @Asynchronous method, there&#39;s a NPE at the end of the<br>
request:<br>
<br>
Exception in thread &quot;default task-107&quot; java.lang.NullPointerException<br>
     at<br>
org.wildfly.extension.<u></u>undertow.security.jaspi.<u></u>JASPIAuthenticationMechanism.<u></u>wasAuthExceptionThrown(<u></u>JASPIAuthenticationMechanism.<u></u>java:164)<br>
     at<br>
org.wildfly.extension.<u></u>undertow.security.jaspi.<u></u>JASPIAuthenticationMechanism.<u></u>access$100(<u></u>JASPIAuthenticationMechanism.<u></u>java:72)<br>
     at<br>
org.wildfly.extension.<u></u>undertow.security.jaspi.<u></u>JASPIAuthenticationMechanism$<u></u>1.wrap(<u></u>JASPIAuthenticationMechanism.<u></u>java:240)<br>
     at<br>
org.wildfly.extension.<u></u>undertow.security.jaspi.<u></u>JASPIAuthenticationMechanism$<u></u>1.wrap(<u></u>JASPIAuthenticationMechanism.<u></u>java:234)<br>
     at<br>
io.undertow.server.<u></u>HttpServerExchange$<u></u>WrapperStreamSinkConduitFactor<u></u>y.create(HttpServerExchange.<u></u>java:2017)<br>
     at<br>
io.undertow.server.<u></u>HttpServerExchange.<u></u>getResponseChannel(<u></u>HttpServerExchange.java:1167)<br>
     at<br>
io.undertow.servlet.spec.<u></u>ServletOutputStreamImpl.close(<u></u>ServletOutputStreamImpl.java:<u></u>619)<br>
     at<br>
io.undertow.servlet.spec.<u></u>HttpServletResponseImpl.<u></u>closeStreamAndWriter(<u></u>HttpServletResponseImpl.java:<u></u>451)<br>
     at<br>
io.undertow.servlet.spec.<u></u>HttpServletResponseImpl.<u></u>responseDone(<u></u>HttpServletResponseImpl.java:<u></u>525)<br>
     at<br>
io.undertow.servlet.spec.<u></u>AsyncContextImpl$3.run(<u></u>AsyncContextImpl.java:294)<br>
     at<br>
io.undertow.servlet.spec.<u></u>AsyncContextImpl$6.run(<u></u>AsyncContextImpl.java:432)<br>
<br>
The direct cause is that<br>
JASPIAuthenticationMechanism#<u></u>wasAuthExceptionThrown tries to access the<br>
security context as-in the following line:<br>
<br>
SecurityContextAssociation.<u></u>getSecurityContext().getData()<u></u>.get(AuthException.class.<u></u>getName())<br>
!= null<br>
<br>
Only, for an async request processing thread<br>
SecurityContextAssociation.<u></u>getSecurityContext() is always null, causing<br>
the NPE. I created a test that functions as a reproducer here:<br>
<a href="https://github.com/arjantijms/javaee7-samples/tree/master/jaspic/async-authentication" target="_blank">https://github.com/arjantijms/<u></u>javaee7-samples/tree/master/<u></u>jaspic/async-authentication</a><br>
It also looks like there&#39;s something not entirely right with the async<br>
time out on Undertow, but I haven&#39;t nailed that one down yet.<br>
<br>
Kind regards,<br>
Arjan<br>
<br>
<br></div></div>
______________________________<u></u>_________________<br>
undertow-dev mailing list<br>
<a href="mailto:undertow-dev@lists.jboss.org" target="_blank">undertow-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/<u></u>mailman/listinfo/undertow-dev</a><br>
</blockquote>
</blockquote></div><br></div></div></div>