Hi aries team,

sry for my last misformated mail! ( was my first, now a second try, hopefully it is wellformed now )

currently im evaluating the possibilites when using the ConditionalPermissionAdmin provided by felix 3.2.0. See attached file for the Consumer code. The consuming bundle does explicitly not have the permission to get any service. I want to observe how three different ways to get a ServiceReference behave if it is not permitted to get a service. The three ways are blueprint, directly the BundleContext and a ServiceTracker/Customizer. I read in the OSGi specification that the ServiceReference should not be visible to a not permitted bundle. The first confusing thing ist that (aries 0.3) blueprint does call the consumers bind/unbind-method with the service reference if the bundle has the permission or not… (i guess its a bug) But lets also continue with the two other ways (i know usually i would put them into the felix mailing, but i was not able to subscripe) : Every time a ServiceReference is injected from blueprint i check the self opened ServiceTracker and the BundleContext for current ServiceReferences and they work fine:

2011-05-11 16:04:50,817 INFO c.b.m.s.c.c.SimpleServiceConsumer[]: injected with blueprint : [....cpa.api.ISimple] | 2011-05-11 16:04:50,817 INFO c.b.m.s.c.c.SimpleServiceConsumer[]: received from bundlecontext : | null 2011-05-11 16:04:50,817 INFO c.b.m.s.c.c.SimpleServiceConsumer[]: received from tracker : null | org.osgi.util.tracker.ServiceTracker@19f90e3

Null means no service reference was found…

If i now add dynamically a ServicePermission for getting services to the consumer bundle i assume that my ServiceTrackerCustomizer is called, since a new service is now available for the consumer bundle, unfortunatly this is not done… to get the new service i either have to reopen the tracker or refresh the bundle… but this is not the wanted flexible behaviour.
AFTER refreshing the consumer bundle the trackercustomizer is notified.
2011-05-11 14:30:00,792 INFO c.b.m.s.c.c.SimpleServiceConsumer[]: SimpleCustomizer added from tracker : [....cpa.api.ISimple]
| org.osgi.util.tracker.ServiceTracker@1d36f77
2011-05-11 14:30:00,792 INFO c.b.m.s.c.c.SimpleServiceConsumer[]: SimpleCustomizer added from tracker : [....cpa.api.ISimple]
| org.osgi.util.tracker.ServiceTracker@1d36f77
2011-05-11 14:30:00,792 INFO c.b.m.s.c.c.SimpleServiceConsumer[]: injected with blueprint : [....cpa.api.ISimple] | 2011-05-11 14:30:00,792 INFO c.b.m.s.c.c.SimpleServiceConsumer[]: received from bundlecontext : | [....cpa.api.ISimple] 2011-05-11 14:30:00,807 INFO c.b.m.s.c.c.SimpleServiceConsumer[]: received from tracker : [...cpa.api.ISimple] | org.osgi.util.tracker.ServiceTracker@1d36f77

Ok now my questions:
1)Im right that that blueprint should not call my unpermitted consumerbundles bind and unbind methods with ServiceReference instances? 2)A Permission state change should trigger the ServiceTrackerCustomizer methods and blueprint initiated bind and unbind method calls?
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ....scenario.cpa.api.ISimple;

/**
 * <code>SimpleServiceConsumer</code>TODO , please write javadoc for class
 * 'SimpleServiceConsumer'!
 * 
 * @author Marcel Hanser 
 */
public class SimpleServiceConsumer
{

   private static final Logger LOGGER = LoggerFactory.getLogger( 
SimpleServiceConsumer.class );

   BundleContext               context;
   Object                      service;
   ServiceTracker              tracker;

   public SimpleServiceConsumer()
   {

   }

   public void bindRef( final ServiceReference ref )
   {
      LOGGER.info( "injected with blueprint : " + ref + " | " );

      final ServiceReference ref2 = context.getServiceReference( 
ISimple.class.getName() );
      LOGGER.info( "received from bundlecontext : " + " | " + ref2 );

      final ServiceReference ref3 = tracker.getServiceReference();
      LOGGER.info( "received from tracker : " + ref3 + " | " + tracker );
   }

   public void unbindRef( final ServiceReference ref )
   {

      LOGGER.info( "unbind injected with blueprint : " + ref + " | " );

      final ServiceReference ref2 = context.getServiceReference( 
ISimple.class.getName() );
      LOGGER.info( "unbind received from bundlecontext : " + " | " + ref2 );

      final ServiceReference ref3 = tracker.getServiceReference();
      LOGGER.info( "unbind received from tracker : " + ref3 + " | " + tracker );
   }

   public BundleContext getContext()
   {
      return context;
   }

   public void setContext( final BundleContext context )
   {

      this.context = context;
      tracker = new ServiceTracker( context, ISimple.class.getName(), new 
SimpleCustomizer() );
      tracker.open();

   }

   private class SimpleCustomizer implements ServiceTrackerCustomizer
   {

      public Object addingService( final ServiceReference reference )
      {
         LOGGER.info( "SimpleCustomizer added from tracker : " + reference + " 
| " + tracker );
         return context.getService( reference );

      }

      public void modifiedService( final ServiceReference reference, final 
Object service )
      {
         LOGGER.info( "SimpleCustomizer modified from tracker : " + reference + 
" | " + tracker );

      }

      public void removedService( final ServiceReference reference, final 
Object service )
      {
         LOGGER.info( "SimpleCustomizer removed from tracker : " + reference + 
" | " + tracker );

      }
   }
}

Reply via email to