use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class TestRestService method newSeriesService.
private static SeriesService newSeriesService() {
AccessControlList acl = new AccessControlList();
SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
try {
EasyMock.expect(seriesService.getSeriesAccessControl((String) EasyMock.anyObject())).andReturn(acl).anyTimes();
EasyMock.expect(seriesService.updateAccessControl((String) EasyMock.anyObject(), (AccessControlList) EasyMock.anyObject())).andThrow(new NotFoundException()).andReturn(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
EasyMock.replay(seriesService);
return seriesService;
}
use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class JpaAclDbTest method testProvider.
@Test
public void testProvider() {
//
// add ACL to org1
final AccessControlList publicAcl = acl(entry("anonymous", "read", true));
final Option<ManagedAcl> acl = p.createAcl(org1, publicAcl, "public");
assertTrue(acl.isSome());
assertTrue(p.getAcl(org1, acl.get().getId()).isSome());
// ACL should not be visible for org2
assertTrue(p.getAcl(org2, acl.get().getId()).isNone());
// create duplicate which should be denied
assertTrue(p.createAcl(org1, publicAcl, "public").isNone());
//
// add another ACL to org1
p.createAcl(org1, acl(entries("instructor", tuple("read", true), tuple("write", true))), "instructor");
assertEquals(2, p.getAcls(org1).size());
// org2 should still have no ACLs
assertEquals(0, p.getAcls(org2).size());
//
// add same ACL to org2
p.createAcl(org2, publicAcl, "public");
assertEquals(1, p.getAcls(org2).size());
assertEquals(2, p.getAcls(org1).size());
//
// update
final ManagedAcl org1Acl = acl.get();
// update with new ACL
assertTrue(p.updateAcl(new ManagedAclImpl(org1Acl.getId(), org1Acl.getName(), org1Acl.getOrganizationId(), acl(entry("anonymous", "write", true)))));
assertEquals("write", p.getAcl(org1, org1Acl.getId()).get().getAcl().getEntries().get(0).getAction());
// update with new name
final ManagedAcl org1AclUpdated = new ManagedAclImpl(org1Acl.getId(), "public2", org1Acl.getOrganizationId(), org1Acl.getAcl());
assertTrue(p.updateAcl(org1AclUpdated));
assertEquals("public2", p.getAcl(org1, org1AclUpdated.getId()).get().getName());
// try to update a non-existing ACL
assertFalse(p.updateAcl(new ManagedAclImpl(27427492384723L, "public2", org1.getId(), org1Acl.getAcl())));
assertEquals(2, p.getAcls(org1).size());
// update without any update
assertTrue(p.updateAcl(org1AclUpdated));
assertEquals(2, p.getAcls(org1).size());
// try to update an ACL of a different org
assertFalse(p.updateAcl(new ManagedAclImpl(org1Acl.getId(), "bla", org2.getId(), org1Acl.getAcl())));
//
// delete
assertTrue(p.deleteAcl(org1, org1Acl.getId()));
assertEquals(1, p.getAcls(org1).size());
// try to delete a non-existing ACL
assertFalse(p.deleteAcl(org1, 894892374923L));
// try to delete an ACL of a different org
assertFalse(p.deleteAcl(org2, org1Acl.getId()));
assertEquals(1, p.getAcls(org2).size());
}
use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class AclScannerTest method testCorrectFileInstall.
@Test
public void testCorrectFileInstall() throws Exception {
File file = new File(AclScannerTest.class.getResource("/xacml_correct.xml").toURI());
ManagedAcl acl = new ManagedAclImpl(1L, "TestAcl", "org", new AccessControlList());
Option<ManagedAcl> managedAcl = Option.some(acl);
EasyMock.expect(aclDb.createAcl(anyObject(Organization.class), anyObject(AccessControlList.class), anyString())).andReturn(managedAcl).times(3);
EasyMock.expect(aclDb.getAcls(anyObject(Organization.class))).andReturn(new ArrayList<ManagedAcl>()).times(3);
EasyMock.replay(aclDb);
aclScanner.install(file);
EasyMock.verify(aclDb);
}
use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class AclScannerTest method testRemoveFile.
@Test
public void testRemoveFile() throws Exception {
File file1 = new File(AclScannerTest.class.getResource("/xacml_correct.xml").toURI());
Long id = 1L;
String org = "org";
ManagedAcl acl = new ManagedAclImpl(id, "TestAcl", org, new AccessControlList());
Option<ManagedAcl> managedAcl = Option.some(acl);
EasyMock.expect(aclDb.createAcl(anyObject(Organization.class), anyObject(AccessControlList.class), anyString())).andReturn(managedAcl).times(3);
EasyMock.expect(aclDb.getAcl(EasyMock.anyObject(Organization.class), anyLong())).andReturn(managedAcl).times(3);
EasyMock.expect(aclDb.deleteAcl(anyObject(Organization.class), anyLong())).andReturn(true).times(3);
EasyMock.expect(aclDb.getAcls(anyObject(Organization.class))).andReturn(new ArrayList<ManagedAcl>()).times(3);
EasyMock.replay(aclDb);
aclScanner.install(file1);
aclScanner.uninstall(file1);
EasyMock.verify(aclDb);
}
use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.
the class AclScannerTest method testCorrectFileUpdate.
@Test
public void testCorrectFileUpdate() throws Exception {
File file = new File(AclScannerTest.class.getResource("/xacml_correct.xml").toURI());
ManagedAcl acl = new ManagedAclImpl(1L, "TestAcl", "org", new AccessControlList());
Option<ManagedAcl> managedAcl = Option.some(acl);
EasyMock.expect(aclDb.createAcl(anyObject(Organization.class), anyObject(AccessControlList.class), anyString())).andReturn(managedAcl).times(3);
EasyMock.expect(aclDb.getAcl(anyObject(Organization.class), anyLong())).andReturn(managedAcl).times(3);
EasyMock.expect(aclDb.updateAcl(anyObject(ManagedAcl.class))).andReturn(true).times(3);
EasyMock.expect(aclDb.getAcls(anyObject(Organization.class))).andReturn(new ArrayList<ManagedAcl>()).times(3);
EasyMock.replay(aclDb);
aclScanner.install(file);
aclScanner.update(file);
EasyMock.verify(aclDb);
}
Aggregations