use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.
the class IngestServiceImplTest method setUp.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
FileUtils.forceMkdir(ingestTempDir);
// set up service and mock workspace
wfr = EasyMock.createNiceMock(WorkingFileRepository.class);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlAttachment);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
EasyMock.expect(wfr.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack1);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlTrack2);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog1);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog2);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlCatalog);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackage);
EasyMock.expect(wfr.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(urlPackageOld);
workflowInstance = EasyMock.createNiceMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getId()).andReturn(workflowInstanceID);
EasyMock.expect(workflowInstance.getState()).andReturn(WorkflowState.STOPPED);
final Capture<MediaPackage> mp = EasyMock.newCapture();
workflowService = EasyMock.createNiceMock(WorkflowService.class);
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), EasyMock.capture(mp), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowInstance.getMediaPackage()).andAnswer(new IAnswer<MediaPackage>() {
@Override
public MediaPackage answer() throws Throwable {
return mp.getValue();
}
});
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject(), (Map) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowService.start((WorkflowDefinition) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(workflowInstance);
EasyMock.expect(workflowService.getWorkflowDefinitionById((String) EasyMock.anyObject())).andReturn(new WorkflowDefinitionImpl());
EasyMock.expect(workflowService.getWorkflowById(EasyMock.anyLong())).andReturn(workflowInstance);
SchedulerService schedulerService = EasyMock.createNiceMock(SchedulerService.class);
Map<String, String> properties = new HashMap<>();
properties.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, "sample");
properties.put("agent-name", "matterhorn-agent");
EasyMock.expect(schedulerService.getCaptureAgentConfiguration(EasyMock.anyString())).andReturn(properties).anyTimes();
EasyMock.expect(schedulerService.getDublinCore(EasyMock.anyString())).andReturn(DublinCores.read(urlCatalog1.toURL().openStream())).anyTimes();
MediaPackage schedulerMediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/source-manifest.xml"), "UTF-8"));
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(schedulerMediaPackage).anyTimes();
EasyMock.replay(wfr, workflowInstance, workflowService, schedulerService);
User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization(), "test"));
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);
HttpEntity entity = EasyMock.createMock(HttpEntity.class);
InputStream is = getClass().getResourceAsStream("/av.mov");
byte[] movie = IOUtils.toByteArray(is);
IOUtils.closeQuietly(is);
EasyMock.expect(entity.getContent()).andReturn(new ByteArrayInputStream(movie)).anyTimes();
EasyMock.replay(entity);
StatusLine statusLine = EasyMock.createMock(StatusLine.class);
EasyMock.expect(statusLine.getStatusCode()).andReturn(200).anyTimes();
EasyMock.replay(statusLine);
Header contentDispositionHeader = EasyMock.createMock(Header.class);
EasyMock.expect(contentDispositionHeader.getValue()).andReturn("attachment; filename=fname.mp4").anyTimes();
EasyMock.replay(contentDispositionHeader);
HttpResponse httpResponse = EasyMock.createMock(HttpResponse.class);
EasyMock.expect(httpResponse.getStatusLine()).andReturn(statusLine).anyTimes();
EasyMock.expect(httpResponse.getFirstHeader("Content-Disposition")).andReturn(contentDispositionHeader).anyTimes();
EasyMock.expect(httpResponse.getEntity()).andReturn(entity).anyTimes();
EasyMock.replay(httpResponse);
TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
EasyMock.expect(httpClient.execute((HttpGet) EasyMock.anyObject())).andReturn(httpResponse).anyTimes();
EasyMock.replay(httpClient);
AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(new AccessControlList(), AclScope.Series)).anyTimes();
EasyMock.replay(authorizationService);
MediaInspectionService mediaInspectionService = EasyMock.createNiceMock(MediaInspectionService.class);
EasyMock.expect(mediaInspectionService.enrich(EasyMock.anyObject(MediaPackageElement.class), EasyMock.anyBoolean())).andAnswer(new IAnswer<Job>() {
private int i = 0;
@Override
public Job answer() throws Throwable {
TrackImpl element = (TrackImpl) EasyMock.getCurrentArguments()[0];
element.setDuration(20000L);
if (i % 2 == 0) {
element.addStream(new VideoStreamImpl());
} else {
element.addStream(new AudioStreamImpl());
}
i++;
JobImpl succeededJob = new JobImpl();
succeededJob.setStatus(Status.FINISHED);
succeededJob.setPayload(MediaPackageElementParser.getAsXml(element));
return succeededJob;
}
}).anyTimes();
EasyMock.replay(mediaInspectionService);
service = new IngestServiceImpl();
service.setHttpClient(httpClient);
service.setAuthorizationService(authorizationService);
service.setWorkingFileRepository(wfr);
service.setWorkflowService(workflowService);
service.setSecurityService(securityService);
service.setSchedulerService(schedulerService);
service.setMediaInspectionService(mediaInspectionService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
serviceRegistry.registerService(service);
service.setServiceRegistry(serviceRegistry);
service.defaultWorkflowDefinionId = "sample";
serviceRegistry.registerService(service);
}
use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.
the class SearchServiceImplTest method testDeleteMediaPackage.
/**
* Test removal from the search index.
*/
@Test
public void testDeleteMediaPackage() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
// Make sure our mocked ACL has the read and write permission
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
// Add the media package to the search index
Job job = service.add(mediaPackage);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
// Now take the role away from the user
userResponder.setResponse(userWithoutPermissions);
Map<String, Integer> servers = new HashMap<String, Integer>();
servers.put("http://localhost", 8080);
organizationResponder.setResponse(new JaxbOrganization(DefaultOrganization.DEFAULT_ORGANIZATION_ID, DefaultOrganization.DEFAULT_ORGANIZATION_NAME, servers, DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, null));
// Try to delete it
job = service.delete(mediaPackage.getIdentifier().toString());
barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to delete mediapackage did not finish", Job.Status.FINISHED, job.getStatus());
assertEquals("Unauthorized user was able to delete a mediapackage", Boolean.FALSE.toString(), job.getPayload());
// Second try with a "fixed" roleset
User adminUser = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(defaultOrganization.getAdminRole(), defaultOrganization));
userResponder.setResponse(adminUser);
Date deletedDate = new Date();
job = service.delete(mediaPackage.getIdentifier().toString());
barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Unauthorized user was able to delete a mediapackage", Job.Status.FINISHED, job.getStatus());
// Now go back to the original security service and user
userResponder.setResponse(defaultUser);
organizationResponder.setResponse(defaultOrganization);
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
assertEquals(0, service.getByQuery(q).size());
// Clear the ID requirement
q.withId(null);
assertEquals(0, service.getByQuery(q).size());
q = new SearchQuery();
q.withDeletedSince(deletedDate);
assertEquals(1, service.getByQuery(q).size());
}
use of org.opencastproject.security.api.JaxbUser 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);
}
use of org.opencastproject.security.api.JaxbUser 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);
}
use of org.opencastproject.security.api.JaxbUser 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);
}
Aggregations