use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerMigrationService method schedule.
void schedule(SchedulerTransaction tx, Event event) {
final Map<String, String> wfProperties = Collections.emptyMap();
final Map<String, String> caMetadata = PropertiesUtil.toMap(event.captureAgentProperites);
final MediaPackage mp = mkMediaPackage();
mp.setIdentifier(new IdImpl(event.mediaPackageId));
// create the catalog
final DublinCoreCatalog dc = event.dublinCore;
mp.setSeries(dc.getFirst(DublinCore.PROPERTY_IS_PART_OF));
// and make them available for download in the workspace
dc.setURI(storeInWs(event.mediaPackageId, dc.getIdentifier(), "dc-episode.xml", inputStream(dc)));
// add them to the media package
mp.add(dc);
// add acl to the media package
for (AccessControlList acl : event.accessControlList) {
authorizationService.setAcl(mp, AclScope.Episode, acl);
}
//
// add to scheduler service
Tuple<Date, Date> schedulingDate = getSchedulingDate(dc);
String caId = dc.getFirst(DublinCore.PROPERTY_SPATIAL);
try {
tx.addEvent(schedulingDate.getA(), schedulingDate.getB(), caId, Collections.<String>emptySet(), mp, wfProperties, caMetadata, Opt.some(event.optOut));
} catch (UnauthorizedException e) {
logger.error("Not authorized to schedule an event", e);
chuck(e);
} catch (SchedulerException e) {
logger.warn("Not able to schedule event.", e);
chuck(e);
} catch (NotFoundException e) {
logger.error("Transaction disappeared");
chuck(e);
}
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class ThemeWorkflowOperationHandler method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
* JobContext)
*/
@Override
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
logger.debug("Running theme workflow operation on workflow {}", workflowInstance.getId());
final MediaPackageElementFlavor bumperFlavor = getOptConfig(workflowInstance, BUMPER_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "bumper"));
final MediaPackageElementFlavor trailerFlavor = getOptConfig(workflowInstance, TRAILER_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "trailer"));
final MediaPackageElementFlavor titleSlideFlavor = getOptConfig(workflowInstance, TITLE_SLIDE_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "title-slide"));
final MediaPackageElementFlavor licenseSlideFlavor = getOptConfig(workflowInstance, LICENSE_SLIDE_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "license-slide"));
final MediaPackageElementFlavor watermarkFlavor = getOptConfig(workflowInstance, WATERMARK_FLAVOR).map(toMediaPackageElementFlavor).getOr(new MediaPackageElementFlavor("branding", "watermark"));
final List<String> bumperTags = asList(workflowInstance.getConfiguration(BUMPER_TAGS));
final List<String> trailerTags = asList(workflowInstance.getConfiguration(TRAILER_TAGS));
final List<String> titleSlideTags = asList(workflowInstance.getConfiguration(TITLE_SLIDE_TAGS));
final List<String> licenseSlideTags = asList(workflowInstance.getConfiguration(LICENSE_SLIDE_TAGS));
final List<String> watermarkTags = asList(workflowInstance.getConfiguration(WATERMARK_TAGS));
Opt<String> layoutStringOpt = getOptConfig(workflowInstance, WATERMARK_LAYOUT);
Opt<String> watermarkLayoutVariable = getOptConfig(workflowInstance, WATERMARK_LAYOUT_VARIABLE);
List<String> layoutList = new ArrayList<>(Stream.$(layoutStringOpt).bind(Strings.split(";")).toList());
try {
MediaPackage mediaPackage = workflowInstance.getMediaPackage();
String series = mediaPackage.getSeries();
if (series == null) {
logger.info("Skipping theme workflow operation, no series assigned to mediapackage {}", mediaPackage.getIdentifier());
return createResult(Action.SKIP);
}
Long themeId;
try {
themeId = Long.parseLong(seriesService.getSeriesProperty(series, THEME_PROPERTY_NAME));
} catch (NotFoundException e) {
logger.info("Skipping theme workflow operation, no theme assigned to series {} on mediapackage {}.", series, mediaPackage.getIdentifier());
return createResult(Action.SKIP);
} catch (UnauthorizedException e) {
logger.warn("Skipping theme workflow operation, user not authorized to perform operation: {}", ExceptionUtils.getStackTrace(e));
return createResult(Action.SKIP);
}
Theme theme;
try {
theme = themesServiceDatabase.getTheme(themeId);
} catch (NotFoundException e) {
logger.warn("Skipping theme workflow operation, no theme with id {} found.", themeId);
return createResult(Action.SKIP);
}
logger.info("Applying theme {} to mediapackage {}", themeId, mediaPackage.getIdentifier());
/* Make theme settings available to workflow instance */
workflowInstance.setConfiguration(THEME_ACTIVE, Boolean.toString(theme.isBumperActive() || theme.isTrailerActive() || theme.isTitleSlideActive() || theme.isWatermarkActive()));
workflowInstance.setConfiguration(THEME_BUMPER_ACTIVE, Boolean.toString(theme.isBumperActive()));
workflowInstance.setConfiguration(THEME_TRAILER_ACTIVE, Boolean.toString(theme.isTrailerActive()));
workflowInstance.setConfiguration(THEME_TITLE_SLIDE_ACTIVE, Boolean.toString(theme.isTitleSlideActive()));
workflowInstance.setConfiguration(THEME_TITLE_SLIDE_UPLOADED, Boolean.toString(StringUtils.isNotBlank(theme.getTitleSlideBackground())));
workflowInstance.setConfiguration(THEME_WATERMARK_ACTIVE, Boolean.toString(theme.isWatermarkActive()));
if (theme.isBumperActive() && StringUtils.isNotBlank(theme.getBumperFile())) {
try (InputStream bumper = staticFileService.getFile(theme.getBumperFile())) {
addElement(mediaPackage, bumperFlavor, bumperTags, bumper, staticFileService.getFileName(theme.getBumperFile()), Type.Track);
} catch (NotFoundException e) {
logger.warn("Bumper file {} not found in static file service, skip applying it", theme.getBumperFile());
}
}
if (theme.isTrailerActive() && StringUtils.isNotBlank(theme.getTrailerFile())) {
try (InputStream trailer = staticFileService.getFile(theme.getTrailerFile())) {
addElement(mediaPackage, trailerFlavor, trailerTags, trailer, staticFileService.getFileName(theme.getTrailerFile()), Type.Track);
} catch (NotFoundException e) {
logger.warn("Trailer file {} not found in static file service, skip applying it", theme.getTrailerFile());
}
}
if (theme.isTitleSlideActive()) {
if (StringUtils.isNotBlank(theme.getTitleSlideBackground())) {
try (InputStream titleSlideBackground = staticFileService.getFile(theme.getTitleSlideBackground())) {
addElement(mediaPackage, titleSlideFlavor, titleSlideTags, titleSlideBackground, staticFileService.getFileName(theme.getTitleSlideBackground()), Type.Attachment);
} catch (NotFoundException e) {
logger.warn("Title slide file {} not found in static file service, skip applying it", theme.getTitleSlideBackground());
}
}
// TODO add the title slide metadata to the workflow properties to be used by the cover-image WOH
// String titleSlideMetadata = theme.getTitleSlideMetadata();
}
if (theme.isLicenseSlideActive()) {
if (StringUtils.isNotBlank(theme.getLicenseSlideBackground())) {
try (InputStream licenseSlideBackground = staticFileService.getFile(theme.getLicenseSlideBackground())) {
addElement(mediaPackage, licenseSlideFlavor, licenseSlideTags, licenseSlideBackground, staticFileService.getFileName(theme.getLicenseSlideBackground()), Type.Attachment);
} catch (NotFoundException e) {
logger.warn("License slide file {} not found in static file service, skip applying it", theme.getLicenseSlideBackground());
}
} else {
// TODO define what to do here (maybe extract image as background)
}
// TODO add the license slide description to the workflow properties to be used by the cover-image WOH
// String licenseSlideDescription = theme.getLicenseSlideDescription();
}
if (theme.isWatermarkActive() && StringUtils.isNotBlank(theme.getWatermarkFile())) {
try (InputStream watermark = staticFileService.getFile(theme.getWatermarkFile())) {
addElement(mediaPackage, watermarkFlavor, watermarkTags, watermark, staticFileService.getFileName(theme.getWatermarkFile()), Type.Attachment);
} catch (NotFoundException e) {
logger.warn("Watermark file {} not found in static file service, skip applying it", theme.getWatermarkFile());
}
if (layoutStringOpt.isNone() || watermarkLayoutVariable.isNone())
throw new WorkflowOperationException(format("Configuration key '%s' or '%s' is either missing or empty", WATERMARK_LAYOUT, WATERMARK_LAYOUT_VARIABLE));
AbsolutePositionLayoutSpec watermarkLayout = parseLayout(theme.getWatermarkPosition());
layoutList.set(layoutList.size() - 1, Serializer.json(watermarkLayout).toJson());
layoutStringOpt = Opt.some(Stream.$(layoutList).mkString(";"));
}
if (watermarkLayoutVariable.isSome() && layoutStringOpt.isSome())
workflowInstance.setConfiguration(watermarkLayoutVariable.get(), layoutStringOpt.get());
return createResult(mediaPackage, Action.CONTINUE);
} catch (SeriesException | ThemesServiceDatabaseException | IllegalStateException | IllegalArgumentException | IOException e) {
throw new WorkflowOperationException(e);
}
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceImpl method cleanupTransactions.
@Override
public synchronized void cleanupTransactions() throws UnauthorizedException, SchedulerException {
logger.info("Cleanup transactions | start");
List<String> transactions;
try {
transactions = persistence.getTransactions();
} catch (SchedulerServiceDatabaseException e) {
logger.error("Unable to get transactions: {}", getStackTrace(e));
throw new SchedulerException(e);
}
logger.info("Cleanup transaction | checking {} transactions...", transactions.size());
for (String trxId : transactions) {
try {
Date lastModified = persistence.getTransactionLastModified(trxId);
if (lastModified.getTime() + transactionOffsetMillis < new Date().getTime()) {
logger.info("Cleanup transactions | rollback outdated transaction {}", trxId);
SchedulerTransaction t = getTransaction(trxId);
t.rollback();
} else {
logger.info("Cleanup transactions | nothing to do");
}
} catch (NotFoundException e) {
logger.info("Cleanup transaction | transaction '{}' has been removed in the meantime.", trxId);
} catch (Exception e) {
logger.warn("Cleanup transaction | unable to cleanup transaction with id '{}': {}", trxId, getStackTrace(e));
}
}
logger.info("Cleanup transactions | end");
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceImpl method removeEvent.
@Override
public synchronized void removeEvent(String mediaPackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
notEmpty(mediaPackageId, "mediaPackageId");
try {
// Check if there are properties only from scheduler
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
AResult result = query.select(p.agent().target(), p.source().target()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId)).and(query.version().isLatest()).and(query.hasPropertiesOf(p.namespace()))).run();
Opt<ARecord> recordOpt = result.getRecords().head();
long deletedProperties = 0;
if (recordOpt.isSome()) {
// Check for locked transactions
Opt<String> source = recordOpt.get().getProperties().apply(Properties.getStringOpt(SOURCE_CONFIG));
if (source.isSome() && persistence.hasTransaction(source.get())) {
logger.warn("Unable to remove event '{}', source '{}' is currently locked due to an active transaction!", mediaPackageId, source.get());
throw new SchedulerTransactionLockException("Unable to remove event, locked source " + source.get());
}
String agentId = recordOpt.get().getProperties().apply(Properties.getString(AGENT_CONFIG));
// Delete all properties
deletedProperties = query.delete(SNAPSHOT_OWNER, query.propertiesOf(p.namespace(), WORKFLOW_NAMESPACE, CA_NAMESPACE)).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId))).name("delete all properties").run();
if (StringUtils.isNotEmpty(agentId))
touchLastEntry(agentId);
}
// Delete scheduler snapshot
long deletedSnapshots = query.delete(SNAPSHOT_OWNER, query.snapshot()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId))).name("delete episode").run();
if (deletedProperties + deletedSnapshots == 0)
throw new NotFoundException();
messageSender.sendObjectMessage(SchedulerItem.SCHEDULER_QUEUE, MessageSender.DestinationType.Queue, SchedulerItem.delete(mediaPackageId));
} catch (NotFoundException | SchedulerException e) {
throw e;
} catch (Exception e) {
logger.error("Could not remove event '{}' from persistent storage: {}", mediaPackageId, e);
throw new SchedulerException(e);
}
}
use of org.opencastproject.security.api.UnauthorizedException in project opencast by opencast.
the class SchedulerServiceImpl method hasActiveTransaction.
@Override
public boolean hasActiveTransaction(String mediaPackageId) throws NotFoundException, UnauthorizedException, SchedulerException {
notEmpty(mediaPackageId, "mediaPackageId");
try {
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
TrxProps trxP = new TrxProps(query);
AResult result = query.select(p.source().target(), trxP.source().target()).where(withOrganization(query).and(query.mediaPackageId(mediaPackageId)).and(query.version().isLatest())).run();
Opt<ARecord> record = result.getRecords().head();
if (record.isNone())
throw new NotFoundException();
// Check for active transactions
Opt<String> source = record.get().getProperties().apply(Properties.getStringOpt(SOURCE_CONFIG));
if (source.isSome() && persistence.hasTransaction(source.get()))
return true;
return false;
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Failed to check for active transaction of event with mediapackage '{}': {}", mediaPackageId, getStackTrace(e));
throw new SchedulerException(e);
}
}
Aggregations