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);
}
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());
}
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));
}
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);
}
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;
}
Aggregations