use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testRequiredRolesRegExp.
public void testRequiredRolesRegExp() throws Exception {
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put(" testit (java.lang.String) [ /ab/]", "manager");
configuration.put("testit(java.lang.String)[/c\"d/]", "tester");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
assertEquals(Collections.singletonList("manager"), guard.getRequiredRoles(on, "testit", new Object[] { "ab" }, new String[] { "java.lang.String" }));
assertEquals(Collections.singletonList("manager"), guard.getRequiredRoles(on, "testit", new Object[] { " ab " }, new String[] { "java.lang.String" }));
assertEquals(Collections.emptyList(), guard.getRequiredRoles(on, "testit", new Object[] { " a b " }, new String[] { "java.lang.String" }));
assertEquals(Collections.singletonList("tester"), guard.getRequiredRoles(on, "testit", new Object[] { " c\"d " }, new String[] { "java.lang.String" }));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testRequiredRolesNumeric.
public void testRequiredRolesNumeric() throws Exception {
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("bar(int)[\"17\"]", "editor #this is the editor rule");
configuration.put("bar", "viewer");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
assertEquals(Collections.singletonList("editor"), guard.getRequiredRoles(on, "bar", new Object[] { new Integer(17) }, new String[] { "int" }));
assertEquals(Collections.singletonList("viewer"), guard.getRequiredRoles(on, "bar", new Object[] { new Integer(18) }, new String[] { "int" }));
}
use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.
the class KarafMBeanServerGuardTest method testCanInvokeMethod2.
public void testCanInvokeMethod2() throws Exception {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("doit(java.lang.String)[/11/]", "viewer");
configuration.put("doit(java.lang.String)", "admin");
configuration.put("doit(java.lang.String,java.lang.String)", "admin");
configuration.put("doit(int)[\"12\"]", "viewer");
configuration.put("doit", "viewer");
configuration.put("do*", "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(null, on, "doit", new String[] { "java.lang.String" }));
assertTrue(guard.canInvoke(null, on, "doit", new String[] {}));
assertTrue(guard.canInvoke(null, on, "doit", new String[] { "int" }));
assertFalse(guard.canInvoke(null, on, "doit", new String[] { "java.lang.String", "java.lang.String" }));
assertFalse(guard.canInvoke(null, on, "dodo", new String[] { "java.lang.String" }));
assertFalse(guard.canInvoke(null, on, "uuuh", new String[] { "java.lang.String" }));
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 testCanInvokeMBean.
public void testCanInvokeMBean() throws Exception {
final ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
final ObjectName on2 = ObjectName.getInstance("foo.bar:type=Toast");
MBeanParameterInfo[] sig = new MBeanParameterInfo[] { new MBeanParameterInfo("arg1", "java.lang.String", "") };
MBeanOperationInfo op = new MBeanOperationInfo("doit", "", sig, "int", MBeanOperationInfo.INFO);
MBeanInfo info = EasyMock.createMock(MBeanInfo.class);
EasyMock.expect(info.getOperations()).andReturn(new MBeanOperationInfo[] { op }).anyTimes();
EasyMock.expect(info.getAttributes()).andReturn(new MBeanAttributeInfo[] {}).anyTimes();
EasyMock.replay(info);
MBeanInfo info2 = EasyMock.createMock(MBeanInfo.class);
EasyMock.expect(info2.getOperations()).andReturn(new MBeanOperationInfo[] {}).anyTimes();
EasyMock.expect(info2.getAttributes()).andReturn(new MBeanAttributeInfo[] {}).anyTimes();
EasyMock.replay(info2);
final MBeanServer mbs = EasyMock.createMock(MBeanServer.class);
EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes();
EasyMock.expect(mbs.getMBeanInfo(on2)).andReturn(info2).anyTimes();
EasyMock.replay(mbs);
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("doit(java.lang.String)[/11/]", "admin");
configuration.put("doit(java.lang.String)", "viewer");
configuration.put("doit(java.lang.String,java.lang.String)", "viewer");
configuration.put("doit(int)[\"12\"]", "admin");
configuration.put("doit", "admin");
configuration.put("do*", "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));
assertFalse(guard.canInvoke(mbs, on2));
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 testRequiredRolesSignature.
public void testRequiredRolesSignature() throws Exception {
Dictionary<String, Object> configuration = new Hashtable<>();
configuration.put("testit", "master");
configuration.put("testit(java.lang.String)", "viewer");
configuration.put("testit(java.lang.String, java.lang.String)", "editor");
ConfigurationAdmin ca = getMockConfigAdmin(configuration);
KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
guard.setConfigAdmin(ca);
ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
assertEquals(Collections.singletonList("editor"), guard.getRequiredRoles(on, "testit", new Object[] { "test", "toast" }, new String[] { "java.lang.String", "java.lang.String" }));
}
Aggregations