Search in sources :

Example 1 with SecurityContext

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);
    }
}
Also used : User(org.opencastproject.security.api.User) SecurityUtil.getUserAndOrganization(org.opencastproject.security.util.SecurityUtil.getUserAndOrganization) Organization(org.opencastproject.security.api.Organization) IOException(java.io.IOException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SecurityContext(org.opencastproject.security.util.SecurityContext) Option(org.opencastproject.util.data.Option) File(java.io.File) Tuple(org.opencastproject.util.data.Tuple)

Example 2 with SecurityContext

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();
}
Also used : CancellationException(java.util.concurrent.CancellationException) Effect0(org.opencastproject.util.data.Effect0) SecurityContext(org.opencastproject.security.util.SecurityContext) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 3 with SecurityContext

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();
}
Also used : CancellationException(java.util.concurrent.CancellationException) Effect0(org.opencastproject.util.data.Effect0) SecurityContext(org.opencastproject.security.util.SecurityContext) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 4 with SecurityContext

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();
}
Also used : CancellationException(java.util.concurrent.CancellationException) Effect0(org.opencastproject.util.data.Effect0) SecurityContext(org.opencastproject.security.util.SecurityContext) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 5 with SecurityContext

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();
}
Also used : CancellationException(java.util.concurrent.CancellationException) Effect0(org.opencastproject.util.data.Effect0) SecurityContext(org.opencastproject.security.util.SecurityContext) ExecutionException(java.util.concurrent.ExecutionException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

SecurityContext (org.opencastproject.security.util.SecurityContext)6 Effect0 (org.opencastproject.util.data.Effect0)5 CancellationException (java.util.concurrent.CancellationException)4 ExecutionException (java.util.concurrent.ExecutionException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 IOException (java.io.IOException)2 File (java.io.File)1 ParseException (java.text.ParseException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JSONException (org.codehaus.jettison.json.JSONException)1 AssetManagerException (org.opencastproject.assetmanager.api.AssetManagerException)1 EventCommentException (org.opencastproject.event.comment.EventCommentException)1 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)1 IngestException (org.opencastproject.ingest.api.IngestException)1 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 MetadataParsingException (org.opencastproject.metadata.dublincore.MetadataParsingException)1