Search in sources :

Example 21 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.

the class KarafMBeanServerGuardTest method testRequiredRolesMethodNameWildcard.

public void testRequiredRolesMethodNameWildcard() throws Exception {
    Dictionary<String, Object> configuration = new Hashtable<>();
    configuration.put("getFoo", "viewer");
    configuration.put("get*", " tester , editor,manager");
    configuration.put("*", "admin");
    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(Arrays.asList("tester", "editor", "manager"), guard.getRequiredRoles(on, "getBar", new Object[] {}, new String[] {}));
    assertEquals(Collections.singletonList("admin"), guard.getRequiredRoles(on, "test", new Object[] { new Long(17) }, new String[] { "java.lang.Long" }));
}
Also used : ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 22 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.

the class KarafMBeanServerGuardTest method testRequiredRolesMethodNameWildcard3.

public void testRequiredRolesMethodNameWildcard3() throws Exception {
    Dictionary<String, Object> configuration = new Hashtable<>();
    configuration.put("get*", "viewer");
    configuration.put("*", "admin");
    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("viewer"), guard.getRequiredRoles(on, "get", new Object[] {}, new String[] {}));
    assertEquals(Collections.singletonList("admin"), guard.getRequiredRoles(on, "ge", new Object[] {}, new String[] {}));
}
Also used : ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 23 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.

the class KarafMBeanServerGuardTest method testRequiredRolesExact2.

public void testRequiredRolesExact2() throws Exception {
    Dictionary<String, Object> configuration = new Hashtable<>();
    configuration.put("foo(java.lang.String,java.lang.String)[\"a\",\",\"]", "editor #this is the editor rule");
    configuration.put("foo(java.lang.String,java.lang.String)[\",\" , \"a\"]", "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, "foo", new Object[] { "a", "," }, new String[] { "java.lang.String", "java.lang.String" }));
    assertEquals(Collections.singletonList("viewer"), guard.getRequiredRoles(on, "foo", new Object[] { ",", "a" }, new String[] { "java.lang.String", "java.lang.String" }));
    assertEquals(Collections.emptyList(), guard.getRequiredRoles(on, "foo", new Object[] { "a", "a" }, new String[] { "java.lang.String", "java.lang.String" }));
}
Also used : ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 24 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.

the class KarafMBeanServerGuardTest method testRequiredRolesMethodNameEmpty.

@SuppressWarnings("unchecked")
public void testRequiredRolesMethodNameEmpty() throws Exception {
    Dictionary<String, Object> conf1 = new Hashtable<>();
    conf1.put("doit", "");
    conf1.put("fryit", "editor, viewer");
    conf1.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test");
    Dictionary<String, Object> conf2 = new Hashtable<>();
    conf2.put("doit", "editor");
    conf2.put(Constants.SERVICE_PID, "jmx.acl.foo.bar");
    ConfigurationAdmin ca = getMockConfigAdmin2(conf1, conf2);
    KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
    guard.setConfigAdmin(ca);
    ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
    assertEquals(Collections.emptyList(), guard.getRequiredRoles(on, "doit", new Object[] {}, new String[] {}));
    assertEquals(Arrays.asList("editor", "viewer"), guard.getRequiredRoles(on, "fryit", new Object[] { "blah" }, new String[] { "java.lang.String" }));
}
Also used : ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 25 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.

the class KarafMBeanServerGuardTest method testRequiredRolesMethodNameOnly.

public void testRequiredRolesMethodNameOnly() throws Exception {
    Dictionary<String, Object> configuration = new Hashtable<>();
    configuration.put("doit", "master");
    configuration.put("fryit", "editor,viewer");
    ConfigurationAdmin ca = getMockConfigAdmin(configuration);
    KarafMBeanServerGuard guard = new KarafMBeanServerGuard();
    guard.setConfigAdmin(ca);
    ObjectName on = ObjectName.getInstance("foo.bar:type=Test");
    assertEquals(Collections.singletonList("master"), guard.getRequiredRoles(on, "doit", new Object[] {}, new String[] {}));
    assertEquals(Arrays.asList("editor", "viewer"), guard.getRequiredRoles(on, "fryit", new Object[] { "blah" }, new String[] { "java.lang.String" }));
}
Also used : ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Aggregations

ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)211 Configuration (org.osgi.service.cm.Configuration)114 Test (org.junit.Test)65 Hashtable (java.util.Hashtable)57 ServiceReference (org.osgi.framework.ServiceReference)52 IOException (java.io.IOException)44 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)25 BundleContext (org.osgi.framework.BundleContext)25 Subject (javax.security.auth.Subject)24 Dictionary (java.util.Dictionary)23 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)21 Bundle (org.osgi.framework.Bundle)16 Properties (java.util.Properties)15 File (java.io.File)8 HashSet (java.util.HashSet)7 BundleException (org.osgi.framework.BundleException)7 Method (java.lang.reflect.Method)6 ObjectName (javax.management.ObjectName)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4