Search in sources :

Example 36 with AccessControlList

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

the class SeriesServiceImpl method repopulate.

@Override
public void repopulate(final String indexName) {
    final String destinationId = SeriesItem.SERIES_QUEUE_PREFIX + indexName.substring(0, 1).toUpperCase() + indexName.substring(1);
    try {
        final int total = persistence.countSeries();
        logger.info("Re-populating '{}' index with series. There are {} series to add to the index.", indexName, total);
        final int responseInterval = (total < 100) ? 1 : (total / 100);
        List<SeriesEntity> databaseSeries = persistence.getAllSeries();
        int current = 1;
        for (SeriesEntity series : databaseSeries) {
            Organization organization = orgDirectory.getOrganization(series.getOrganization());
            SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Function0.X<Void>() {

                @Override
                public Void xapply() throws Exception {
                    String id = series.getSeriesId();
                    logger.trace("Adding series '{}' for org '{}'", id, series.getOrganization());
                    DublinCoreCatalog catalog = DublinCoreXmlFormat.read(series.getDublinCoreXML());
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateCatalog(catalog));
                    AccessControlList acl = AccessControlParser.parseAcl(series.getAccessControl());
                    if (acl != null) {
                        messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateAcl(id, acl));
                    }
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateOptOut(id, series.isOptOut()));
                    for (Entry<String, String> property : persistence.getSeriesProperties(id).entrySet()) {
                        messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateProperty(id, property.getKey(), property.getValue()));
                    }
                    return null;
                }
            });
            if ((current % responseInterval == 0) || (current == total)) {
                logger.info("Initializing {} series index rebuild {}/{}: {} percent", indexName, current, total, current * 100 / total);
            }
            current++;
        }
        logger.info("Finished initializing '{}' index rebuild", indexName);
    } catch (Exception e) {
        logger.warn("Unable to index series instances:", e);
        throw new ServiceException(e.getMessage());
    }
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Series));
        }
    });
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) SeriesEntity(org.opencastproject.series.impl.persistence.SeriesEntity) Function0(org.opencastproject.util.data.Function0) ServiceException(org.osgi.framework.ServiceException) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) FunctionException(org.opencastproject.util.data.FunctionException) Entry(java.util.Map.Entry) ServiceException(org.osgi.framework.ServiceException) Effect0(org.opencastproject.util.data.Effect0) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 37 with AccessControlList

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

the class EventsLoader method getBasicMediaPackage.

private MediaPackage getBasicMediaPackage(EventEntry event) throws Exception {
    URL baseMediapackageUrl = EventsLoader.class.getResource("/base_mediapackage.xml");
    MediaPackage mediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(baseMediapackageUrl));
    DublinCoreCatalog episodeDublinCore = getBasicEpisodeDublinCore(event);
    mediaPackage.setDate(event.getRecordingDate());
    mediaPackage.setIdentifier(new IdImpl(episodeDublinCore.getFirst(DublinCoreCatalog.PROPERTY_IDENTIFIER)));
    mediaPackage.setTitle(event.getTitle());
    addDublinCoreCatalog(IOUtils.toInputStream(episodeDublinCore.toXmlString(), "UTF-8"), MediaPackageElements.EPISODE, mediaPackage);
    // assign to a series
    if (event.getSeries().isSome()) {
        DublinCoreCatalog seriesCatalog = seriesService.getSeries(event.getSeries().get());
        mediaPackage.setSeries(event.getSeries().get());
        mediaPackage.setSeriesTitle(seriesCatalog.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
        addDublinCoreCatalog(IOUtils.toInputStream(seriesCatalog.toXmlString(), "UTF-8"), MediaPackageElements.SERIES, mediaPackage);
        AccessControlList acl = seriesService.getSeriesAccessControl(event.getSeries().get());
        if (acl != null) {
            authorizationService.setAcl(mediaPackage, AclScope.Series, acl);
        }
    }
    // Set track URI's to demo file
    for (Track track : mediaPackage.getTracks()) {
        InputStream in = null;
        try {
            in = getClass().getResourceAsStream("/av.mov");
            URI uri = workspace.put(mediaPackage.getIdentifier().compact(), track.getIdentifier(), FilenameUtils.getName(track.toString()), in);
            track.setURI(uri);
            track.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, getClass().getResourceAsStream("/av.mov")));
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    return mediaPackage;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) URI(java.net.URI) URL(java.net.URL) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Track(org.opencastproject.mediapackage.Track)

