@SuppressWarnings("unchecked") @Test public void testStartActivator() throws Exception { Properties oldProps = new Properties(); oldProps.putAll(System.getProperties()); try { System.setProperty(GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP, "(foo=bar)"); Bundle b = EasyMock.createMock(Bundle.class); EasyMock.expect(b.getBundleId()).andReturn(768L).anyTimes(); EasyMock.replay(b); BundleContext bc = EasyMock.createNiceMock(BundleContext.class); EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); EasyMock.expect(bc.createFilter(EasyMock.anyObject(String.class))).andAnswer( () -> FrameworkUtil.createFilter((String) EasyMock.getCurrentArguments()[0])).anyTimes(); EasyMock.expect(bc.registerService( EasyMock.eq(EventListenerHook.class), EasyMock.isA(EventListenerHook.class), EasyMock.isNull(Dictionary.class))) .andReturn(null); EasyMock.expect(bc.registerService( EasyMock.eq(FindHook.class), EasyMock.isA(FindHook.class), EasyMock.isNull(Dictionary.class))) .andReturn(null); EasyMock.replay(bc); Activator a = new Activator(); a.start(bc); assertNotNull(a.guardProxyCatalog); assertNotNull(a.guardingEventHook); assertNotNull(a.guardingFindHook); EasyMock.verify(bc); } finally { System.setProperties(oldProps); } }
@Override public void start(BundleContext bundleContext) throws Exception { String f = System.getProperty(GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); Filter securedServicesFilter; if (f == null) { logger.info("No role-based security for services as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); return; } else { securedServicesFilter = bundleContext.createFilter(f); logger.info("Adding role-based security to services with filter: {}", f); } guardProxyCatalog = new GuardProxyCatalog(bundleContext); guardingEventHook = new GuardingEventHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(EventListenerHook.class, guardingEventHook, null); guardingFindHook = new GuardingFindHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(FindHook.class, guardingFindHook, null); }
Activator implements BundleActivator { @Override public void start(BundleContext bundleContext) throws Exception { String f = System.getProperty(GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); Filter securedServicesFilter; if (f == null) { logger.info("No role-based security for services as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); return; } else { securedServicesFilter = bundleContext.createFilter(f); logger.info("Adding role-based security to services with filter: {}", f); } guardProxyCatalog = new GuardProxyCatalog(bundleContext); guardingEventHook = new GuardingEventHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(EventListenerHook.class, guardingEventHook, null); guardingFindHook = new GuardingFindHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(FindHook.class, guardingFindHook, null); } }
Activator implements BundleActivator { @Override public void start(BundleContext bundleContext) throws Exception { String f = System.getProperty(GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); Filter securedServicesFilter; if (f == null) { logger.info("No role-based security for services as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); return; } else { securedServicesFilter = bundleContext.createFilter(f); logger.info("Adding role-based security to services with filter: {}", f); } guardProxyCatalog = new GuardProxyCatalog(bundleContext); guardingEventHook = new GuardingEventHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(EventListenerHook.class, guardingEventHook, null); guardingFindHook = new GuardingFindHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(FindHook.class, guardingFindHook, null); }  }
Activator implements BundleActivator { @Override public void start(BundleContext bundleContext) throws Exception { String f = System.getProperty(GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); Filter securedServicesFilter; if (f == null) { logger.info("No role-based security for services as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); return; } else { securedServicesFilter = bundleContext.createFilter(f); logger.info("Adding role-based security to services with filter: {}", f); } guardProxyCatalog = new GuardProxyCatalog(bundleContext); guardingEventHook = new GuardingEventHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(EventListenerHook.class, guardingEventHook, null); guardingFindHook = new GuardingFindHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(FindHook.class, guardingFindHook, null); }  @Override void start(BundleContext bundleContext); @Override void stop(BundleContext bundleContext); }
Activator implements BundleActivator { @Override public void start(BundleContext bundleContext) throws Exception { String f = System.getProperty(GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); Filter securedServicesFilter; if (f == null) { logger.info("No role-based security for services as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_SERVICES_SYSPROP); return; } else { securedServicesFilter = bundleContext.createFilter(f); logger.info("Adding role-based security to services with filter: {}", f); } guardProxyCatalog = new GuardProxyCatalog(bundleContext); guardingEventHook = new GuardingEventHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(EventListenerHook.class, guardingEventHook, null); guardingFindHook = new GuardingFindHook(bundleContext, guardProxyCatalog, securedServicesFilter); bundleContext.registerService(FindHook.class, guardingFindHook, null); }  @Override void start(BundleContext bundleContext); @Override void stop(BundleContext bundleContext);  }