Search in sources :

Example 1 with PermissionInfo

use of org.osgi.service.permissionadmin.PermissionInfo 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 PermissionInfo

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

the class PermissionAdminMBeanTest method toEncodedPerm.

private String[] toEncodedPerm(PermissionInfo[] permissions) {
    assertNotNull(permissions);
    String[] encoded = new String[permissions.length];
    for (int i = 0; i < permissions.length; i++) {
        PermissionInfo info = permissions[i];
        encoded[i] = info.getEncoded();
    }
    return encoded;
}
Also used : PermissionInfo(org.osgi.service.permissionadmin.PermissionInfo)

Example 3 with PermissionInfo

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

the class PermissionAdminTest method testSetPermissions.

@Test
public void testSetPermissions() throws IOException {
    PermissionInfo info1 = new PermissionInfo("Admin", "test", "set");
    PermissionInfo info2 = new PermissionInfo("Admin", "test2", "set");
    PermissionInfo[] permInfos = new PermissionInfo[] { info1, info2 };
    String[] encodedPermissions = new String[2];
    int i = 0;
    for (PermissionInfo info : permInfos) {
        encodedPermissions[i++] = info.getEncoded();
    }
    mbean.setPermissions("test", encodedPermissions);
    Mockito.verify(permAdmin).setPermissions("test", permInfos);
}
Also used : PermissionInfo(org.osgi.service.permissionadmin.PermissionInfo) Test(org.junit.Test)

Example 4 with PermissionInfo

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

the class PermissionAdminTest method testGetPermissions.

@Test
public void testGetPermissions() throws IOException {
    PermissionInfo info = new PermissionInfo("Admin", "test", "get");
    PermissionInfo[] permInfos = new PermissionInfo[] { info, info };
    Mockito.when(permAdmin.getPermissions(Mockito.anyString())).thenReturn(permInfos);
    String[] permissions = mbean.getPermissions("test");
    Assert.assertNotNull(permissions);
    Assert.assertEquals(2, permissions.length);
    Assert.assertArrayEquals("Checks encoded permissions", new String[] { info.getEncoded(), info.getEncoded() }, permissions);
    Mockito.reset(permAdmin);
    Mockito.when(permAdmin.getPermissions(Mockito.anyString())).thenReturn(null);
    String[] permissions2 = mbean.getPermissions("test");
    Assert.assertNull(permissions2);
}
Also used : PermissionInfo(org.osgi.service.permissionadmin.PermissionInfo) Test(org.junit.Test)

Example 5 with PermissionInfo

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

the class PermissionAdmin method getPermissions.

/**
     * @see org.osgi.jmx.service.permissionadmin.PermissionAdminMBean#getPermissions(java.lang.String)
     */
public String[] getPermissions(String location) throws IOException {
    if (location == null) {
        throw new IOException("Location cannot be null");
    }
    PermissionInfo[] permissions = permAdmin.getPermissions(location);
    if (permissions != null) {
        String[] encoded = new String[permissions.length];
        for (int i = 0; i < permissions.length; i++) {
            PermissionInfo info = permissions[i];
            encoded[i] = info.getEncoded();
        }
        return encoded;
    }
    return null;
}
Also used : PermissionInfo(org.osgi.service.permissionadmin.PermissionInfo) IOException(java.io.IOException)

Aggregations

PermissionInfo (org.osgi.service.permissionadmin.PermissionInfo)14 Test (org.junit.Test)5 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)2 Triple (org.apache.clerezza.commons.rdf.Triple)2 PermissionAdmin (org.osgi.service.permissionadmin.PermissionAdmin)2 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 ImmutableGraph (org.apache.clerezza.commons.rdf.ImmutableGraph)1 Literal (org.apache.clerezza.commons.rdf.Literal)1 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)1 PermissionDefinitions (org.apache.stanbol.commons.security.PermissionDefinitions)1 Bundle (org.osgi.framework.Bundle)1 PermissionAdminMBean (org.osgi.jmx.service.permissionadmin.PermissionAdminMBean)1