use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testCanGetAttributeAnyOverload2.
public void testCanGetAttributeAnyOverload2() throws Exception {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
MBeanAttributeInfo attr = new MBeanAttributeInfo("Foo", "int", "", true, true, false);
MBeanInfo info = EasyMock.createMock(MBeanInfo.class);
EasyMock.expect(info.getOperations()).andReturn(new MBeanOperationInfo[] {}).anyTimes();
EasyMock.expect(info.getAttributes()).andReturn(new MBeanAttributeInfo[] { attr }).anyTimes();
EasyMock.replay(info);
final MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes();
EasyMock.replay(mbs);
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("getFoo(java.lang.String)", "viewer");
configuration.put("getFoo()", "admin");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
final KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
Subject subject = loginWithTestRoles("viewer");
Subject.doAs(subject, (PrivilegedAction<Void>) () -> {
try {
assertFalse(guard.canInvoke(mbs, on, "getFoo"));
return null;
} catch (Throwable th) {
throw new RuntimeException(th);
}
});
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testRequiredRolesRegExpNobody.
public void testRequiredRolesRegExpNobody() throws Exception {
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("testit(java.lang.String)[/ab/]", "");
configuration.put("test*", "tester");
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[] { "ab" }, new String[] { "java.lang.String" }));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testRequiredRolesHierarchyWildcard2.
@SuppressWarnings("unchecked")
public void testRequiredRolesHierarchyWildcard2() throws Exception {
Dictionary<String, Object> conf1 = new Hashtable<>();
conf1.put("foo", "viewer");
conf1.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test");
Dictionary<String, Object> conf2 = new Hashtable<>();
conf2.put("foo", "editor");
conf2.put(Constants.SERVICE_PID, "jmx.acl._.bar.Test");
ConfigurationAdmin ca = getMockConfigAdmin2(conf1, conf2);
assertEquals("Precondition", 2, ca.listConfigurations("(service.pid=jmx.acl*)").length);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
ObjectName on1 = ObjectName.getInstance("foo.bar:type=Test");
assertEquals("Should only return the most specific definition", Collections.singletonList("viewer"), guard.getRequiredRoles(on1, "foo", new Object[] {}, new String[] {}));
ObjectName on2 = ObjectName.getInstance("tar.bar:type=Test");
assertEquals("Should return definition from wildcard PID", Collections.singletonList("editor"), guard.getRequiredRoles(on2, "foo", new Object[] {}, new String[] {}));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testRequiredRolesHierarchyWildcard1.
@SuppressWarnings("unchecked")
public void testRequiredRolesHierarchyWildcard1() throws Exception {
Dictionary<String, Object> conf1 = new Hashtable<>();
conf1.put("foo", "viewer");
conf1.put(Constants.SERVICE_PID, "jmx.acl._.bar.Test");
Dictionary<String, Object> conf2 = new Hashtable<>();
conf2.put("foo", "editor");
conf2.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test");
ConfigurationAdmin ca = getMockConfigAdmin2(conf1, conf2);
assertEquals("Precondition", 2, ca.listConfigurations("(service.pid=jmx.acl*)").length);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
ObjectName on1 = ObjectName.getInstance("foo.bar:type=Test");
assertEquals("Should only return the most specific definition", Collections.singletonList("editor"), guard.getRequiredRoles(on1, "foo", new Object[] {}, new String[] {}));
ObjectName on2 = ObjectName.getInstance("tar.bar:type=Test");
assertEquals("Should return definition from wildcard PID", Collections.singletonList("viewer"), guard.getRequiredRoles(on2, "foo", new Object[] {}, new String[] {}));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testCanGetAttributeAnyOverload3.
public void testCanGetAttributeAnyOverload3() throws Exception {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
MBeanAttributeInfo attr = new MBeanAttributeInfo("Foo", "boolean", "", true, true, true);
MBeanInfo info = EasyMock.createMock(MBeanInfo.class);
EasyMock.expect(info.getOperations()).andReturn(new MBeanOperationInfo[] {}).anyTimes();
EasyMock.expect(info.getAttributes()).andReturn(new MBeanAttributeInfo[] { attr }).anyTimes();
EasyMock.replay(info);
final MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes();
EasyMock.replay(mbs);
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("getFoo(java.lang.String)", "admin");
configuration.put("getFoo()", "admin");
configuration.put("isFoo()", "viewer");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
final KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
Subject subject = loginWithTestRoles("viewer");
Subject.doAs(subject, (PrivilegedAction<Void>) () -> {
try {
assertTrue(guard.canInvoke(mbs, on, "isFoo"));
return null;
} catch (Throwable th) {
throw new RuntimeException(th);
}
});
}
Aggregations