use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testGetAttributes2.
public void testGetAttributes2() throws Throwable {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
MBeanAttributeInfo attr = new MBeanAttributeInfo("Toast", "boolean", "", true, false, true);
MBeanAttributeInfo attr2 = new MBeanAttributeInfo("TestSomething", "boolean", "", true, false, true);
MBeanAttributeInfo attr3 = new MBeanAttributeInfo("Butter", "boolean", "", true, true, true);
MBeanInfo mbeanInfo = EasyMock.createMock(MBeanInfo.class);
EasyMock.expect(mbeanInfo.getAttributes()).andReturn(new MBeanAttributeInfo[] { attr, attr2, attr3 }).anyTimes();
EasyMock.replay(mbeanInfo);
final MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(mbeanInfo).anyTimes();
EasyMock.replay(mbs);
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("isT*", "editor");
configuration.put("getToast", "admin");
configuration.put("getButter", "editor");
configuration.put("getTest*", "admin");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
final KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
Subject subject = loginWithTestRoles("editor", "admin");
Subject.doAs(subject, (PrivilegedAction<Void>) () -> {
try {
Method im = MBeanServer.class.getMethod("getAttributes", ObjectName.class, String[].class);
guard.invoke(mbs, im, new Object[] { on, new String[] { "Toast" } });
guard.invoke(mbs, im, new Object[] { on, new String[] { "TestSomething", "Toast" } });
try {
guard.invoke(mbs, im, new Object[] { on, new String[] { "Butter", "Toast" } });
fail("Should not have allowed the invocation");
} catch (SecurityException se) {
}
return null;
} catch (Throwable ex) {
throw new RuntimeException(ex);
}
});
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testRequiredRolesMethodNameWildcard2.
public void testRequiredRolesMethodNameWildcard2() throws Exception {
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("ge", "janitor");
configuration.put("get", "admin");
configuration.put("get*", "viewer");
configuration.put("*", "manager");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
assertEquals(Collections.singletonList("viewer"), guard.getRequiredRoles(on, "getFoo", new Object[] {}, new String[] {}));
assertEquals(Collections.singletonList("admin"), guard.getRequiredRoles(on, "get", new Object[] {}, new String[] {}));
assertEquals(Collections.singletonList("janitor"), guard.getRequiredRoles(on, "ge", new Object[] {}, new String[] {}));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testGetAttributeIs.
public void testGetAttributeIs() throws Throwable {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
MBeanAttributeInfo attr = new MBeanAttributeInfo("Toast", "boolean", "", true, false, true);
MBeanAttributeInfo attr2 = new MBeanAttributeInfo("TestAttr", "java.lang.String", "", true, false, false);
MBeanAttributeInfo attr3 = new MBeanAttributeInfo("Butter", "int", "", true, true, false);
MBeanInfo mbeanInfo = EasyMock.createMock(MBeanInfo.class);
EasyMock.expect(mbeanInfo.getAttributes()).andReturn(new MBeanAttributeInfo[] { attr, attr2, attr3 }).anyTimes();
EasyMock.replay(mbeanInfo);
final MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(mbeanInfo).anyTimes();
EasyMock.replay(mbs);
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("getToast", "admin");
configuration.put("isToast", "editor");
configuration.put("getTest*", "admin");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
final KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
Subject subject = loginWithTestRoles("editor", "admin");
Subject.doAs(subject, (PrivilegedAction<Void>) () -> {
try {
Method im = MBeanServer.class.getMethod("getAttribute", ObjectName.class, String.class);
guard.invoke(mbs, im, new Object[] { on, "Toast" });
guard.invoke(mbs, im, new Object[] { on, "TestAttr" });
try {
guard.invoke(mbs, im, new Object[] { on, "Butter" });
fail("Should not have allowed the invocation");
} catch (SecurityException se) {
}
return null;
} catch (Throwable ex) {
throw new RuntimeException(ex);
}
});
}
use of org.osgi.service.cm.ConfigurationAdmin in project sling by apache.
the class ServicesListener method notifyChange.
public synchronized void notifyChange() {
// check if all services are available
final ResourceChangeListener listener = (ResourceChangeListener) this.changeHandlerListener.getService();
final ConfigurationAdmin configAdmin = (ConfigurationAdmin) this.configAdminListener.getService();
if (configAdmin != null && listener != null) {
if (configTaskCreator == null) {
final Hashtable<String, String> props = new Hashtable<String, String>();
props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Configuration Install Task Factory");
props.put(Constants.SERVICE_VENDOR, VENDOR);
props.put(InstallTaskFactory.NAME, "org.osgi.service.cm");
props.put(ResourceTransformer.NAME, "org.osgi.service.cm");
this.configTaskCreator = new ConfigTaskCreator(listener, configAdmin);
// start and register osgi installer service
final String[] serviceInterfaces = { InstallTaskFactory.class.getName(), ConfigurationListener.class.getName(), ResourceTransformer.class.getName() };
configTaskCreatorRegistration = this.bundleContext.registerService(serviceInterfaces, configTaskCreator, props);
}
} else {
this.stop();
}
}
use of org.osgi.service.cm.ConfigurationAdmin in project sling by apache.
the class MDCStateServlet method createTestConfig.
private void createTestConfig() throws IOException {
ConfigurationAdmin ca = (ConfigurationAdmin) configAdminTracker.getService();
Configuration cfg = ca.getConfiguration("org.apache.sling.extensions.mdc.internal.MDCInsertingFilter", null);
Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put("headers", new String[] { "mdc-test-header" });
dict.put("parameters", new String[] { "mdc-test-param" });
dict.put("cookies", new String[] { "mdc-test-cookie" });
cfg.update(dict);
}
Aggregations