On Fri, Jan 13, 2012 at 9:10 AM, Jamesb <[email protected]> wrote:
> I think I've gotten to the bottom of this. I have a sample test project
> available here:
> https://github.com/jbowkett/Apache-Shiro-probs
> https://github.com/jbowkett/Apache-Shiro-probs
> The crux of the problem is that I was using Stripes for my page layout etc.
> within one of those layouts, was the shiro:hasRole (to present a link to our
> admin area). One of my pages was a generic 404 error page, which also used
> the same page layout. I configured this error page with the following in my
> web.xml:
> <error-page>
> <error-code>404</error-code>
> <location>/WEB-INF/jsp/core/not_found.jsp</location>
> </error-page>
> It would appear when running with Tomcat 6, this error page was re-compiled
> on each separate page impression, however, I guess it had not gone through
> the Shiro filter so it did not have the SecurityManager instance in its
> ThreadLocal, hence the exception trace.
> This was wrapped in several re-used layout jsps, so it was a bit of a rats'
> nest to untangle (not least because it looked like the layout jsp for the
> requested page was causing the exception trace, not a parallel compile of
> the 404 page), but hopefully the code example I've put in github should show
> the problem in its most obvious form. (You can turn the error on or off, by
> commenting out the error page snippet above in the web.xml)
> Interestingly, this is not a problem when running my webapp under jetty :
> Perhaps Tomcat pre-compiles the 404 page (but on every page impression?) and
> jetty does not?
No, nothing to do with pre-compilation. It's just that you haven't
configured the Shiro filter to run on invocation of the ERROR
dispatcher. By default, Tomcat invokes the filter chain only on
REQUEST dispatcher. It's a standard servlet thing, but I'm not sure if
Jetty implements dispatchers at all or they just have a different
default. In your web.xml, configure:
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
or just some as needed.
Kalle