use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.
the class AbstractTransactionTest method configuredConnection.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Connection configuredConnection(Properties jdbc) throws IOException {
String type = System.getProperty(CONFIGURED_PROVIDER_PROPERTY);
jdbc.setProperty(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, "org.h2.Driver");
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
String pid = "local".equals(type) ? "org.apache.aries.tx.control.jdbc.local" : "org.apache.aries.tx.control.jdbc.xa";
System.out.println("Configuring connection provider with pid " + pid);
resourceProviderConfig().entrySet().stream().forEach(e -> jdbc.put(e.getKey(), e.getValue()));
org.osgi.service.cm.Configuration config = cm.createFactoryConfiguration(pid, "?");
config.update((Hashtable) jdbc);
provider = getService(JDBCConnectionProvider.class, 5000);
return provider.getResource(txControl);
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class GuardingFindHookTest method mockConfigAdminBundleContext.
@SuppressWarnings({ "rawtypes", "unchecked" })
private BundleContext mockConfigAdminBundleContext(Dictionary<String, Object>... configs) throws IOException, InvalidSyntaxException {
Configuration[] configurations = new Configuration[configs.length];
for (int i = 0; i < configs.length; i++) {
Configuration conf = EasyMock.createMock(Configuration.class);
EasyMock.expect(conf.getProperties()).andReturn(configs[i]).anyTimes();
EasyMock.expect(conf.getPid()).andReturn((String) configs[i].get(Constants.SERVICE_PID)).anyTimes();
EasyMock.replay(conf);
configurations[i] = conf;
}
ConfigurationAdmin ca = EasyMock.createMock(ConfigurationAdmin.class);
EasyMock.expect(ca.listConfigurations("(&(service.pid=org.apache.karaf.service.acl.*)(service.guard=*))")).andReturn(configurations).anyTimes();
EasyMock.replay(ca);
final ServiceReference caSR = EasyMock.createMock(ServiceReference.class);
EasyMock.replay(caSR);
Bundle b = EasyMock.createMock(Bundle.class);
EasyMock.expect(b.getBundleId()).andReturn(877342449L).anyTimes();
EasyMock.replay(b);
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getBundle()).andReturn(b).anyTimes();
EasyMock.expect(bc.createFilter(EasyMock.isA(String.class))).andAnswer(() -> FrameworkUtil.createFilter((String) EasyMock.getCurrentArguments()[0])).anyTimes();
String cmFilter = "(&(objectClass=" + ConfigurationAdmin.class.getName() + ")" + "(!(" + GuardProxyCatalog.PROXY_SERVICE_KEY + "=*)))";
bc.addServiceListener(EasyMock.isA(ServiceListener.class), EasyMock.eq(cmFilter));
EasyMock.expectLastCall().anyTimes();
EasyMock.expect(bc.getServiceReferences(EasyMock.anyObject(String.class), EasyMock.eq(cmFilter))).andReturn(new ServiceReference<?>[] { caSR }).anyTimes();
EasyMock.expect(bc.getService(caSR)).andReturn(ca).anyTimes();
EasyMock.replay(bc);
return bc;
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class JMXSecurityMBeanImplTestCase method testCanInvokeBulk.
public void testCanInvokeBulk() throws Exception {
MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.replay(mbs);
ConfigurationAdmin testConfigAdmin = EasyMock.createMock(ConfigurationAdmin.class);
EasyMock.expect(testConfigAdmin.listConfigurations(EasyMock.eq("(service.pid=jmx.acl*)"))).andReturn(new Configuration[0]).anyTimes();
EasyMock.expect(testConfigAdmin.listConfigurations(EasyMock.eq("(service.pid=jmx.acl.whitelist)"))).andReturn(new Configuration[0]).once();
EasyMock.replay(testConfigAdmin);
KarafMBeanServerGuard testGuard = EasyMock.createMock(KarafMBeanServerGuard.class);
String objectName = "foo.bar.testing:type=SomeMBean";
final String[] la = new String[] { "long" };
final String[] sa = new String[] { "java.lang.String" };
EasyMock.expect(testGuard.getConfigAdmin()).andReturn(testConfigAdmin).anyTimes();
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName)), EasyMock.eq("testMethod"), EasyMock.aryEq(la))).andReturn(true).anyTimes();
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName)), EasyMock.eq("testMethod"), EasyMock.aryEq(sa))).andReturn(false).anyTimes();
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName)), EasyMock.eq("otherMethod"))).andReturn(true).anyTimes();
String objectName2 = "foo.bar.testing:type=SomeOtherMBean";
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName2)))).andReturn(true).anyTimes();
String objectName3 = "foo.bar.foo.testing:type=SomeOtherMBean";
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName3)))).andReturn(false).anyTimes();
EasyMock.replay(testGuard);
JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl();
mb.setMBeanServer(mbs);
mb.setGuard(testGuard);
Map<String, List<String>> query = new HashMap<>();
query.put(objectName, Arrays.asList("otherMethod", "testMethod(long)", "testMethod(java.lang.String)"));
query.put(objectName2, Collections.emptyList());
query.put(objectName3, Collections.emptyList());
TabularData result = mb.canInvoke(query);
assertEquals(5, result.size());
CompositeData cd = result.get(new Object[] { objectName, "testMethod(long)" });
assertEquals(objectName, cd.get("ObjectName"));
assertEquals("testMethod(long)", cd.get("Method"));
assertEquals(true, cd.get("CanInvoke"));
CompositeData cd2 = result.get(new Object[] { objectName, "testMethod(java.lang.String)" });
assertEquals(objectName, cd2.get("ObjectName"));
assertEquals("testMethod(java.lang.String)", cd2.get("Method"));
assertEquals(false, cd2.get("CanInvoke"));
CompositeData cd3 = result.get(new Object[] { objectName, "otherMethod" });
assertEquals(objectName, cd3.get("ObjectName"));
assertEquals("otherMethod", cd3.get("Method"));
assertEquals(true, cd3.get("CanInvoke"));
CompositeData cd4 = result.get(new Object[] { objectName2, "" });
assertEquals(objectName2, cd4.get("ObjectName"));
assertEquals("", cd4.get("Method"));
assertEquals(true, cd4.get("CanInvoke"));
CompositeData cd5 = result.get(new Object[] { objectName3, "" });
assertEquals(objectName3, cd5.get("ObjectName"));
assertEquals("", cd5.get("Method"));
assertEquals(false, cd5.get("CanInvoke"));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testRequiredRolesMethodNameWildcardEmpty.
@SuppressWarnings("unchecked")
public void testRequiredRolesMethodNameWildcardEmpty() throws Exception {
Dictionary<String, Object> conf1 = new Hashtable<>();
conf1.put("get*", " ");
conf1.put("*", "admin");
conf1.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test");
Dictionary<String, Object> conf2 = new Hashtable<>();
conf2.put("get*", "viewer");
conf2.put(Constants.SERVICE_PID, "jmx.acl");
ConfigurationAdmin ca = getMockConfigAdmin2(conf1, conf2);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
assertEquals(Collections.emptyList(), guard.getRequiredRoles(on, "getBar", new Object[] {}, new String[] {}));
assertEquals(Collections.singletonList("admin"), guard.getRequiredRoles(on, "test", new Object[] { new Long(17) }, new String[] { "java.lang.Long" }));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testRequiredRolesSignatureEmpty.
public void testRequiredRolesSignatureEmpty() throws Exception {
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("testit", "master");
configuration.put("testit(java.lang.String)", "viewer");
configuration.put("testit(java.lang.String, java.lang.String)", "");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
assertEquals(Collections.emptyList(), guard.getRequiredRoles(on, "testit", new Object[] { "test", "toast" }, new String[] { "java.lang.String", "java.lang.String" }));
}
Aggregations