Search in sources :

Example 6 with SecurityService

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

the class SeriesServiceSolrTest method testAccessControlManagmentRewrite.

@Test
public void testAccessControlManagmentRewrite() throws Exception {
    // sample access control list
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    User user = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole("ROLE_ANONYMOUS", new DefaultOrganization()));
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.replay(securityService);
    // deactivate the default index created in setUp()
    index.deactivate();
    // create a new index with the security service anonymous user
    index = new SeriesServiceSolrIndex();
    index.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
    dcService = new DublinCoreCatalogService();
    index.setDublinCoreService(dcService);
    index.setSecurityService(securityService);
    index.activate(null);
    AccessControlList accessControlList = new AccessControlList();
    List<AccessControlEntry> acl = accessControlList.getEntries();
    acl.add(new AccessControlEntry("ROLE_ANONYMOUS", Permissions.Action.READ.toString(), true));
    index.updateIndex(testCatalog);
    String seriesID = testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER);
    index.updateSecurityPolicy(seriesID, accessControlList);
    SeriesQuery q = new SeriesQuery();
    DublinCoreCatalogList result = index.search(q);
    Assert.assertTrue("Only one anomymous series", result.size() == 1);
    index.updateSecurityPolicy(seriesID, new AccessControlList());
    q = new SeriesQuery();
    result = index.search(q);
    Assert.assertTrue("No anomymous series", result.size() == 0);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SeriesQuery(org.opencastproject.series.api.SeriesQuery) DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 7 with SecurityService

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

the class ComposerServiceTest method setUp.

@Before
public void setUp() throws Exception {
    // Skip tests if FFmpeg is not installed
    Assume.assumeTrue(ffmpegInstalled);
    // Create video only file
    File f = getFile("/video.mp4");
    sourceVideoOnly = File.createTempFile(FilenameUtils.getBaseName(f.getName()), ".mp4", testDir);
    FileUtils.copyFile(f, sourceVideoOnly);
    // Create another audio only file
    f = getFile("/audio.mp3");
    sourceAudioOnly = File.createTempFile(FilenameUtils.getBaseName(f.getName()), ".mp3", testDir);
    FileUtils.copyFile(f, sourceAudioOnly);
    // Create an image file
    f = getFile("/image.jpg");
    sourceImage = File.createTempFile(FilenameUtils.getBaseName(f.getName()), ".jpg", testDir);
    FileUtils.copyFile(f, sourceImage);
    // create the needed mocks
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getProperty(EasyMock.anyString())).andReturn(FFMPEG_BINARY);
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    JaxbOrganization org = new DefaultOrganization();
    HashSet<JaxbRole> roles = new HashSet<>();
    roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, org, ""));
    User user = new JaxbUser("admin", "test", org, roles);
    OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(org).anyTimes();
    UserDirectoryService userDirectory = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectory.loadUser("admin")).andReturn(user).anyTimes();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject())).andReturn(sourceVideoOnly).anyTimes();
    profileScanner = new EncodingProfileScanner();
    File encodingProfile = getFile("/encodingprofiles.properties");
    assertNotNull("Encoding profile must exist", encodingProfile);
    profileScanner.install(encodingProfile);
    // Finish setting up the mocks
    EasyMock.replay(bc, cc, orgDirectory, userDirectory, securityService, workspace);
    // Create an encoding engine factory
    inspectedTrack = (Track) MediaPackageElementParser.getFromXml(IOUtils.toString(ComposerServiceTest.class.getResourceAsStream("/composer_test_source_track_video.xml"), Charset.defaultCharset()));
    sourceVideoTrack = (Track) MediaPackageElementParser.getFromXml(IOUtils.toString(ComposerServiceTest.class.getResourceAsStream("/composer_test_source_track_video.xml"), Charset.defaultCharset()));
    sourceAudioTrack = (Track) MediaPackageElementParser.getFromXml(IOUtils.toString(ComposerServiceTest.class.getResourceAsStream("/composer_test_source_track_audio.xml"), Charset.defaultCharset()));
    // Create and populate the composer service
    composerService = new ComposerServiceImpl() {

        @Override
        protected Job inspect(Job job, URI workspaceURI) throws EncoderException {
            Job inspectionJob = EasyMock.createNiceMock(Job.class);
            try {
                EasyMock.expect(inspectionJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(inspectedTrack));
            } catch (MediaPackageException e) {
                throw new RuntimeException(e);
            }
            EasyMock.replay(inspectionJob);
            return inspectionJob;
        }
    };
    ServiceRegistry serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
    final Capture<String> type = EasyMock.newCapture();
    final Capture<String> operation = EasyMock.newCapture();
    final Capture<List<String>> args = EasyMock.newCapture();
    EasyMock.expect(serviceRegistry.createJob(capture(type), capture(operation), capture(args), EasyMock.anyFloat())).andAnswer(() -> {
        // you could do work here to return something different if you needed.
        Job job = new JobImpl(0);
        job.setJobType(type.getValue());
        job.setOperation(operation.getValue());
        job.setArguments(args.getValue());
        job.setPayload(composerService.process(job));
        return job;
    }).anyTimes();
    composerService.setServiceRegistry(serviceRegistry);
    composerService.setProfileScanner(profileScanner);
    composerService.setWorkspace(workspace);
    EasyMock.replay(serviceRegistry);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) SecurityService(org.opencastproject.security.api.SecurityService) List(java.util.List) ArrayList(java.util.ArrayList) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) JobImpl(org.opencastproject.job.api.JobImpl) ComponentContext(org.osgi.service.component.ComponentContext) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) EncoderException(org.opencastproject.composer.api.EncoderException) JaxbRole(org.opencastproject.security.api.JaxbRole) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 8 with SecurityService

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

