title: Apache Shiro integration and Netty ExecutionHandler/OrderedMemoryAwareThreadPoolExecutor
body: <p>I just added an <code>ExecutionHandler</code> to my server pipeline just before my main business logic handler as recommended in the documentation.</p>
  
  <p>I am using Apache Shiro <a href="http://shiro.apache.org/" rel="noreferrer">http://shiro.apache.org/</a> for security. It worked fine until I added the <code>ExecutionHandler</code>. </p>
  
  <p><em>The issue</em>: <br/>
  Shiro's execution context is bound to the current thread in which you obtain the <code>Subject</code> object. So, if the <code>Subject</code> is obtained in the worker thread, but the business logic executes in a separate <code>ExecutionHandler</code> managed thread then the two execution contexts won't be connected as far as Shiro is concerned. Thus Shiro in the <code>ExecutionHandler</code> thread will fail to be aware that the <code>Subject</code> is in fact authenticated. So I'm getting Authentication errors.</p>
  
  <p>It is possible to associate a given <code>Subject</code> with a <code>Runnable</code> before passing it to <code>Executor.execute()</code> so that the security context is maintained. See: <a href="http://shiro.apache.org/subject.html" rel="noreferrer">http://shiro.apache.org/subject.html</a></p>
  
  <p>Based on this I think need to find a way to associate the current Shiro <code>Subject</code> with the <code>ExecutionHandler</code> <code>Runnable</code>. </p>
  
  <p>I'm still trying to fully understand the <code>ExecutionHandler</code> and <code>OrderedMemoryAwareThreadPoolExecutor</code> implementations. </p>
  
  <p>Basically I need to call <code>subject.associateWith(aRunnable)</code> just before <code>aRunnable</code> is passed to <code>Executor.execute(aRunnable)</code>.</p>
  
  <p>Does anyone have thoughts on where/how I could hook Shiro into the mix?</p>
  
  <p>Thanks,
  Matt</p>