use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testCanSetAttributeAnyOverload.
public void testCanSetAttributeAnyOverload() 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("setFoo(java.lang.String)", "admin");
configuration.put("setFoo(boolean)", "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, "setFoo"));
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 testCanInvokeAnyOverload.
public void testCanInvokeAnyOverload() throws Exception {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
MBeanParameterInfo[] sig = new MBeanParameterInfo[] { new MBeanParameterInfo("arg1", "java.lang.String", "") };
MBeanOperationInfo op = new MBeanOperationInfo("doit", "", sig, "int", MBeanOperationInfo.INFO);
MBeanParameterInfo[] sig2 = new MBeanParameterInfo[] { new MBeanParameterInfo("arg1", "java.lang.String", ""), new MBeanParameterInfo("arg2", "java.lang.String", "") };
MBeanOperationInfo op2 = new MBeanOperationInfo("doit", "", sig2, "int", MBeanOperationInfo.INFO);
MBeanInfo info = EasyMock.createMock(MBeanInfo.class);
EasyMock.expect(info.getOperations()).andReturn(new MBeanOperationInfo[] { op, op2 }).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("doit(java.lang.String)", "admin");
configuration.put("doit(java.lang.String,java.lang.String)", "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, "doit"));
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 testCanInvokeAnyOverload2.
public void testCanInvokeAnyOverload2() throws Exception {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
MBeanParameterInfo[] sig = new MBeanParameterInfo[] { new MBeanParameterInfo("arg1", "java.lang.String", "") };
MBeanOperationInfo op = new MBeanOperationInfo("foit", "", sig, "int", MBeanOperationInfo.INFO);
MBeanParameterInfo[] sig2 = new MBeanParameterInfo[] { new MBeanParameterInfo("arg1", "java.lang.String", ""), new MBeanParameterInfo("arg2", "java.lang.String", "") };
MBeanOperationInfo op2 = new MBeanOperationInfo("doit", "", sig2, "int", MBeanOperationInfo.INFO);
MBeanInfo info = EasyMock.createMock(MBeanInfo.class);
EasyMock.expect(info.getOperations()).andReturn(new MBeanOperationInfo[] { op, op2 }).anyTimes();
EasyMock.expect(info.getAttributes()).andReturn(new MBeanAttributeInfo[] {}).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("foit(java.lang.String)", "viewer");
configuration.put("doit(java.lang.String,java.lang.String)", "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, "doit"));
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 testRequiredRolesHierarchyWildcard3.
@SuppressWarnings("unchecked")
public void testRequiredRolesHierarchyWildcard3() 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._.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("foo.tar:type=Test");
assertEquals(Collections.singletonList("editor"), guard.getRequiredRoles(on2, "foo", new Object[] {}, new String[] {}));
ObjectName on3 = ObjectName.getInstance("boo.bar:type=Test");
assertEquals(Collections.singletonList("viewer"), guard.getRequiredRoles(on3, "foo", new Object[] {}, new String[] {}));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testCanInvokeMBeanSetter.
public void testCanInvokeMBeanSetter() throws Exception {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
MBeanAttributeInfo attr = new MBeanAttributeInfo("A2", "java.lang.String", "", 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("get*", "admin");
configuration.put("setA2", "viewer");
configuration.put("*", "admin");
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));
return null;
} catch (Throwable th) {
throw new RuntimeException(th);
}
});
}
Aggregations