the class UserTrackingRestServiceTest method setUp.

@Before
public void setUp() throws UserTrackingException {
    SecurityService security = EasyMock.createMock(SecurityService.class);
    EasyMock.expect(security.getUser()).andReturn(new JaxbUser(MOCK_USER, "test", new DefaultOrganization(), new JaxbRole("ROLE_USER", new DefaultOrganization()))).anyTimes();
    BundleContext bc = EasyMock.createMock(BundleContext.class);
    EasyMock.expect(bc.getProperty(OpencastConstants.SERVER_URL_PROPERTY)).andReturn("http://www.example.org:8080").anyTimes();
    @SuppressWarnings("rawtypes") Dictionary dict = EasyMock.createMock(Dictionary.class);
    EasyMock.expect(dict.get(RestConstants.SERVICE_PATH_PROPERTY)).andReturn("/usertracking").anyTimes();
    ComponentContext context = EasyMock.createMock(ComponentContext.class);
    EasyMock.expect(context.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.expect(context.getProperties()).andReturn(dict).anyTimes();
    UserActionImpl ua = EasyMock.createMock(UserActionImpl.class);
    EasyMock.expect(ua.getId()).andReturn(4L).anyTimes();
    UserTrackingService usertracking = EasyMock.createMock(UserTrackingService.class);
    EasyMock.expect(usertracking.addUserFootprint(EasyMock.isA(UserAction.class), EasyMock.isA(UserSession.class))).andReturn(ua).anyTimes();
    EasyMock.replay(security, bc, dict, context, ua, usertracking);
    service = new UserTrackingRestService();
    service.setSecurityService(security);
    service.setService(usertracking);
    service.activate(context);
}
Also used : Dictionary(java.util.Dictionary) UserTrackingService(org.opencastproject.usertracking.api.UserTrackingService) JaxbRole(org.opencastproject.security.api.JaxbRole) ComponentContext(org.osgi.service.component.ComponentContext) UserTrackingRestService(org.opencastproject.usertracking.endpoint.UserTrackingRestService) SecurityService(org.opencastproject.security.api.SecurityService) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 9 with SecurityService

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

the class VideoEditorTest method setUp.

/**
 * Setup for the video editor service, including creation of a mock workspace and all dependencies.
 *
 * @throws Exception
 *           if setup fails
 */
@Before
public void setUp() throws Exception {
    File tmpDir = folder.newFolder(getClass().getName());
    // output file
    tempFile1 = new File(tmpDir, "testoutput.mp4");
    /* mock the workspace for the input/output file */
    // workspace.get(new URI(sourceTrackUri));
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.rootDirectory()).andReturn(tmpDir.getAbsolutePath());
    EasyMock.expect(workspace.get(track1.getURI())).andReturn(new File(track1.getURI())).anyTimes();
    EasyMock.expect(workspace.get(track2.getURI())).andReturn(new File(track2.getURI())).anyTimes();
    EasyMock.expect(workspace.putInCollection(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject(InputStream.class))).andAnswer(() -> {
        InputStream in = (InputStream) EasyMock.getCurrentArguments()[2];
        IOUtils.copy(in, new FileOutputStream(tempFile1));
        return tempFile1.toURI();
    });
    /* mock the role/org/security dependencies */
    User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization()));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    /* mock the osgi init for the video editor itself */
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    File storageDir = folder.newFolder();
    logger.info("storageDir: {}", storageDir);
    EasyMock.expect(bc.getProperty("org.opencastproject.storage.dir")).andReturn(storageDir.getPath()).anyTimes();
    EasyMock.expect(bc.getProperty("org.opencastproject.composer.ffmpegpath")).andReturn(FFMPEG_BINARY).anyTimes();
    EasyMock.expect(bc.getProperty(FFmpegAnalyzer.FFPROBE_BINARY_CONFIG)).andReturn("ffprobe").anyTimes();
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.replay(bc, cc, workspace, userDirectoryService, organizationDirectoryService, securityService);
    /* mock inspector output so that the job will alway pass */
    String sourceTrackXml = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" + "<track xmlns=\"http://mediapackage.opencastproject.org\" type='presentation/source' id='deadbeef-a926-4ba9-96d9-2fafbcc30d2a'>" + "<audio id='audio-1'><encoder type='MP3 (MPEG audio layer 3)'/><channels>2</channels>" + "<bitrate>96000.0</bitrate></audio><video id='video-1'><device/>" + "<encoder type='FLV / Sorenson Spark / Sorenson H.263 (Flash Video)'/>" + "<bitrate>512000.0</bitrate><framerate>15.0</framerate>" + "<resolution>854x480</resolution></video>" + "<mimetype>video/mpeg</mimetype><url>video.mp4</url></track>";
    inspectedTrack = (Track) MediaPackageElementParser.getFromXml(sourceTrackXml);
    veditor = new VideoEditorServiceImpl() {

        @Override
        protected Job inspect(Job job, URI workspaceURI) throws MediaInspectionException, ProcessFailedException {
            Job inspectionJob = EasyMock.createNiceMock(Job.class);
            try {
                EasyMock.expect(inspectionJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(inspectedTrack));
            } catch (MediaPackageException e) {
                throw new MediaInspectionException(e);
            }
            EasyMock.replay(inspectionJob);
            return inspectionJob;
        }
    };
    /* set up video editor */
    veditor.activate(cc);
    veditor.setWorkspace(workspace);
    veditor.setSecurityService(securityService);
    veditor.setUserDirectoryService(userDirectoryService);
    veditor.setSmilService(smilService);
    veditor.setOrganizationDirectoryService(organizationDirectoryService);
    serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
    final Capture<String> type = EasyMock.newCapture();
    final Capture<String> operation = EasyMock.newCapture();
    final Capture<List<String>> args = EasyMock.newCapture();
    EasyMock.expect(serviceRegistry.createJob(capture(type), capture(operation), capture(args), EasyMock.anyFloat())).andAnswer(() -> {
        Job job = new JobImpl(0);
        logger.error("type: {}", type.getValue());
        job.setJobType(type.getValue());
        job.setOperation(operation.getValue());
        job.setArguments(args.getValue());
        job.setPayload(veditor.process(job));
        return job;
    }).anyTimes();
    EasyMock.replay(serviceRegistry);
    veditor.setServiceRegistry(serviceRegistry);
}
Also used : 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) URI(java.net.URI) MediaInspectionException(org.opencastproject.inspection.api.MediaInspectionException) SecurityService(org.opencastproject.security.api.SecurityService) List(java.util.List) ArrayList(java.util.ArrayList) Job(org.opencastproject.job.api.Job) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) JobImpl(org.opencastproject.job.api.JobImpl) ComponentContext(org.osgi.service.component.ComponentContext) InputStream(java.io.InputStream) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) FileOutputStream(java.io.FileOutputStream) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 10 with SecurityService

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

