Search in sources :

Example 56 with AccessControlList

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;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SeriesService(org.opencastproject.series.api.SeriesService) NotFoundException(org.opencastproject.util.NotFoundException) NotFoundException(org.opencastproject.util.NotFoundException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException)

Example 57 with AccessControlList

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());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ManagedAclImpl(org.opencastproject.authorization.xacml.manager.impl.ManagedAclImpl) Test(org.junit.Test)

Example 58 with AccessControlList

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 59 with AccessControlList

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) EasyMock.anyLong(org.easymock.EasyMock.anyLong) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ArrayList(java.util.ArrayList) EasyMock.anyString(org.easymock.EasyMock.anyString) File(java.io.File) Test(org.junit.Test)

Example 60 with AccessControlList

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Aggregations

AccessControlList (org.opencastproject.security.api.AccessControlList)108 NotFoundException (org.opencastproject.util.NotFoundException)46 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)38 AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)30 MediaPackage (org.opencastproject.mediapackage.MediaPackage)27 Test (org.junit.Test)26 IOException (java.io.IOException)22 Organization (org.opencastproject.security.api.Organization)22 User (org.opencastproject.security.api.User)21 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)19 ArrayList (java.util.ArrayList)18 SeriesException (org.opencastproject.series.api.SeriesException)18 ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)16 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)16 Date (java.util.Date)15 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)14 Path (javax.ws.rs.Path)13 RestQuery (org.opencastproject.util.doc.rest.RestQuery)13 WebApplicationException (javax.ws.rs.WebApplicationException)12 File (java.io.File)10