use of org.apache.karaf.management.KarafMBeanServerGuard in project karaf by apache.
the class JMXSecurityMBeanImplTestCase method testCanInvokeMBean.
public void testCanInvokeMBean() throws Exception {
MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.replay(mbs);
String objectName = "foo.bar.testing:type=SomeMBean";
KarafMBeanServerGuard testGuard = EasyMock.createMock(KarafMBeanServerGuard.class);
EasyMock.expect(testGuard.canInvoke(null, mbs, new ObjectName(objectName))).andReturn(true);
EasyMock.replay(testGuard);
JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl();
mb.setMBeanServer(mbs);
mb.setGuard(testGuard);
assertTrue(mb.canInvoke(objectName));
}
use of org.apache.karaf.management.KarafMBeanServerGuard in project karaf by apache.
the class JMXSecurityMBeanImplTestCase method testCanInvokeMBeanThrowsException.
public void testCanInvokeMBeanThrowsException() throws Exception {
try {
MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.replay(mbs);
String objectName = "foo.bar.testing:type=SomeMBean";
KarafMBeanServerGuard testGuard = EasyMock.createMock(KarafMBeanServerGuard.class);
EasyMock.expect(testGuard.canInvoke(null, mbs, new ObjectName(objectName))).andThrow(new IOException());
EasyMock.replay(testGuard);
JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl();
mb.setMBeanServer(mbs);
mb.setGuard(testGuard);
mb.canInvoke(objectName);
fail("Should have thrown an exception");
} catch (IOException ioe) {
// good!
}
}
use of org.apache.karaf.management.KarafMBeanServerGuard in project karaf by apache.
the class JMXSecurityMBeanImplTestCase method testCanInvokeMethod.
public void testCanInvokeMethod() throws Exception {
MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.replay(mbs);
String objectName = "foo.bar.testing:type=SomeMBean";
KarafMBeanServerGuard testGuard = EasyMock.createMock(KarafMBeanServerGuard.class);
String[] la = new String[] { "long" };
String[] sa = new String[] { "java.lang.String" };
String[] sa2 = new String[] { "java.lang.String", "java.lang.String" };
EasyMock.expect(testGuard.canInvoke(null, mbs, new ObjectName(objectName), "testMethod", la)).andReturn(true);
EasyMock.expect(testGuard.canInvoke(null, mbs, new ObjectName(objectName), "testMethod", sa)).andReturn(true);
EasyMock.expect(testGuard.canInvoke(null, mbs, new ObjectName(objectName), "otherMethod", sa2)).andReturn(false);
EasyMock.replay(testGuard);
JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl();
mb.setMBeanServer(mbs);
mb.setGuard(testGuard);
assertTrue(mb.canInvoke(objectName, "testMethod", la));
assertTrue(mb.canInvoke(objectName, "testMethod", sa));
assertFalse(mb.canInvoke(objectName, "otherMethod", sa2));
}
use of org.apache.karaf.management.KarafMBeanServerGuard in project karaf by apache.
the class JMXSecurityMBeanImplTestCase method testCanInvokeBulkWithDuplicateMethods.
public void testCanInvokeBulkWithDuplicateMethods() 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("duplicateMethod1"), EasyMock.aryEq(la))).andReturn(true).anyTimes();
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName)), EasyMock.eq("duplicateMethod1"), EasyMock.aryEq(sa))).andReturn(false).anyTimes();
EasyMock.expect(testGuard.canInvoke(EasyMock.anyObject(BulkRequestContext.class), EasyMock.eq(mbs), EasyMock.eq(new ObjectName(objectName)), EasyMock.eq("duplicateMethod2"))).andReturn(true).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("duplicateMethod1(long)", "duplicateMethod1(java.lang.String)", "duplicateMethod1(long)", "duplicateMethod2", "duplicateMethod2"));
TabularData result = mb.canInvoke(query);
assertEquals(3, result.size());
CompositeData cd = result.get(new Object[] { objectName, "duplicateMethod1(long)" });
assertEquals(objectName, cd.get("ObjectName"));
assertEquals("duplicateMethod1(long)", cd.get("Method"));
assertEquals(true, cd.get("CanInvoke"));
CompositeData cd2 = result.get(new Object[] { objectName, "duplicateMethod1(java.lang.String)" });
assertEquals(objectName, cd2.get("ObjectName"));
assertEquals("duplicateMethod1(java.lang.String)", cd2.get("Method"));
assertEquals(false, cd2.get("CanInvoke"));
CompositeData cd3 = result.get(new Object[] { objectName, "duplicateMethod2" });
assertEquals(objectName, cd3.get("ObjectName"));
assertEquals("duplicateMethod2", cd3.get("Method"));
assertEquals(true, cd3.get("CanInvoke"));
}
Aggregations