the class OpencastLdapAuthoritiesPopulatorTest method setUp.

@Before
public void setUp() {
    mappings = new HashMap<>();
    org = EasyMock.createNiceMock(Organization.class);
    EasyMock.expect(org.getId()).andReturn(ORG_NAME).anyTimes();
    Set<Role> groupRoles = new HashSet<>();
    for (int i = 1; i <= N_GROUP_ROLES; i++) {
        Role r = EasyMock.createNiceMock(Role.class);
        EasyMock.expect(r.getOrganization()).andReturn(org).anyTimes();
        EasyMock.expect(r.getName()).andReturn(format("group_role_%d", i)).anyTimes();
        EasyMock.replay(r);
        groupRoles.add(r);
    }
    User mockUser = EasyMock.createNiceMock(User.class);
    EasyMock.expect(mockUser.getUsername()).andReturn(USERNAME).anyTimes();
    EasyMock.expect(mockUser.getRoles()).andReturn(DEFAULT_INTERNAL_ROLES).anyTimes();
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(mockUser).anyTimes();
    groupRoleProvider = EasyMock.createNiceMock(JpaGroupRoleProvider.class);
    EasyMock.expect(groupRoleProvider.getRolesForGroup(GROUP_ROLE)).andReturn(new ArrayList<>(groupRoles)).anyTimes();
    EasyMock.replay(org, securityService, groupRoleProvider, mockUser);
}
Also used : Role(org.opencastproject.security.api.Role) Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) JpaGroupRoleProvider(org.opencastproject.userdirectory.JpaGroupRoleProvider) SecurityService(org.opencastproject.security.api.SecurityService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

SecurityService (org.opencastproject.security.api.SecurityService)99 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)62 Before (org.junit.Before)55 JaxbUser (org.opencastproject.security.api.JaxbUser)44 User (org.opencastproject.security.api.User)43 JaxbRole (org.opencastproject.security.api.JaxbRole)39 Organization (org.opencastproject.security.api.Organization)31 Test (org.junit.Test)30 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)29 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)29 Workspace (org.opencastproject.workspace.api.Workspace)29 MediaPackage (org.opencastproject.mediapackage.MediaPackage)22 InputStream (java.io.InputStream)21 URI (java.net.URI)21 File (java.io.File)20 ArrayList (java.util.ArrayList)20 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)18 MessageSender (org.opencastproject.message.broker.api.MessageSender)16 AuthorizationService (org.opencastproject.security.api.AuthorizationService)16 IOException (java.io.IOException)15