Search in sources :

Example 91 with Organization

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

the class SeriesServiceSolrIndex method appendAuthorization.

/**
 * Appends the authorization information to the solr query string
 *
 * @param sb
 *          the {@link StringBuilder} containing the query
 * @param forEdit
 *          if this query should return only series available to the current user for editing
 *
 * @return the appended {@link StringBuilder}
 */
protected StringBuilder appendAuthorization(StringBuilder sb, boolean forEdit) {
    User currentUser = securityService.getUser();
    Organization currentOrg = securityService.getOrganization();
    if (!currentUser.hasRole(currentOrg.getAdminRole()) && !currentUser.hasRole(GLOBAL_ADMIN_ROLE)) {
        List<String> roleList = new ArrayList<String>();
        for (Role role : currentUser.getRoles()) {
            roleList.add(role.getName());
        }
        String[] roles = roleList.toArray(new String[roleList.size()]);
        if (forEdit) {
            appendAnd(sb, SolrFields.ACCESS_CONTROL_EDIT, roles);
        } else if (roles.length > 0) {
            sb.append(" AND (");
            append(sb, "", SolrFields.ACCESS_CONTROL_CONTRIBUTE, roles);
            sb.append(" OR ");
            append(sb, "", SolrFields.ACCESS_CONTROL_READ, roles);
            sb.append(")");
        }
    }
    return sb;
}
Also used : Role(org.opencastproject.security.api.Role) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) ArrayList(java.util.ArrayList)

Example 92 with Organization

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

