@SuppressWarnings("unchecked") @Test public void testHandleProxificationForHook() throws Exception { Dictionary<String, Object> config = new Hashtable<>(); config.put(Constants.SERVICE_PID, GuardProxyCatalog.SERVICE_ACL_PREFIX + "foo"); config.put(GuardProxyCatalog.SERVICE_GUARD_KEY, "(a>=5)"); BundleContext bc = mockConfigAdminBundleContext(config); GuardProxyCatalog gpc = new GuardProxyCatalog(bc); Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_ID, 13L); props.put("a", "6"); props.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); ServiceReference<?> sref2 = mockServiceReference(props); assertFalse("Should not hide an existing proxy for this client", gpc.handleProxificationForHook(sref2)); assertEquals("No proxy should have been created", 0, gpc.proxyMap.size()); Dictionary<String, Object> props4 = new Hashtable<>(); props4.put(Constants.SERVICE_ID, 15L); props4.put("a", "7"); ServiceReference<?> sref4 = mockServiceReference(props4); assertTrue("Should hide a service that needs to be proxied", gpc.handleProxificationForHook(sref4)); assertEquals("Should trigger proxy creation", 1, gpc.proxyMap.size()); }
boolean handleProxificationForHook(ServiceReference<?> sr) { if (isProxy(sr)) { return false; } proxyIfNotAlreadyProxied(sr); return true; }
GuardProxyCatalog implements ServiceListener { boolean handleProxificationForHook(ServiceReference<?> sr) { if (isProxy(sr)) { return false; } proxyIfNotAlreadyProxied(sr); return true; } }
GuardProxyCatalog implements ServiceListener { boolean handleProxificationForHook(ServiceReference<?> sr) { if (isProxy(sr)) { return false; } proxyIfNotAlreadyProxied(sr); return true; } GuardProxyCatalog(BundleContext bc); }
GuardProxyCatalog implements ServiceListener { boolean handleProxificationForHook(ServiceReference<?> sr) { if (isProxy(sr)) { return false; } proxyIfNotAlreadyProxied(sr); return true; } GuardProxyCatalog(BundleContext bc); @Override void serviceChanged(ServiceEvent event); }
GuardProxyCatalog implements ServiceListener { boolean handleProxificationForHook(ServiceReference<?> sr) { if (isProxy(sr)) { return false; } proxyIfNotAlreadyProxied(sr); return true; } GuardProxyCatalog(BundleContext bc); @Override void serviceChanged(ServiceEvent event); static final String KARAF_SECURED_SERVICES_SYSPROP; static final String SERVICE_GUARD_ROLES_PROPERTY; static final String KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY; }