Search in sources :

Example 11 with AccessControlList

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

the class AccessInformationUtilTest method testSerializePrivilegesByRole.

/**
 * Test method for {@link AccessInformationUtil#serializePrivilegesByRole(AccessControlList)}
 */
@Test
public void testSerializePrivilegesByRole() throws Exception {
    AccessControlList acl = new AccessControlList();
    acl.getEntries().add(ACE_ROLE_ADMIN_ALLOW_ACTION_READ);
    acl.getEntries().add(ACE_ROLE_ADMIN_ALLOW_ACTION_WRITE);
    acl.getEntries().add(ACE_ROLE_STUDENT_ALLOW_ACTION_READ);
    acl.getEntries().add(ACE_ROLE_STUDENT_DISALLOW_ACTION_WRITE);
    JSONObject privilegesByRole = AccessInformationUtil.serializePrivilegesByRole(acl);
    assertTrue(privilegesByRole.getJSONObject(ROLE_ADMIN).getBoolean(ACTION_READ));
    assertTrue(privilegesByRole.getJSONObject(ROLE_ADMIN).getBoolean(ACTION_WRITE));
    assertTrue(privilegesByRole.getJSONObject(ROLE_STUDENT).getBoolean(ACTION_READ));
    assertFalse(privilegesByRole.getJSONObject(ROLE_STUDENT).getBoolean(ACTION_WRITE));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) JSONObject(org.codehaus.jettison.json.JSONObject) Test(org.junit.Test)

Example 12 with AccessControlList

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

the class IngestServiceImpl method setPublicAclIfEmpty.

