use of org.opencastproject.security.util.SecurityContext in project opencast by opencast.
the class InboxScannerService method updated.
// synchronized with activate(ComponentContext)
@Override
public synchronized void updated(Dictionary properties) throws ConfigurationException {
// build scanner configuration
final String orgId = getCfg(properties, USER_ORG);
final String userId = getCfg(properties, USER_NAME);
final String mediaFlavor = getCfg(properties, MEDIA_FLAVOR);
final String workflowDefinition = getCfg(properties, WORKFLOW_DEFINITION);
final Map<String, String> workflowConfig = getCfgAsMap(properties, WORKFLOW_CONFIG);
final int interval = getCfgAsInt(properties, INBOX_POLL);
final File inbox = new File(getCfg(properties, INBOX_PATH));
if (!inbox.isDirectory()) {
try {
FileUtils.forceMkdir(inbox);
} catch (IOException e) {
throw new ConfigurationException(INBOX_PATH, String.format("%s does not exists and could not be created", inbox.getAbsolutePath()));
}
}
/* We need to be able to read from the inbox to get files from there */
if (!inbox.canRead()) {
throw new ConfigurationException(INBOX_PATH, String.format("Cannot read from %s", inbox.getAbsolutePath()));
}
/* We need to be able to write to the inbox to remove files after they have been ingested */
if (!inbox.canWrite()) {
throw new ConfigurationException(INBOX_PATH, String.format("Cannot write to %s", inbox.getAbsolutePath()));
}
final int maxthreads = option(cc.getBundleContext().getProperty("org.opencastproject.inbox.threads")).bind(Strings.toInt).getOrElse(1);
final Option<SecurityContext> secCtx = getUserAndOrganization(securityService, orgDir, orgId, userDir, userId).bind(new Function<Tuple<User, Organization>, Option<SecurityContext>>() {
@Override
public Option<SecurityContext> apply(Tuple<User, Organization> a) {
return some(new SecurityContext(securityService, a.getB(), a.getA()));
}
});
// Only setup new inbox if security context could be aquired
if (secCtx.isSome()) {
// remove old file install configuration
fileInstallCfg.foreach(removeFileInstallCfg);
// set up new file install config
fileInstallCfg = some(configureFileInstall(cc.getBundleContext(), inbox, interval));
// create new scanner
ingestor = some(new Ingestor(ingestService, workingFileRepository, secCtx.get(), workflowDefinition, workflowConfig, mediaFlavor, inbox, maxthreads));
logger.info("Now watching inbox {}", inbox.getAbsolutePath());
} else {
logger.warn("Cannot create security context for user {}, organization {}. " + "Either the organization or the user does not exist", userId, orgId);
}
}
use of org.opencastproject.security.util.SecurityContext in project opencast by opencast.
the class IndexEndpoint method recreateIndexFromService.
@POST
@Path("recreateIndex/{service}")
@RestQuery(name = "recreateIndexFromService", description = "Repopulates the Admin UI Index from an specific service", returnDescription = "OK if repopulation has started", pathParameters = { @RestParameter(name = "service", isRequired = true, description = "The service to recreate index from. " + "The available services are: Groups, Acl, Themes, Series, Scheduler, Workflow, AssetManager and Comments. " + "The service order (see above) is very important! Make sure, you do not run index rebuild for more than one " + "service at a time!", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "OK if repopulation has started", responseCode = HttpServletResponse.SC_OK) })
public Response recreateIndexFromService(@PathParam("service") final String service) {
final SecurityContext securityContext = new SecurityContext(securityService, securityService.getOrganization(), securityService.getUser());
executor.execute(new Runnable() {
@Override
public void run() {
securityContext.runInContext(new Effect0() {
@Override
protected void run() {
try {
logger.info("Starting to repopulate the index from service {}", service);
adminUISearchIndex.recreateIndex(service);
} catch (InterruptedException e) {
logger.error("Repopulating the index was interrupted", e);
} catch (CancellationException e) {
logger.trace("Listening for index messages has been cancelled.");
} catch (ExecutionException e) {
logger.error("Repopulating the index failed to execute", e);
} catch (Throwable t) {
logger.error("Repopulating the index failed", t);
}
}
});
}
});
return R.ok();
}
use of org.opencastproject.security.util.SecurityContext in project opencast by opencast.
the class BaseEndpoint method recreateIndex.
@POST
@Path("recreateIndex")
@RestQuery(name = "recreateIndex", description = "Repopulates the External Index directly from the Services", returnDescription = "OK if repopulation has started", reponses = { @RestResponse(description = "OK if repopulation has started", responseCode = HttpServletResponse.SC_OK) })
public Response recreateIndex() {
final SecurityContext securityContext = new SecurityContext(securityService, securityService.getOrganization(), securityService.getUser());
executor.execute(new Runnable() {
@Override
public void run() {
securityContext.runInContext(new Effect0() {
@Override
protected void run() {
try {
logger.info("Starting to repopulate the external index");
externalIndex.recreateIndex();
logger.info("Finished repopulating the external index");
} catch (InterruptedException e) {
logger.error("Repopulating the external index was interrupted {}", getStackTrace(e));
} catch (CancellationException e) {
logger.trace("Listening for external index messages has been cancelled.");
} catch (ExecutionException e) {
logger.error("Repopulating the external index failed to execute because {}", getStackTrace(e));
} catch (Throwable t) {
logger.error("Repopulating the external index failed because {}", getStackTrace(t));
}
}
});
}
});
return R.ok();
}
use of org.opencastproject.security.util.SecurityContext in project opencast by opencast.
the class IndexEndpoint method recreateIndex.
@POST
@Path("recreateIndex")
@RestQuery(name = "recreateIndex", description = "Clear and repopulates the Admin UI Index directly from the Services", returnDescription = "OK if repopulation has started", reponses = { @RestResponse(description = "OK if repopulation has started", responseCode = HttpServletResponse.SC_OK) })
public Response recreateIndex() {
final SecurityContext securityContext = new SecurityContext(securityService, securityService.getOrganization(), securityService.getUser());
executor.execute(new Runnable() {
@Override
public void run() {
securityContext.runInContext(new Effect0() {
@Override
protected void run() {
try {
logger.info("Starting to repopulate the index");
adminUISearchIndex.recreateIndex();
} catch (InterruptedException e) {
logger.error("Repopulating the index was interrupted", e);
} catch (CancellationException e) {
logger.trace("Listening for index messages has been cancelled.");
} catch (ExecutionException e) {
logger.error("Repopulating the index failed to execute", e);
} catch (Throwable t) {
logger.error("Repopulating the index failed", t);
}
}
});
}
});
return R.ok();
}
use of org.opencastproject.security.util.SecurityContext in project opencast by opencast.
the class BaseEndpoint method recreateIndexFromService.
@POST
@Path("recreateIndex/{service}")
@RestQuery(name = "recreateIndexFromService", description = "Repopulates the external Index from an specific service", returnDescription = "OK if repopulation has started", pathParameters = { @RestParameter(name = "service", isRequired = true, description = "The service to recreate index from. " + "The available services are: Groups, Acl, Themes, Series, Scheduler, Workflow, AssetManager and Comments. " + "The service order (see above) is very important! Make sure, you do not run index rebuild for more than one " + "service at a time!", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "OK if repopulation has started", responseCode = HttpServletResponse.SC_OK) })
public Response recreateIndexFromService(@PathParam("service") final String service) {
final SecurityContext securityContext = new SecurityContext(securityService, securityService.getOrganization(), securityService.getUser());
executor.execute(new Runnable() {
@Override
public void run() {
securityContext.runInContext(new Effect0() {
@Override
protected void run() {
try {
logger.info("Starting to repopulate the index from service {}", service);
externalIndex.recreateIndex(service);
} catch (InterruptedException e) {
logger.error("Repopulating the index was interrupted", e);
} catch (CancellationException e) {
logger.trace("Listening for index messages has been cancelled.");
} catch (ExecutionException e) {
logger.error("Repopulating the index failed to execute", e);
} catch (Throwable t) {
logger.error("Repopulating the index failed", t);
}
}
});
}
});
return R.ok();
}
Aggregations