Hi Rory,

Rory Douglas schrieb:
I want to write a facade AccessManager implementation that will delegate to a bundle-provided service. The idea would be to register one or more bundles providing AccessManager implementations and be able to configure the paths and/or nodetypes that they control, though initially it will probably just delegate to one service (if available), and fallback to SimpleAccessManager logic if no AccessManager service is available.

Since the AccessManager implementation is instantiated by Jackrabbit directly (has no Bundle- or ComponentContext), how can I get a handle to the Felix framework to lookup/listen for services? Would this even be advisable?

Depends on who you ask ;-) I think this is a valuable extension of Jackrabbit. Unfortunately, as you correctly note, Jackrabbit is currently configured in an non-dependency-injection way.

Of course, I assume you know of the risk of allowing any provider to plug in an AccessManager ;-)

As a solution I suggest you do the following:

  * Create a new bundle and export the AccessManagerFacade class
        and the extension interface.
  * Configure your AccessManagerFacade into Jackrabbit. The
        jackrabbit-server bundle will find the AccessManagerFacade
        class with a dynamic import.
  * Create a BundleActivator in your AccessManagerFacade bundle
        along these lines (make sure to _not_export this class) :
            public class Activator implements BundleActivator {
                private static BundleContext context;
                public static BundleContext getBundleContext() {
                    return context;
                }
                public void start(BundleContext context) {
                    this.context = context;
                }
                public void stop(BundleContext context) {
                    this.context = null;
                }
   * To find and use the real access managers the AccessManagerFacade
         would then access the Activator.getBundleContext() method

This works thanks to OSGi's class loader isolation. The drawback is, that the repository of course only works correctly if your AccessManager bundle is started.

Hope this helps.

Regards
Felix


Regards,
Rory

Reply via email to