Search in sources :

Example 1 with PermissionAdminMBean

use of org.osgi.jmx.service.permissionadmin.PermissionAdminMBean in project aries by apache.

the class PermissionAdminMBeanTest method testMBeanInterface.

@Test
public void testMBeanInterface() throws IOException {
    PermissionAdminMBean mBean = getMBean(PermissionAdminMBean.OBJECTNAME, PermissionAdminMBean.class);
    PermissionAdmin permAdminService = context().getService(PermissionAdmin.class);
    assertNotNull(permAdminService);
    String[] serviceLocation = permAdminService.getLocations();
    String[] mBeanLocations = mBean.listLocations();
    assertArrayEquals(serviceLocation, mBeanLocations);
    PermissionInfo defPerm = new PermissionInfo("AllPermission", "*", "*");
    permAdminService.setDefaultPermissions(new PermissionInfo[] { defPerm });
    PermissionInfo[] permissions = permAdminService.getDefaultPermissions();
    assertNotNull(permissions);
    String[] encoded = toEncodedPerm(permissions);
    String[] mBeanDefPermissions = mBean.listDefaultPermissions();
    assertArrayEquals(encoded, mBeanDefPermissions);
    Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
    assertNotNull(a);
    String location = a.getLocation();
    PermissionInfo bundleaPerm = new PermissionInfo("ServicePermission", "ServiceA", "GET");
    mBean.setPermissions(location, new String[] { bundleaPerm.getEncoded() });
    String[] serviceBundleaPerm = toEncodedPerm(permAdminService.getPermissions(location));
    String[] mBeanBundleaPerm = mBean.getPermissions(location);
    assertNotNull(mBeanBundleaPerm);
    assertArrayEquals(serviceBundleaPerm, mBeanBundleaPerm);
    PermissionInfo defaultPerm = new PermissionInfo("AllPermission", "*", "GET");
    mBean.setDefaultPermissions(new String[] { defaultPerm.getEncoded() });
    String[] serviceDefaultPerm = toEncodedPerm(permAdminService.getDefaultPermissions());
    String[] mBeanDefaultPerm = mBean.listDefaultPermissions();
    assertNotNull(mBeanDefaultPerm);
    assertArrayEquals(serviceDefaultPerm, mBeanDefaultPerm);
}
Also used : PermissionInfo(org.osgi.service.permissionadmin.PermissionInfo) Bundle(org.osgi.framework.Bundle) PermissionAdminMBean(org.osgi.jmx.service.permissionadmin.PermissionAdminMBean) PermissionAdmin(org.osgi.service.permissionadmin.PermissionAdmin) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 2 with PermissionAdminMBean

use of org.osgi.jmx.service.permissionadmin.PermissionAdminMBean in project aries by apache.

the class PermissionAdminMBeanHandler method constructInjectMBean.

/**
 * @see org.apache.aries.jmx.AbstractCompendiumHandler#constructInjectMBean(java.lang.Object)
 */
@Override
protected StandardMBean constructInjectMBean(Object targetService) {
    PermissionAdminMBean paMBean = new PermissionAdmin((org.osgi.service.permissionadmin.PermissionAdmin) targetService);
    StandardMBean mbean = null;
    try {
        mbean = new StandardMBean(paMBean, PermissionAdminMBean.class);
    } catch (NotCompliantMBeanException e) {
        Logger logger = agentContext.getLogger();
        logger.log(LogService.LOG_ERROR, "Not compliant MBean", e);
    }
    return mbean;
}
Also used : StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) PermissionAdminMBean(org.osgi.jmx.service.permissionadmin.PermissionAdminMBean) Logger(org.apache.aries.jmx.Logger)

Aggregations

PermissionAdminMBean (org.osgi.jmx.service.permissionadmin.PermissionAdminMBean)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 StandardMBean (javax.management.StandardMBean)1 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)1 Logger (org.apache.aries.jmx.Logger)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 PermissionAdmin (org.osgi.service.permissionadmin.PermissionAdmin)1 PermissionInfo (org.osgi.service.permissionadmin.PermissionInfo)1