the class AnalyzeAudioWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    uriMP = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    URI soxTrackUri = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox-track.xml").toURI();
    URI soxEncodeUri = AnalyzeAudioWorkflowOperationHandler.class.getResource("/sox-encode-track.xml").toURI();
    String soxTrackXml = IOUtils.toString(soxTrackUri.toURL().openStream());
    String encodeTrackXml = IOUtils.toString(soxEncodeUri.toURL().openStream());
    instance = EasyMock.createNiceMock(WorkflowInstance.class);
    EasyMock.expect(instance.getMediaPackage()).andReturn(mp).anyTimes();
    EasyMock.expect(instance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
    EasyMock.replay(instance);
    DefaultOrganization org = new DefaultOrganization();
    User anonymous = new JaxbUser("anonymous", "test", org, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, org));
    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);
    IncidentService incidentService = EasyMock.createNiceMock(IncidentService.class);
    EasyMock.replay(incidentService);
    ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(null, securityService, userDirectoryService, organizationDirectoryService, incidentService);
    Job analyzeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Analyze", null, soxTrackXml, false);
    analyzeJob.setStatus(Status.FINISHED);
    analyzeJob = serviceRegistry.updateJob(analyzeJob);
    Job encodeJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Encode", null, encodeTrackXml, false);
    encodeJob.setStatus(Status.FINISHED);
    encodeJob = serviceRegistry.updateJob(encodeJob);
    SoxService sox = EasyMock.createNiceMock(SoxService.class);
    EasyMock.expect(sox.analyze((Track) EasyMock.anyObject())).andReturn(analyzeJob).anyTimes();
    EasyMock.replay(sox);
    ComposerService composer = EasyMock.createNiceMock(ComposerService.class);
    EasyMock.expect(composer.encode((Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(encodeJob);
    EasyMock.replay(composer);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.replay(workspace);
    // set up the handler
    operationHandler = new AnalyzeAudioWorkflowOperationHandler();
    operationHandler.setJobBarrierPollingInterval(0);
    operationHandler.setComposerService(composer);
    operationHandler.setSoxService(sox);
    operationHandler.setWorkspace(workspace);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) ComposerService(org.opencastproject.composer.api.ComposerService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) SoxService(org.opencastproject.sox.api.SoxService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) Track(org.opencastproject.mediapackage.Track) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 93 with Organization

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

the class NormalizeAudioWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    uriMP = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    URI soxTrackUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-track.xml").toURI();
    URI normalizedTrackUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/normalized-track.xml").toURI();
    URI soxEncodeUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-encode-track.xml").toURI();
    URI soxMuxUri = NormalizeAudioWorkflowOperationHandler.class.getResource("/sox-mux-track.xml").toURI();
    String soxTrackXml = IOUtils.toString(soxTrackUri.toURL().openStream());
    String encodeTrackXml = IOUtils.toString(soxEncodeUri.toURL().openStream());
    String normalizedTrackXml = IOUtils.toString(normalizedTrackUri.toURL().openStream());
    String muxedTrackXml = IOUtils.toString(soxMuxUri.toURL().openStream());
    instance = EasyMock.createNiceMock(WorkflowInstance.class);
    EasyMock.expect(instance.getMediaPackage()).andReturn(mp).anyTimes();
    EasyMock.expect(instance.getCurrentOperation()).andReturn(operationInstance).anyTimes();
    EasyMock.replay(instance);
    DefaultOrganization org = new DefaultOrganization();
    User anonymous = new JaxbUser("anonymous", "test", org, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, org));
    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);
    IncidentService incidentService = EasyMock.createNiceMock(IncidentService.class);
    EasyMock.replay(incidentService);
    ServiceRegistry serviceRegistry = new ServiceRegistryInMemoryImpl(null, securityService, userDirectoryService, organizationDirectoryService, incidentService);
    Job analyzeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Analyze", null, soxTrackXml, false);
    analyzeJob.setStatus(Status.FINISHED);
    analyzeJob = serviceRegistry.updateJob(analyzeJob);
    Job normalizeJob = serviceRegistry.createJob(SoxService.JOB_TYPE, "Normalize", null, normalizedTrackXml, false);
    normalizeJob.setStatus(Status.FINISHED);
    normalizeJob = serviceRegistry.updateJob(normalizeJob);
    Job encodeJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Encode", null, encodeTrackXml, false);
    encodeJob.setStatus(Status.FINISHED);
    encodeJob = serviceRegistry.updateJob(encodeJob);
    Job muxJob = serviceRegistry.createJob(ComposerService.JOB_TYPE, "Mux", null, muxedTrackXml, false);
    muxJob.setStatus(Status.FINISHED);
    muxJob = serviceRegistry.updateJob(muxJob);
    SoxService sox = EasyMock.createNiceMock(SoxService.class);
    EasyMock.expect(sox.analyze((Track) EasyMock.anyObject())).andReturn(analyzeJob).anyTimes();
    EasyMock.expect(sox.normalize((Track) EasyMock.anyObject(), (Float) EasyMock.anyObject())).andReturn(normalizeJob).anyTimes();
    EasyMock.replay(sox);
    ComposerService composer = EasyMock.createNiceMock(ComposerService.class);
    EasyMock.expect(composer.encode((Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(encodeJob);
    EasyMock.expect(composer.mux((Track) EasyMock.anyObject(), (Track) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(muxJob);
    EasyMock.replay(composer);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(new URI("fooVideo.flv"));
    EasyMock.replay(workspace);
    // set up the handler
    operationHandler = new NormalizeAudioWorkflowOperationHandler();
    operationHandler.setJobBarrierPollingInterval(0);
    operationHandler.setComposerService(composer);
    operationHandler.setSoxService(sox);
    operationHandler.setWorkspace(workspace);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) ComposerService(org.opencastproject.composer.api.ComposerService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) SoxService(org.opencastproject.sox.api.SoxService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) Track(org.opencastproject.mediapackage.Track) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 94 with Organization

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

the class ThemesServiceDatabaseImpl method repopulate.

@Override
public void repopulate(final String indexName) {
    final String destinationId = ThemeItem.THEME_QUEUE_PREFIX + WordUtils.capitalize(indexName);
    for (final Organization organization : organizationDirectoryService.getOrganizations()) {
        SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

            @Override
            protected void run() {
                try {
                    final List<Theme> themes = getThemes();
                    int total = themes.size();
                    int current = 1;
                    logger.info("Re-populating '{}' index with themes from organization {}. There are {} theme(s) to add to the index.", indexName, securityService.getOrganization().getId(), total);
                    for (Theme theme : themes) {
                        messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, ThemeItem.update(toSerializableTheme(theme)));
                        messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Themes, total, current));
                        current++;
                    }
                } catch (ThemesServiceDatabaseException e) {
                    logger.error("Unable to get themes from the database because: {}", ExceptionUtils.getStackTrace(e));
                    throw new IllegalStateException(e);
                }
            }
        });
    }
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Themes));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Effect0(org.opencastproject.util.data.Effect0) Theme(org.opencastproject.themes.Theme) SerializableTheme(org.opencastproject.message.broker.api.theme.SerializableTheme) ArrayList(java.util.ArrayList) List(java.util.List) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 95 with Organization

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

