Has anyone else been using apache shiro with the pax web whiteboard
extender?  Has anyone else succeeded in making it work?

Shiro uses a filter to handle authentication and authorization for a
paths of a webapp.

I'm trying to create a ShiroFilter DS component to front a servlet
(also a DS component) when using the Pax Web Whiteboard Exctender.

It seemed to work at first, ie. I got a login windown in my application
and was able to log in (which means that shiro is working as it is
supposed to), but when I changed the name of the filter DS component it
started failing.

I don't know *why* it fails when the name is changed, but I know *how*
it fails: it fails with the error message:
  No WebEnvironment found: no EnvironmentLoaderListener registered?

This is a well known and dreaded error message when using apache shiro,
see eg.
 
https://stackoverflow.com/questions/15645799/jetty-maven-plugin-unable-to-hot-redeploy-shiro-filter
 
https://stackoverflow.com/questions/15645799/jetty-maven-plugin-unable-to-hot-redeploy-shiro-filter

I have encountered this issue earlier, when I first tried to use the pax
web whiteboard extender, using my home brewed "mini dependency
injection" BundleActivator.  The way I solved it make the ShiroFilter
listen for a service of type WebContainer, and create an
EnvironmentLoaderListener when a WebContainer is enabled, like this:

 @Component(
     property= {
         HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN+"=/ukelonn/*",
         "servletNames=ukelonn"},
     service=Filter.class,
     immediate=true
 )
 public class UkelonnShiroFilter extends ShiroFilter {
     private WebContainer webContainer;
     private HttpContext httpcontext;
     private EnvironmentLoaderListener listener;

     @Reference
     public void setWebContainer(WebContainer webContainer) {
         createEnvironmentLoaderListenerAndDefaultContext(webContainer);
     }

     private void createEnvironmentLoaderListenerAndDefaultContext(WebContainer 
webContainer) {
         if (this.webContainer == webContainer) {
             return; // already registered, nothing to do
         }

         unregisterExistingEnvironmentLoaderListener();

         this.webContainer = webContainer;

         if (webContainer != null) {
             httpcontext = webContainer.createDefaultHttpContext();
             listener = new EnvironmentLoaderListener();
             webContainer.registerEventListener(listener, httpcontext);
         }
     }

     private void unregisterExistingEnvironmentLoaderListener() {
         if (webContainer != null) {
             webContainer.unregisterEventListener(listener);
             listener = null;
         }
     }

 }

This worked at first, but stopped working when I changed the name of the
class.  I can see in the debugger that the UkelonnShiroFilter gets a
WebContainer injection and creates and registers an
EnvironmentLoaderListener.

But even so the ShiroFilter fails during initialization with the
following error message:
 java.lang.IllegalStateException: No WebEnvironment found: no 
EnvironmentLoaderListener registered?

Does anyone know what I can/should do to initialize the WebEnvironment
properly for the shiro filter?

Thanks!


- Steinar

-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to