use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class LogDumpProvider method createDump.
/**
* Attach log entries from directory.
*/
public void createDump(DumpDestination destination) throws Exception {
// get the ConfigAdmin service
ServiceReference ref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
if (ref == null) {
return;
}
// get the PAX Logging configuration
ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) bundleContext.getService(ref);
try {
Configuration configuration = configurationAdmin.getConfiguration("org.ops4j.pax.logging", null);
// get the ".file" Pax Logging properties
Dictionary dictionary = configuration.getProperties();
for (Enumeration e = dictionary.keys(); e.hasMoreElements(); ) {
String property = (String) e.nextElement();
if (property.endsWith(".file")) {
// it's a file appender, get the file location
String location = (String) dictionary.get(property);
File file = new File(location);
if (file.exists()) {
FileInputStream inputStream = new FileInputStream(file);
OutputStream outputStream = destination.add("log/" + file.getName());
StreamUtils.copy(inputStream, outputStream);
}
}
}
} catch (Exception e) {
throw e;
} finally {
bundleContext.ungetService(ref);
}
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class Activator method doStart.
protected void doStart() throws Exception {
BundleContext systemBundleContext = bundleContext.getBundle(0).getBundleContext();
ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
Resolver resolver = new ResolverImpl(new Slf4jResolverLog(LoggerFactory.getLogger(ResolverImpl.class)));
URLStreamHandlerService mvnUrlHandler = getTrackedService(URLStreamHandlerService.class);
if (configurationAdmin == null || mvnUrlHandler == null) {
return;
}
StandardRegionDigraph dg = DigraphHelper.loadDigraph(bundleContext);
registerRegionDiGraph(dg);
boolean configCfgStore = getBoolean("configCfgStore", FeaturesService.DEFAULT_CONFIG_CFG_STORE);
FeatureConfigInstaller configInstaller = configurationAdmin != null ? new FeatureConfigInstaller(configurationAdmin, configCfgStore) : null;
installSupport = new BundleInstallSupportImpl(bundleContext.getBundle(), bundleContext, systemBundleContext, configInstaller, dg);
register(RegionDigraphPersistence.class, () -> installSupport.saveState());
FeatureRepoFinder featureFinder = new FeatureRepoFinder();
register(ManagedService.class, featureFinder, FeatureRepoFinder.getServiceProperties());
Repository globalRepository = getGlobalRepository();
FeaturesServiceConfig cfg = getConfig();
StateStorage stateStorage = createStateStorage();
featuresService = new FeaturesServiceImpl(stateStorage, featureFinder, configurationAdmin, resolver, installSupport, globalRepository, cfg);
try {
EventAdminListener eventAdminListener = new EventAdminListener(bundleContext);
featuresService.registerListener(eventAdminListener);
} catch (Throwable t) {
// No EventAdmin support in this case
}
register(FeaturesService.class, featuresService);
featuresListenerTracker = createFeatureListenerTracker();
featuresListenerTracker.open();
FeaturesServiceMBeanImpl featuresServiceMBean = new FeaturesServiceMBeanImpl();
featuresServiceMBean.setBundleContext(bundleContext);
featuresServiceMBean.setFeaturesService(featuresService);
registerMBean(featuresServiceMBean, "type=feature");
String[] featuresRepositories = getStringArray("featuresRepositories", "");
String featuresBoot = getString("featuresBoot", "");
boolean featuresBootAsynchronous = getBoolean("featuresBootAsynchronous", false);
BootFeaturesInstaller bootFeaturesInstaller = new BootFeaturesInstaller(bundleContext, featuresService, featuresRepositories, featuresBoot, featuresBootAsynchronous);
bootFeaturesInstaller.start();
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class Activator method doStart.
@Override
protected void doStart() throws Exception {
ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
if (configurationAdmin == null) {
return;
}
final BundleServiceImpl bundleService = new BundleServiceImpl(bundleContext);
register(BundleService.class, bundleService);
bundleStateServicesTracker = new ServiceTracker<>(bundleContext, BundleStateService.class, new ServiceTrackerCustomizer<BundleStateService, BundleStateService>() {
@Override
public BundleStateService addingService(ServiceReference<BundleStateService> reference) {
BundleStateService service = bundleContext.getService(reference);
bundleService.registerBundleStateService(service);
return service;
}
@Override
public void modifiedService(ServiceReference<BundleStateService> reference, BundleStateService service) {
}
@Override
public void removedService(ServiceReference<BundleStateService> reference, BundleStateService service) {
bundleService.unregisterBundleStateService(service);
bundleContext.ungetService(reference);
}
});
bundleStateServicesTracker.open();
bundleWatcher = new BundleWatcherImpl(bundleContext, new MavenConfigService(configurationAdmin), bundleService);
bundleWatcher.start();
register(BundleWatcher.class, bundleWatcher);
BundlesMBeanImpl bundlesMBeanImpl = new BundlesMBeanImpl(bundleContext, bundleService);
registerMBean(bundlesMBeanImpl, "type=bundle");
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class JMXSecurityTest method testJMXSecurityAsViewer.
@Test
public void testJMXSecurityAsViewer() throws Exception {
String suffix = "_" + counter.incrementAndGet();
String managerUser = "managerUser" + System.currentTimeMillis() + suffix;
String managerGroup = "managerGroup" + System.currentTimeMillis() + suffix;
String viewerUser = "viewerUser" + System.currentTimeMillis() + suffix;
System.out.println(executeCommand("jaas:realm-manage --realm karaf" + ";jaas:user-add " + managerUser + " " + managerUser + ";jaas:group-add " + managerUser + " " + managerGroup + ";jaas:group-role-add " + managerGroup + " viewer" + ";jaas:group-role-add " + managerGroup + " manager" + ";jaas:user-add " + viewerUser + " " + viewerUser + ";jaas:role-add " + viewerUser + " viewer" + ";jaas:update" + ";jaas:realm-manage --realm karaf" + ";jaas:user-list", new RolePrincipal("admin")));
ConfigurationAdmin configurationAdmin = getOsgiService(ConfigurationAdmin.class, 30000);
org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration("org.apache.karaf.management", null);
if (configuration == null) {
}
JMXConnector connector = getJMXConnector(viewerUser, viewerUser);
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName systemMBean = new ObjectName("org.apache.karaf:type=system,name=root");
assertEquals(100, connection.getAttribute(systemMBean, "StartLevel"));
assertSetAttributeSecEx(connection, systemMBean, new Attribute("StartLevel", 101));
assertEquals("Changing the start level should have no effect for a viewer", 100, connection.getAttribute(systemMBean, "StartLevel"));
assertInvokeSecEx(connection, systemMBean, "halt");
ObjectName memoryMBean = new ObjectName("java.lang:type=Memory");
assertEquals(false, connection.getAttribute(memoryMBean, "Verbose"));
assertSetAttributeSecEx(connection, memoryMBean, new Attribute("Verbose", true));
assertEquals("Changing the verbosity should have no effect for a viewer", false, connection.getAttribute(memoryMBean, "Verbose"));
assertInvokeSecEx(connection, memoryMBean, "gc");
testJMXSecurityMBean(connection, false, false);
testKarafConfigAdminMBean(connection, false, false);
testOSGiConfigAdminMBean(connection, false, false);
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class JMXSecurityMBeanImplTestCase method testCanInvokeBulkCacheConfigAdmin.
public void testCanInvokeBulkCacheConfigAdmin() throws Exception {
MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.replay(mbs);
Configuration fooWildcardTesting = EasyMock.createMock(Configuration.class);
EasyMock.expect(fooWildcardTesting.getPid()).andReturn("jmx.acl.foo._.testing").once();
EasyMock.replay(fooWildcardTesting);
Dictionary<String, Object> fooBarProperties = new Hashtable<>();
// using '*' frees us from mocking JAAS
fooBarProperties.put("testMethod(java.lang.String)", "*");
fooBarProperties.put("testMethod(long)", "*");
Configuration fooBarTesting = EasyMock.createMock(Configuration.class);
EasyMock.expect(fooBarTesting.getPid()).andReturn("jmx.acl.foo.bar.testing").once();
EasyMock.expect(fooBarTesting.getProperties()).andReturn(fooBarProperties).once();
EasyMock.replay(fooBarTesting);
ConfigurationAdmin testConfigAdmin = EasyMock.createMock(ConfigurationAdmin.class);
EasyMock.expect(testConfigAdmin.listConfigurations(EasyMock.eq("(service.pid=jmx.acl*)"))).andReturn(new Configuration[] { fooWildcardTesting, fooBarTesting }).once();
EasyMock.expect(testConfigAdmin.listConfigurations(EasyMock.eq("(service.pid=jmx.acl.whitelist)"))).andReturn(new Configuration[0]).once();
EasyMock.expect(testConfigAdmin.getConfiguration(EasyMock.eq("jmx.acl.foo.bar.testing"), EasyMock.isNull(String.class))).andReturn(fooBarTesting).once();
EasyMock.replay(testConfigAdmin);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(testConfigAdmin);
String objectName = "foo.bar.testing:type=SomeMBean";
String objectName2 = "foo.bar.testing:type=SomeOtherMBean";
JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl();
mb.setMBeanServer(mbs);
mb.setGuard(guard);
Map<String, List<String>> query = new HashMap<>();
query.put(objectName, Collections.singletonList("testMethod(java.lang.String)"));
query.put(objectName2, Collections.singletonList("testMethod(long)"));
TabularData result = mb.canInvoke(query);
assertEquals(2, result.size());
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(true, cd2.get("CanInvoke"));
CompositeData cd4 = result.get(new Object[] { objectName2, "testMethod(long)" });
assertEquals(objectName2, cd4.get("ObjectName"));
assertEquals("testMethod(long)", cd4.get("Method"));
assertEquals(true, cd4.get("CanInvoke"));
EasyMock.verify(testConfigAdmin, fooWildcardTesting, fooBarTesting);
}
Aggregations