Search in sources :

Example 6 with AccessControlList

use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.

the class AclScannerTest method testRemoveMissingFile.

@Test
public void testRemoveMissingFile() throws Exception {
    File file1 = new File(AclScannerTest.class.getResource("/xacml_correct.xml").toURI());
    File file2 = new File(AclScannerTest.class.getResource("/xacml_correct2.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(file1);
    aclScanner.uninstall(file2);
    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 7 with AccessControlList

use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.

the class AclScannerTest method testMissingFileUpdate.

@Test
public void testMissingFileUpdate() throws Exception {
    File file1 = new File(AclScannerTest.class.getResource("/xacml_correct.xml").toURI());
    File file2 = new File(AclScannerTest.class.getResource("/xacml_correct2.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(file1);
    aclScanner.update(file2);
    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 8 with AccessControlList

use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.

the class XACMLAuthorizationService method getDefaultAcl.

private Tuple<AccessControlList, AclScope> getDefaultAcl(final MediaPackage mp) {
    logger.debug("Get default ACL for media package {}", mp.getIdentifier());
    if (StringUtils.isNotBlank(mp.getSeries())) {
        logger.debug("Falling back to acl from series {} for media package {}", mp.getSeries(), mp.getIdentifier());
        try {
            return tuple(seriesService.getSeriesAccessControl(mp.getSeries()), AclScope.Series);
        } catch (Exception e) {
            logger.debug("Unable to get acl from series '{}'", mp.getSeries());
        }
    }
    logger.trace("Falling back to global default acl for media package '{}'", mp.getIdentifier());
    return tuple(new AccessControlList(), AclScope.Global);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) URISyntaxException(java.net.URISyntaxException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) JAXBException(javax.xml.bind.JAXBException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException)

Example 9 with AccessControlList

use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.

the class AssetManagerItemTest method testSerializeUpdate.

@Test
public void testSerializeUpdate() throws Exception {
    final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(new File(getClass().getResource("/dublincore-a.xml").toURI())).once();
    EasyMock.expect(workspace.read(EasyMock.anyObject(URI.class))).andAnswer(() -> getClass().getResourceAsStream("/dublincore-a.xml")).once();
    EasyMock.replay(workspace);
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.add(DublinCores.mkOpencastEpisode().getCatalog());
    final AccessControlList acl = new AccessControlList(new AccessControlEntry("admin", "read", true));
    final Date now = new Date();
    final AssetManagerItem item = AssetManagerItem.add(workspace, mp, acl, 10L, now);
    final AssetManagerItem deserialized = IoSupport.serializeDeserialize(item);
    assertEquals(item.getDate(), deserialized.getDate());
    assertEquals(item.getType(), deserialized.getType());
    assertEquals(item.decompose(TakeSnapshot.getMediaPackage, null, null).getIdentifier(), deserialized.decompose(TakeSnapshot.getMediaPackage, null, null).getIdentifier());
    assertEquals(item.decompose(TakeSnapshot.getAcl, null, null).getEntries(), deserialized.decompose(TakeSnapshot.getAcl, null, null).getEntries());
    assertTrue(DublinCoreUtil.equals(item.decompose(TakeSnapshot.getEpisodeDublincore, null, null).get(), deserialized.decompose(TakeSnapshot.getEpisodeDublincore, null, null).get()));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AssetManagerItem(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) File(java.io.File) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 10 with AccessControlList

use of org.opencastproject.security.api.AccessControlList in project opencast by opencast.

the class AssetManagerWithSecurityTest method mkTestEnvironment.

/**
 * Setup the test environment.
 */
public AssetManagerWithSecurity mkTestEnvironment() throws Exception {
    final AuthorizationService authSvc = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authSvc.getActiveAcl(EasyMock.<MediaPackage>anyObject())).andAnswer(new IAnswer<Tuple<AccessControlList, AclScope>>() {

        @Override
        public Tuple<AccessControlList, AclScope> answer() throws Throwable {
            return tuple(currentMediaPackageAcl, AclScope.Episode);
        }
    }).anyTimes();
    EasyMock.replay(authSvc);
    // 
    secSvc = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(secSvc.getUser()).andAnswer(new IAnswer<User>() {

        @Override
        public User answer() throws Throwable {
            return currentUser;
        }
    }).anyTimes();
    EasyMock.expect(secSvc.getOrganization()).andAnswer(new IAnswer<Organization>() {

        @Override
        public Organization answer() throws Throwable {
            return currentUser.getOrganization();
        }
    }).anyTimes();
    EasyMock.replay(secSvc);
    // 
    return new AssetManagerWithSecurity(mkAbstractAssetManager(), authSvc, secSvc);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) IAnswer(org.easymock.IAnswer) AuthorizationService(org.opencastproject.security.api.AuthorizationService) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AclScope(org.opencastproject.security.api.AclScope)

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