private void setPublicAclIfEmpty(MediaPackage mp) {
    AccessControlList activeAcl = authorizationService.getActiveAcl(mp).getA();
    if (activeAcl.getEntries().size() == 0) {
        String anonymousRole = securityService.getOrganization().getAnonymousRole();
        activeAcl = new AccessControlList(new AccessControlEntry(anonymousRole, Permissions.Action.READ.toString(), true));
        authorizationService.setAcl(mp, AclScope.Series, activeAcl);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry)

Example 13 with AccessControlList

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

the class IngestServiceImpl method updateSeries.

/**
 * Updates the persistent representation of a series based on a potentially modified dublin core document.
 *
 * @param uri
 *          the URI to the dublin core document containing series metadata.
 * @return
 *         true, if the series is created or overwritten, false if the existing series remains intact.
 */
protected boolean updateSeries(URI uri) throws IOException, IngestException {
    HttpResponse response = null;
    InputStream in = null;
    boolean isUpdated = false;
    try {
        HttpGet getDc = new HttpGet(uri);
        response = httpClient.execute(getDc);
        in = response.getEntity().getContent();
        DublinCoreCatalog dc = dublinCoreService.load(in);
        String id = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
        if (id == null) {
            logger.warn("Series dublin core document contains no identifier, rejecting ingested series cagtalog.");
        } else {
            try {
                try {
                    seriesService.getSeries(id);
                    if (isOverwriteSeries) {
                        // Update existing series
                        seriesService.updateSeries(dc);
                        isUpdated = true;
                        logger.debug("Ingest is overwriting the existing series {} with the ingested series", id);
                    } else {
                        logger.debug("Series {} already exists. Ignoring series catalog from ingest.", id);
                    }
                } catch (NotFoundException e) {
                    logger.info("Creating new series {} with default ACL", id);
                    seriesService.updateSeries(dc);
                    isUpdated = true;
                    String anonymousRole = securityService.getOrganization().getAnonymousRole();
                    AccessControlList acl = new AccessControlList(new AccessControlEntry(anonymousRole, "read", true));
                    seriesService.updateAccessControl(id, acl);
                }
            } catch (Exception e) {
                throw new IngestException(e);
            }
        }
        in.close();
    } catch (IOException e) {
        logger.error("Error updating series from DublinCoreCatalog: {}", e.getMessage());
    } finally {
        IOUtils.closeQuietly(in);
        httpClient.close(response);
    }
    return isUpdated;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ProgressInputStream(org.opencastproject.util.ProgressInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) IngestException(org.opencastproject.ingest.api.IngestException) HandleException(org.opencastproject.mediapackage.identifier.HandleException) ConfigurationException(org.opencastproject.util.ConfigurationException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException)

Example 14 with AccessControlList

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

the class AssetManagerMessageReceiverImplTest method testUpdateCreator.

@Test
public void testUpdateCreator() throws Exception {
    MediaPackage mediaPackage = new MediaPackageBuilderImpl().loadFromXml(getClass().getResourceAsStream("/jobs_mediapackage1.xml"));
    TakeSnapshot takeSnapshot = AssetManagerItem.add(workspace, mediaPackage, new AccessControlList(), 0, new Date());
    // Test initial set of creator
    assetManager.execute(takeSnapshot);
    Event event = index.getEventResult();
    assertNotNull(event);
    assertEquals("Current user is expected to be creator as no other creator has been set explicitly", "Creator", event.getCreator());
    // Test updating creator
    event.setCreator("Hans");
    index.setInitialEvent(event);
    assetManager.execute(takeSnapshot);
    event = index.getEventResult();
    assertNotNull(event);
    assertEquals("Creator has been updated", "Hans", event.getCreator());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) TakeSnapshot(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.TakeSnapshot) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) Date(java.util.Date) Test(org.junit.Test)

Example 15 with AccessControlList

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

the class IngestServiceImplTest method setUp.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
    FileUtils.forceMkdir(ingestTempDir);
    // set up service and mock workspace
    wfr = EasyMock.createNiceMock(WorkingFileRepository.class);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlAttachment);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
    EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackage);
    EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackageOld);
    workflowInstance = EasyMock.createNiceMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getId()).andReturn(workflowInstanceID);
    EasyMock.expect(workflowInstance.getState()).andReturn(WorkflowState.STOPPED);
    final Capture<MediaPackage> mp = EasyMock.newCapture();
    workflowService = EasyMock.createNiceMock(WorkflowService.class);
    EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), EasyMock.capture(mp), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
    EasyMock.expect(workflowInstance.getMediaPackage()).andAnswer(new IAnswer<MediaPackage>() {

        @Override
        public MediaPackage answer() throws Throwable {
            return mp.getValue();
        }
    });
    EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject(), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
    EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(workflowInstance);
    EasyMock.expect(workflowService.getWorkflowDefinitionById((String) EasyMock.anyObject())).andReturn(new WorkflowDefinitionImpl());
    EasyMock.expect(workflowService.getWorkflowById(EasyMock.anyLong())).andReturn(workflowInstance);
    SchedulerService schedulerService = EasyMock.createNiceMock(SchedulerService.class);
    Map<String, String> properties = new HashMap<>();
    properties.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, "sample");
    properties.put("agent-name", "matterhorn-agent");
    EasyMock.expect(schedulerService.getCaptureAgentConfiguration(EasyMock.anyString())).andReturn(properties).anyTimes();
    EasyMock.expect(schedulerService.getDublinCore(EasyMock.anyString())).andReturn(DublinCores.read(urlCatalog1.toURL().openStream())).anyTimes();
    MediaPackage schedulerMediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/source-manifest.xml"), "UTF-8"));
    EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(schedulerMediaPackage).anyTimes();
    EasyMock.replay(wfr, workflowInstance, workflowService, schedulerService);
    User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization(), "test"));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    EasyMock.replay(userDirectoryService);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    HttpEntity entity = EasyMock.createMock(HttpEntity.class);
    InputStream is = getClass().getResourceAsStream("/av.mov");
    byte[] movie = IOUtils.toByteArray(is);
    IOUtils.closeQuietly(is);
    EasyMock.expect(entity.getContent()).andReturn(new ByteArrayInputStream(movie)).anyTimes();
    EasyMock.replay(entity);
    StatusLine statusLine = EasyMock.createMock(StatusLine.class);
    EasyMock.expect(statusLine.getStatusCode()).andReturn(200).anyTimes();
    EasyMock.replay(statusLine);
    Header contentDispositionHeader = EasyMock.createMock(Header.class);
    EasyMock.expect(contentDispositionHeader.getValue()).andReturn("attachment; filename=fname.mp4").anyTimes();
    EasyMock.replay(contentDispositionHeader);
    HttpResponse httpResponse = EasyMock.createMock(HttpResponse.class);
    EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLine).anyTimes();
    EasyMock.expect(httpResponse.getFirstHeader("Content-Disposition")).andReturn(contentDispositionHeader).anyTimes();
    EasyMock.expect(httpResponse.getEntity()).andReturn(entity).anyTimes();
    EasyMock.replay(httpResponse);
    TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
    EasyMock.expect(httpClient.execute((HttpGet) EasyMock.anyObject())).andReturn(httpResponse).anyTimes();
    EasyMock.replay(httpClient);
    AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(new AccessControlList(), AclScope.Series)).anyTimes();
    EasyMock.replay(authorizationService);
    MediaInspectionService mediaInspectionService = EasyMock.createNiceMock(MediaInspectionService.class);
    EasyMock.expect(mediaInspectionService.enrich(EasyMock.anyObject(MediaPackageElement.class), EasyMock.anyBoolean())).andAnswer(new IAnswer<Job>() {

        private int i = 0;

        @Override
        public Job answer() throws Throwable {
            TrackImpl element = (TrackImpl) EasyMock.getCurrentArguments()[0];
            element.setDuration(20000L);
            if (i % 2 == 0) {
                element.addStream(new VideoStreamImpl());
            } else {
                element.addStream(new AudioStreamImpl());
            }
            i++;
            JobImpl succeededJob = new JobImpl();
            succeededJob.setStatus(Status.FINISHED);
            succeededJob.setPayload(MediaPackageElementParser.getAsXml(element));
            return succeededJob;
        }
    }).anyTimes();
    EasyMock.replay(mediaInspectionService);
    service = new IngestServiceImpl();
    service.setHttpClient(httpClient);
    service.setAuthorizationService(authorizationService);
    service.setWorkingFileRepository(wfr);
    service.setWorkflowService(workflowService);
    service.setSecurityService(securityService);
    service.setSchedulerService(schedulerService);
    service.setMediaInspectionService(mediaInspectionService);
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    serviceRegistry.registerService(service);
    service.setServiceRegistry(serviceRegistry);
    service.defaultWorkflowDefinionId = "sample";
    serviceRegistry.registerService(service);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SchedulerService(org.opencastproject.scheduler.api.SchedulerService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) HttpGet(org.apache.http.client.methods.HttpGet) AudioStreamImpl(org.opencastproject.mediapackage.track.AudioStreamImpl) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaInspectionService(org.opencastproject.inspection.api.MediaInspectionService) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowService(org.opencastproject.workflow.api.WorkflowService) SecurityService(org.opencastproject.security.api.SecurityService) WorkingFileRepository(org.opencastproject.workingfilerepository.api.WorkingFileRepository) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) JobImpl(org.opencastproject.job.api.JobImpl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpResponse(org.apache.http.HttpResponse) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StatusLine(org.apache.http.StatusLine) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) Header(org.apache.http.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

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