the class IBMWatsonTranscriptionService method registerCallback.

/**
 * Register the callback url with the Speech-to-text service. From:
 * https://www.ibm.com/watson/developercloud/speech-to-text/api/v1/#register_callback
 *
 * curl -X POST -u "{username}":"{password}" --data "{}"
 * "https://stream.watsonplatform.net/speech-to-text/api/v1/register_callback?callback_url=http://{user_callback_path}/results&user_secret=ThisIsMySecret"
 * Response looks like: { "status": "created", "url": "http://{user_callback_path}/results" }
 */
void registerCallback() throws TranscriptionServiceException {
    if (callbackAlreadyRegistered)
        return;
    Organization org = securityService.getOrganization();
    String adminUrl = StringUtils.trimToNull(org.getProperties().get(ADMIN_URL_PROPERTY));
    if (adminUrl != null)
        callbackUrl = adminUrl + CALLBACK_PATH;
    else
        callbackUrl = serverUrl + CALLBACK_PATH;
    logger.info("Callback url is {}", callbackUrl);
    CloseableHttpClient httpClient = makeHttpClient();
    HttpPost httpPost = new HttpPost(IBM_WATSON_SERVICE_URL + REGISTER_CALLBACK + String.format("?callback_url=%s", callbackUrl));
    CloseableHttpResponse response = null;
    try {
        response = httpClient.execute(httpPost);
        int code = response.getStatusLine().getStatusCode();
        switch(code) {
            case // 200
            HttpStatus.SC_OK:
                logger.info("Callback url: {} had already already been registered", callbackUrl);
                callbackAlreadyRegistered = true;
                EntityUtils.consume(response.getEntity());
                break;
            case // 201
            HttpStatus.SC_CREATED:
                logger.info("Callback url: {} has been successfully registered", callbackUrl);
                callbackAlreadyRegistered = true;
                EntityUtils.consume(response.getEntity());
                break;
            case // 400
            HttpStatus.SC_BAD_REQUEST:
                logger.warn("Callback url {} could not be verified, status: {}", callbackUrl, code);
                break;
            case // 503
            HttpStatus.SC_SERVICE_UNAVAILABLE:
                logger.warn("Service unavailable when registering callback url {} status: {}", callbackUrl, code);
                break;
            default:
                logger.warn("Unknown status when registering callback url {}, status: {}", callbackUrl, code);
                break;
        }
    } catch (Exception e) {
        logger.warn("Exception when calling the the register callback endpoint", e);
    } finally {
        try {
            httpClient.close();
            if (response != null)
                response.close();
        } catch (IOException e) {
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) TranscriptionServiceException(org.opencastproject.transcription.api.TranscriptionServiceException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) TranscriptionDatabaseException(org.opencastproject.transcription.ibmwatson.persistence.TranscriptionDatabaseException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IOException(java.io.IOException)

Aggregations

Organization (org.opencastproject.security.api.Organization)135 User (org.opencastproject.security.api.User)60 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)46 NotFoundException (org.opencastproject.util.NotFoundException)43 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)29 SecurityService (org.opencastproject.security.api.SecurityService)29 IOException (java.io.IOException)24 Before (org.junit.Before)24 ArrayList (java.util.ArrayList)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)22 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)22 JaxbRole (org.opencastproject.security.api.JaxbRole)21 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 JaxbUser (org.opencastproject.security.api.JaxbUser)20 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)19 File (java.io.File)18 HashMap (java.util.HashMap)17 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)17 Test (org.junit.Test)15