@Test public void testGuardProxyCatalog() throws Exception { Bundle b = EasyMock.createMock(Bundle.class); EasyMock.expect(b.getBundleId()).andReturn(9823L).anyTimes(); EasyMock.replay(b); BundleContext bc = EasyMock.createNiceMock(BundleContext.class); EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes(); bc.addServiceListener(EasyMock.isA(ServiceListener.class)); EasyMock.expectLastCall().once(); String caFilter = "(&(objectClass=org.osgi.service.cm.ConfigurationAdmin)" + "(!(" + GuardProxyCatalog.PROXY_SERVICE_KEY + "=*)))"; EasyMock.expect(bc.createFilter(caFilter)).andReturn(FrameworkUtil.createFilter(caFilter)).anyTimes(); String pmFilter = "(&(objectClass=org.apache.aries.proxy.ProxyManager)" + "(!(" + GuardProxyCatalog.PROXY_SERVICE_KEY + "=*)))"; EasyMock.expect(bc.createFilter(pmFilter)).andReturn(FrameworkUtil.createFilter(pmFilter)).anyTimes(); EasyMock.replay(bc); GuardProxyCatalog gpc = new GuardProxyCatalog(bc); assertTrue("Service Tracker for ConfigAdmin should be opened", gpc.configAdminTracker.getTrackingCount() != -1); assertTrue("Service Tracker for ProxyManager should be opened", gpc.proxyManagerTracker.getTrackingCount() != -1); EasyMock.verify(bc); EasyMock.reset(bc); bc.removeServiceListener(EasyMock.isA(ServiceListener.class)); EasyMock.expectLastCall().once(); EasyMock.replay(bc); gpc.close(); assertEquals("Service Tracker for ConfigAdmin should be closed", -1, gpc.configAdminTracker.getTrackingCount()); assertEquals("Service Tracker for ProxyManager should be closed", -1, gpc.proxyManagerTracker.getTrackingCount()); EasyMock.verify(bc); }
GuardProxyCatalog(BundleContext bc) throws Exception { LOG.trace("Starting GuardProxyCatalog"); myBundleContext = bc; compulsoryRoles = System.getProperty(GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); if (compulsoryRoles == null) { LOG.info("No compulsory roles for a karaf command without the ACL as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); } bc.addServiceListener(this); Filter caFilter = getNonProxyFilter(bc, ConfigurationAdmin.class); LOG.trace("Creating Config Admin Tracker using filter {}", caFilter); configAdminTracker = new ServiceTracker<>(bc, caFilter, null); configAdminTracker.open(); Filter pmFilter = getNonProxyFilter(bc, ProxyManager.class); LOG.trace("Creating Proxy Manager Tracker using filter {}", pmFilter); proxyManagerTracker = new ServiceTracker<>(bc, pmFilter, new ServiceProxyCreatorCustomizer()); proxyManagerTracker.open(); }
GuardProxyCatalog implements ServiceListener { GuardProxyCatalog(BundleContext bc) throws Exception { LOG.trace("Starting GuardProxyCatalog"); myBundleContext = bc; compulsoryRoles = System.getProperty(GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); if (compulsoryRoles == null) { LOG.info("No compulsory roles for a karaf command without the ACL as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); } bc.addServiceListener(this); Filter caFilter = getNonProxyFilter(bc, ConfigurationAdmin.class); LOG.trace("Creating Config Admin Tracker using filter {}", caFilter); configAdminTracker = new ServiceTracker<>(bc, caFilter, null); configAdminTracker.open(); Filter pmFilter = getNonProxyFilter(bc, ProxyManager.class); LOG.trace("Creating Proxy Manager Tracker using filter {}", pmFilter); proxyManagerTracker = new ServiceTracker<>(bc, pmFilter, new ServiceProxyCreatorCustomizer()); proxyManagerTracker.open(); } }
GuardProxyCatalog implements ServiceListener { GuardProxyCatalog(BundleContext bc) throws Exception { LOG.trace("Starting GuardProxyCatalog"); myBundleContext = bc; compulsoryRoles = System.getProperty(GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); if (compulsoryRoles == null) { LOG.info("No compulsory roles for a karaf command without the ACL as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); } bc.addServiceListener(this); Filter caFilter = getNonProxyFilter(bc, ConfigurationAdmin.class); LOG.trace("Creating Config Admin Tracker using filter {}", caFilter); configAdminTracker = new ServiceTracker<>(bc, caFilter, null); configAdminTracker.open(); Filter pmFilter = getNonProxyFilter(bc, ProxyManager.class); LOG.trace("Creating Proxy Manager Tracker using filter {}", pmFilter); proxyManagerTracker = new ServiceTracker<>(bc, pmFilter, new ServiceProxyCreatorCustomizer()); proxyManagerTracker.open(); } GuardProxyCatalog(BundleContext bc); }
GuardProxyCatalog implements ServiceListener { GuardProxyCatalog(BundleContext bc) throws Exception { LOG.trace("Starting GuardProxyCatalog"); myBundleContext = bc; compulsoryRoles = System.getProperty(GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); if (compulsoryRoles == null) { LOG.info("No compulsory roles for a karaf command without the ACL as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); } bc.addServiceListener(this); Filter caFilter = getNonProxyFilter(bc, ConfigurationAdmin.class); LOG.trace("Creating Config Admin Tracker using filter {}", caFilter); configAdminTracker = new ServiceTracker<>(bc, caFilter, null); configAdminTracker.open(); Filter pmFilter = getNonProxyFilter(bc, ProxyManager.class); LOG.trace("Creating Proxy Manager Tracker using filter {}", pmFilter); proxyManagerTracker = new ServiceTracker<>(bc, pmFilter, new ServiceProxyCreatorCustomizer()); proxyManagerTracker.open(); } GuardProxyCatalog(BundleContext bc); @Override void serviceChanged(ServiceEvent event); }
GuardProxyCatalog implements ServiceListener { GuardProxyCatalog(BundleContext bc) throws Exception { LOG.trace("Starting GuardProxyCatalog"); myBundleContext = bc; compulsoryRoles = System.getProperty(GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); if (compulsoryRoles == null) { LOG.info("No compulsory roles for a karaf command without the ACL as its system property is not set: {}", GuardProxyCatalog.KARAF_SECURED_COMMAND_COMPULSORY_ROLES_PROPERTY); } bc.addServiceListener(this); Filter caFilter = getNonProxyFilter(bc, ConfigurationAdmin.class); LOG.trace("Creating Config Admin Tracker using filter {}", caFilter); configAdminTracker = new ServiceTracker<>(bc, caFilter, null); configAdminTracker.open(); Filter pmFilter = getNonProxyFilter(bc, ProxyManager.class); LOG.trace("Creating Proxy Manager Tracker using filter {}", pmFilter); proxyManagerTracker = new ServiceTracker<>(bc, pmFilter, new ServiceProxyCreatorCustomizer()); proxyManagerTracker.open(); } 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; }