Search in sources :

Example 1 with Permission

use of org.onosproject.security.Permission in project onos by opennetworkinglab.

the class ApplicationArchive method getPermissions.

// Returns the set of Permissions specified in the app.xml file
private ImmutableSet<Permission> getPermissions(XMLConfiguration cfg) {
    List<Permission> permissionList = Lists.newArrayList();
    for (Object o : cfg.getList(APP_PERMISSIONS)) {
        String name = (String) o;
        permissionList.add(new Permission(AppPermission.class.getName(), name));
    }
    for (Object o : cfg.getList(NET_PERMISSIONS)) {
        // TODO: TO BE FLESHED OUT WHEN NETWORK PERMISSIONS ARE SUPPORTED
        break;
    }
    List<HierarchicalConfiguration> fields = cfg.configurationsAt(JAVA_PERMISSIONS);
    for (HierarchicalConfiguration sub : fields) {
        String classname = sub.getString("classname");
        String name = sub.getString("name");
        String actions = sub.getString("actions");
        if (classname != null && name != null) {
            permissionList.add(new Permission(classname, name, actions));
        }
    }
    return ImmutableSet.copyOf(permissionList);
}
Also used : Permission(org.onosproject.security.Permission) AppPermission(org.onosproject.security.AppPermission) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 2 with Permission

use of org.onosproject.security.Permission in project onos by opennetworkinglab.

the class SimpleApplicationStoreTest method permissions.

@Test
public void permissions() {
    Application app = createTestApp();
    ImmutableSet<Permission> permissions = ImmutableSet.of(new Permission(AppPermission.class.getName(), "FLOWRULE_WRITE"));
    store.setPermissions(app.id(), permissions);
    assertEquals("incorrect app perms", 1, store.getPermissions(app.id()).size());
    assertEquals("incorrect app state", INSTALLED, store.getState(app.id()));
    assertEquals("incorrect event type", APP_PERMISSIONS_CHANGED, delegate.event.type());
    assertEquals("incorrect event app", app, delegate.event.subject());
}
Also used : Permission(org.onosproject.security.Permission) AppPermission(org.onosproject.security.AppPermission) Application(org.onosproject.core.Application) Test(org.junit.Test)

Example 3 with Permission

use of org.onosproject.security.Permission in project onos by opennetworkinglab.

the class DistributedSecurityModeStoreTest method testRequestPermission.

@Test
public void testRequestPermission() {
    states.compute(appId, (id, securityInfo) -> new SecurityInfo(securityInfo.getPermissions(), POLICY_VIOLATED));
    assertEquals(POLICY_VIOLATED, states.get(appId).getState());
    Permission testPermissionB = new Permission("testClassB", "testNameB");
    violations.compute(appId, (k, v) -> v == null ? Sets.newHashSet(testPermissionB) : addAndGet(v, testPermissionB));
    assertTrue(violations.get(appId).contains(testPermissionB));
}
Also used : Permission(org.onosproject.security.Permission) Test(org.junit.Test)

Example 4 with Permission

use of org.onosproject.security.Permission in project onos by opennetworkinglab.

the class SecurityModeManagerTest method setUp.

@Before
public void setUp() throws Exception {
    store = new SecurityModeStoreAdapter();
    appId = new DefaultApplicationId(1, "test");
    testPermissions = new HashSet<Permission>();
    testPermission = new Permission("testClass", "testNameAdmin");
    testPermissions.add(testPermission);
    testFeatures = new ArrayList<String>();
    testFeatures.add("testFeature");
    testRequiredApps = new ArrayList<String>();
    testRequiredApps.add("testRequiredApp");
    app = DefaultApplication.builder().withAppId(appId).withVersion(Version.version(1, 1, "patch", "build")).withTitle("testTitle").withDescription("testDes").withOrigin("testOri").withCategory("testCT").withUrl("testurl").withReadme("test").withIcon(null).withRole(ApplicationRole.ADMIN).withPermissions(testPermissions).withFeaturesRepo(Optional.ofNullable(null)).withFeatures(testFeatures).withRequiredApps(testRequiredApps).build();
    store.registerApplication(appId);
}
Also used : Permission(org.onosproject.security.Permission) SecurityModeStoreAdapter(org.onosproject.security.store.SecurityModeStoreAdapter) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) Before(org.junit.Before)

Example 5 with Permission

use of org.onosproject.security.Permission in project onos by opennetworkinglab.

the class SecurityModeManagerTest method getPrintablePermissionMap.

private Map<Integer, List<Permission>> getPrintablePermissionMap(Set<Permission> perms) {
    ConcurrentHashMap<Integer, List<Permission>> sortedMap = new ConcurrentHashMap<>();
    sortedMap.put(0, new ArrayList());
    sortedMap.put(1, new ArrayList());
    sortedMap.put(2, new ArrayList());
    sortedMap.put(3, new ArrayList());
    sortedMap.put(4, new ArrayList());
    for (Permission perm : perms) {
        if (perm.getName().contains("Admin")) {
            sortedMap.get(1).add(perm);
        } else {
            sortedMap.get(2).add(perm);
        }
    }
    return sortedMap;
}
Also used : ArrayList(java.util.ArrayList) Permission(org.onosproject.security.Permission) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Permission (org.onosproject.security.Permission)7 AppPermission (org.onosproject.security.AppPermission)3 Before (org.junit.Before)2 Test (org.junit.Test)2 DefaultApplicationId (org.onosproject.core.DefaultApplicationId)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 Application (org.onosproject.core.Application)1 ApplicationId (org.onosproject.core.ApplicationId)1 ApplicationRole (org.onosproject.core.ApplicationRole)1 Version (org.onosproject.core.Version)1 SecurityModeStoreAdapter (org.onosproject.security.store.SecurityModeStoreAdapter)1