use of ddf.security.permission.impl.KeyValuePermissionImpl in project ddf by codice.
the class CollectionPermissionTest method testCollectionToString.
/**
* Tests that the string output of the collection has correct permissions.
*/
@Test
public void testCollectionToString() {
ArrayList<KeyValuePermission> permissionList = new ArrayList<KeyValuePermission>();
permissionList.add(new KeyValuePermissionImpl("key1", Arrays.asList("val1")));
permissionList.add(new KeyValuePermissionImpl("key2", Arrays.asList("val2")));
CollectionPermission collection = new CollectionPermissionImpl("", permissionList);
// String outputs the correct collection permissions.
assertTrue(collection.toString().indexOf("key2") != -1);
// String does not output extra permissions
assertFalse(collection.toString().indexOf("key3") != -1);
}
use of ddf.security.permission.impl.KeyValuePermissionImpl in project ddf by codice.
the class CollectionPermissionTest method testAddAllCollection.
/**
* Tests that all of the items were added when calling addAll().
*/
@Test
public void testAddAllCollection() {
CollectionPermission collection = new CollectionPermissionImpl();
assertTrue(collection.getPermissionList().isEmpty());
ArrayList<KeyValuePermission> permissionList = new ArrayList<KeyValuePermission>();
permissionList.add(new KeyValuePermissionImpl("key1", Arrays.asList("val1")));
permissionList.add(new KeyValuePermissionImpl("key2", Arrays.asList("val2")));
collection.addAll(permissionList);
assertFalse(collection.getPermissionList().isEmpty());
assertEquals(permissionList.size(), collection.getPermissionList().size());
}
use of ddf.security.permission.impl.KeyValuePermissionImpl in project ddf by codice.
the class CollectionPermissionTest method testCollectionImplies.
/**
* Tests the collection implying permissions and other collections.
*/
@Test
public void testCollectionImplies() {
// Permissions of the user
ArrayList<KeyValuePermission> permissionList = new ArrayList<KeyValuePermission>();
permissionList.add(new KeyValuePermissionImpl("key1", Arrays.asList("val1")));
permissionList.add(new KeyValuePermissionImpl("key2", Arrays.asList("val2")));
permissionList.add(new KeyValuePermissionImpl("key3", Arrays.asList("val3")));
CollectionPermission userPermission = new CollectionPermissionImpl("", permissionList);
// user can create
assertTrue(userPermission.implies(new KeyValuePermissionImpl("key1", Arrays.asList("val1"))));
// user cannot delete
assertFalse(userPermission.implies(new KeyValuePermissionImpl("key2", Arrays.asList("somevalue"))));
// user can create and query
CollectionPermission task1Permission = new CollectionPermissionImpl("", new KeyValuePermissionImpl("key1", Arrays.asList("val1")), new KeyValuePermissionImpl("key2", Arrays.asList("val2")));
assertTrue(userPermission.implies(task1Permission));
// user cannot create AND delete
CollectionPermission task2Permission = new CollectionPermissionImpl("", new KeyValuePermissionImpl("key1", Arrays.asList("val1")), new KeyValuePermissionImpl("somekey", Arrays.asList("somevalue")));
assertFalse(userPermission.implies(task2Permission));
// test empty collection (should always return false)
assertFalse(new CollectionPermissionImpl().implies(userPermission));
}
use of ddf.security.permission.impl.KeyValuePermissionImpl in project ddf by codice.
the class CollectionPermissionTest method testClearCollection.
/**
* Tests that the collection was properly cleared out after calling clear.
*/
@Test
public void testClearCollection() {
ArrayList<KeyValuePermission> permissionList = new ArrayList<KeyValuePermission>();
permissionList.add(new KeyValuePermissionImpl("key1", Arrays.asList("val1")));
permissionList.add(new KeyValuePermissionImpl("key2", Arrays.asList("val2")));
CollectionPermission collection = new CollectionPermissionImpl("", permissionList);
collection.clear();
assertTrue(collection.getPermissionList().isEmpty());
}
use of ddf.security.permission.impl.KeyValuePermissionImpl in project ddf by codice.
the class CollectionPermissionTest method testModifyPermissionList.
/**
* Tests that the permission list that comes back cannot be modified.
*/
@Test(expected = UnsupportedOperationException.class)
public void testModifyPermissionList() {
ArrayList<KeyValuePermission> permissionList = new ArrayList<KeyValuePermission>();
permissionList.add(new KeyValuePermissionImpl("key1", Arrays.asList("val1")));
permissionList.add(new KeyValuePermissionImpl("key2", Arrays.asList("val2")));
CollectionPermission collection = new CollectionPermissionImpl("", permissionList);
collection.getPermissionList().clear();
fail("Returned list should not be able to modify.");
}
Aggregations