@SuppressWarnings("unchecked") @Test public void testFindHookProxyServices() throws Exception { Dictionary<String, Object> config = new Hashtable<>(); config.put("service.guard", "(service.id=*)"); BundleContext hookBC = mockConfigAdminBundleContext(config); GuardProxyCatalog gpc = new GuardProxyCatalog(hookBC); Filter serviceFilter = FrameworkUtil.createFilter("(service.id=*)"); GuardingFindHook gfh = new GuardingFindHook(hookBC, gpc, serviceFilter); BundleContext clientBC = mockBundleContext(31L); Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_ID, 16L); props.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); ServiceReference<?> sref = mockServiceReference(props); Collection<ServiceReference<?>> refs = new ArrayList<>(); refs.add(sref); gfh.find(clientBC, null, null, false, refs); assertEquals("No proxy should have been created for the proxy find", 0, gpc.proxyMap.size()); assertEquals("As the proxy is for this bundle is should be visible and remain on the list", Collections.singletonList(sref), refs); }
public void find(BundleContext bundleContext, String name, String filter, boolean allServices, Collection<ServiceReference<?>> references) { if (servicesFilter == null) { return; } if (this.bundleContext.equals(bundleContext) || bundleContext.getBundle().getBundleId() == 0) { return; } for (Iterator<ServiceReference<?>> i = references.iterator(); i.hasNext(); ) { ServiceReference<?> sr = i.next(); if (!servicesFilter.match(sr)) { continue; } if (guardProxyCatalog.handleProxificationForHook(sr)) { i.remove(); } } }
GuardingFindHook implements FindHook { public void find(BundleContext bundleContext, String name, String filter, boolean allServices, Collection<ServiceReference<?>> references) { if (servicesFilter == null) { return; } if (this.bundleContext.equals(bundleContext) || bundleContext.getBundle().getBundleId() == 0) { return; } for (Iterator<ServiceReference<?>> i = references.iterator(); i.hasNext(); ) { ServiceReference<?> sr = i.next(); if (!servicesFilter.match(sr)) { continue; } if (guardProxyCatalog.handleProxificationForHook(sr)) { i.remove(); } } } }
GuardingFindHook implements FindHook { public void find(BundleContext bundleContext, String name, String filter, boolean allServices, Collection<ServiceReference<?>> references) { if (servicesFilter == null) { return; } if (this.bundleContext.equals(bundleContext) || bundleContext.getBundle().getBundleId() == 0) { return; } for (Iterator<ServiceReference<?>> i = references.iterator(); i.hasNext(); ) { ServiceReference<?> sr = i.next(); if (!servicesFilter.match(sr)) { continue; } if (guardProxyCatalog.handleProxificationForHook(sr)) { i.remove(); } } } GuardingFindHook(BundleContext bundleContext, GuardProxyCatalog guardProxyCatalog, Filter securedServicesFilter); }
GuardingFindHook implements FindHook { public void find(BundleContext bundleContext, String name, String filter, boolean allServices, Collection<ServiceReference<?>> references) { if (servicesFilter == null) { return; } if (this.bundleContext.equals(bundleContext) || bundleContext.getBundle().getBundleId() == 0) { return; } for (Iterator<ServiceReference<?>> i = references.iterator(); i.hasNext(); ) { ServiceReference<?> sr = i.next(); if (!servicesFilter.match(sr)) { continue; } if (guardProxyCatalog.handleProxificationForHook(sr)) { i.remove(); } } } GuardingFindHook(BundleContext bundleContext, GuardProxyCatalog guardProxyCatalog, Filter securedServicesFilter); void find(BundleContext bundleContext, String name, String filter, boolean allServices, Collection<ServiceReference<?>> references); }
GuardingFindHook implements FindHook { public void find(BundleContext bundleContext, String name, String filter, boolean allServices, Collection<ServiceReference<?>> references) { if (servicesFilter == null) { return; } if (this.bundleContext.equals(bundleContext) || bundleContext.getBundle().getBundleId() == 0) { return; } for (Iterator<ServiceReference<?>> i = references.iterator(); i.hasNext(); ) { ServiceReference<?> sr = i.next(); if (!servicesFilter.match(sr)) { continue; } if (guardProxyCatalog.handleProxificationForHook(sr)) { i.remove(); } } } GuardingFindHook(BundleContext bundleContext, GuardProxyCatalog guardProxyCatalog, Filter securedServicesFilter); void find(BundleContext bundleContext, String name, String filter, boolean allServices, Collection<ServiceReference<?>> references);  }