Example 38 with AccessControlList

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

the class AclEndpoint method createAcl.

@POST
@Path("")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "createacl", description = "Create an ACL", returnDescription = "Create an ACL", restParameters = { @RestParameter(name = "name", isRequired = true, description = "The ACL name", type = STRING), @RestParameter(name = "acl", isRequired = true, description = "The access control list", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has successfully been added"), @RestResponse(responseCode = SC_CONFLICT, description = "An ACL with the same name already exists"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the ACL") })
public Response createAcl(@FormParam("name") String name, @FormParam("acl") String accessControlList) {
    final AccessControlList acl = parseAcl.apply(accessControlList);
    final Opt<ManagedAcl> managedAcl = aclService().createAcl(acl, name).toOpt();
    if (managedAcl.isNone()) {
        logger.info("An ACL with the same name '{}' already exists", name);
        throw new WebApplicationException(Response.Status.CONFLICT);
    }
    return RestUtils.okJson(full(managedAcl.get()));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) WebApplicationException(javax.ws.rs.WebApplicationException) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 39 with AccessControlList

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

the class AssetManagerWithSecurity method isAuthorizedByAcl.

private boolean isAuthorizedByAcl(Version version, String mpId, String action) {
    Opt<Asset> secAsset = super.getAsset(version, mpId, "security-policy-episode");
    if (secAsset.isSome()) {
        InputStream in = secAsset.get().getInputStream();
        final AccessControlList acl = authSvc.getAclFromInputStream(in).getA();
        return isAuthorizedByAcl(acl, action);
    }
    return false;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) InputStream(java.io.InputStream) Asset(org.opencastproject.assetmanager.api.Asset)

Example 40 with AccessControlList

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

the class SeriesEndpoint method applyAclToSeries.

@POST
@Path("/{seriesId}/access")
@RestQuery(name = "applyAclToSeries", description = "Immediate application of an ACL to a series", returnDescription = "Status code", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series ID", type = STRING) }, restParameters = { @RestParameter(name = "acl", isRequired = true, description = "The ACL to apply", type = STRING), @RestParameter(name = "override", isRequired = false, defaultValue = "false", description = "If true the series ACL will take precedence over any existing episode ACL", type = BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the given ACL"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series has not been found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToSeries(@PathParam("seriesId") String seriesId, @FormParam("acl") String acl, @DefaultValue("false") @FormParam("override") boolean override) throws SearchIndexException {
    AccessControlList accessControlList;
    try {
        accessControlList = AccessControlParser.parseAcl(acl);
    } catch (Exception e) {
        logger.warn("Unable to parse ACL '{}'", acl);
        return badRequest();
    }
    Opt<Series> series = indexService.getSeries(seriesId, searchIndex);
    if (series.isNone())
        return notFound("Cannot find a series with id {}", seriesId);
    if (hasProcessingEvents(seriesId)) {
        logger.warn("Can not update the ACL from series {}. Events being part of the series are currently processed.", seriesId);
        return conflict();
    }
    try {
        if (getAclService().applyAclToSeries(seriesId, accessControlList, override, Option.none()))
            return ok();
        else {
            logger.warn("Unable to find series '{}' to apply the ACL.", seriesId);
            return notFound();
        }
    } catch (AclServiceException e) {
        logger.error("Error applying acl to series {}", seriesId);
        return serverError();
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Series(org.opencastproject.index.service.impl.index.series.Series) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SeriesException(org.opencastproject.series.api.SeriesException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

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