use of org.opencastproject.security.api.DefaultOrganization 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);
}
use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class UserAndRoleDirectoryServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
org = new DefaultOrganization();
userName = "sampleUser";
role1 = new JaxbRole("role1", org);
role2 = new JaxbRole("role2", org);
role3 = new JaxbRole("role3", org);
JaxbUser user1 = new JaxbUser(userName, "matterhorn", org, role1, role2);
user1.setManageable(true);
User user2 = new JaxbUser(userName, "secret", "test", true, org, role2, role3);
User user3 = new JaxbUser("userSample", "test", org, role2, role3);
List<User> users = new ArrayList<User>();
users.add(user1);
UserProvider provider1 = EasyMock.createNiceMock(UserProvider.class);
EasyMock.expect(provider1.getOrganization()).andReturn(org.getId()).anyTimes();
EasyMock.expect(provider1.loadUser((String) EasyMock.anyObject())).andReturn(user1).anyTimes();
EasyMock.expect(provider1.findUsers("%mple%", 0, 0)).andReturn(users.iterator()).once();
EasyMock.expect(provider1.findUsers("%mple%", 0, 0)).andReturn(users.iterator()).once();
EasyMock.expect(provider1.getUsers()).andReturn(users.iterator()).once();
EasyMock.expect(provider1.getName()).andReturn("test").once();
List<User> users2 = new ArrayList<User>();
users2.add(user3);
UserProvider provider2 = EasyMock.createNiceMock(UserProvider.class);
EasyMock.expect(provider2.getOrganization()).andReturn(org.getId()).anyTimes();
EasyMock.expect(provider2.loadUser((String) EasyMock.anyObject())).andReturn(user2).anyTimes();
EasyMock.expect(provider2.findUsers("%mple%", 0, 0)).andReturn(users2.iterator()).once();
EasyMock.expect(provider2.findUsers("%mple%", 0, 0)).andReturn(users2.iterator()).once();
EasyMock.expect(provider2.getUsers()).andReturn(users2.iterator()).once();
EasyMock.expect(provider2.getName()).andReturn("matterhorn").once();
List<Role> roles1 = new ArrayList<Role>();
roles1.add(new JaxbRole("ROLE_ASTRO_2011", org));
roles1.add(new JaxbRole("ROLE_ASTRO_2012", org));
List<Role> rolesForUser1 = new ArrayList<Role>();
rolesForUser1.add(new JaxbRole("ROLE_ASTRO_2012", org));
List<Role> findRoles1 = new ArrayList<Role>();
findRoles1.add(new JaxbRole("ROLE_ASTRO_2012", org));
RoleProvider roleProvider1 = EasyMock.createNiceMock(RoleProvider.class);
EasyMock.expect(roleProvider1.getOrganization()).andReturn(org.getId()).anyTimes();
EasyMock.expect(roleProvider1.getRoles()).andReturn(roles1.iterator()).anyTimes();
EasyMock.expect(roleProvider1.getRolesForUser((String) EasyMock.anyObject())).andReturn(rolesForUser1).anyTimes();
EasyMock.expect(roleProvider1.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(findRoles1.iterator()).once();
EasyMock.expect(roleProvider1.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(findRoles1.iterator()).once();
List<Role> roles2 = new ArrayList<Role>();
roles2.add(new JaxbRole("ROLE_MATH_2011", org));
roles2.add(new JaxbRole("ROLE_MATH_2012", org));
List<Role> rolesForUser2 = new ArrayList<Role>();
rolesForUser2.add(new JaxbRole("ROLE_MATH_2012", org));
List<Role> findRoles2 = new ArrayList<Role>();
findRoles2.add(new JaxbRole("ROLE_MATH_2012", org));
RoleProvider roleProvider2 = EasyMock.createNiceMock(RoleProvider.class);
EasyMock.expect(roleProvider2.getOrganization()).andReturn(org.getId()).anyTimes();
EasyMock.expect(roleProvider2.getRoles()).andReturn(roles2.iterator()).anyTimes();
EasyMock.expect(roleProvider2.getRolesForUser((String) EasyMock.anyObject())).andReturn(rolesForUser2).anyTimes();
EasyMock.expect(roleProvider2.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(findRoles2.iterator()).once();
EasyMock.expect(roleProvider2.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(findRoles2.iterator()).once();
RoleProvider otherOrgRoleProvider = EasyMock.createNiceMock(RoleProvider.class);
EasyMock.expect(otherOrgRoleProvider.getOrganization()).andReturn("otherOrg").anyTimes();
EasyMock.expect(otherOrgRoleProvider.getRoles()).andReturn(roles2.iterator()).anyTimes();
EasyMock.expect(otherOrgRoleProvider.getRolesForUser((String) EasyMock.anyObject())).andReturn(rolesForUser2).anyTimes();
EasyMock.expect(otherOrgRoleProvider.findRoles("%2012%", Role.Target.ALL, 0, 0)).andReturn(new ArrayList<Role>().iterator()).anyTimes();
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
EasyMock.replay(provider1, provider2, roleProvider1, roleProvider2, otherOrgRoleProvider, securityService);
directory = new UserAndRoleDirectoryServiceImpl();
directory.activate(null);
directory.setSecurityService(securityService);
directory.addUserProvider(provider1);
directory.addUserProvider(provider2);
directory.addRoleProvider(roleProvider1);
directory.addRoleProvider(roleProvider2);
directory.addRoleProvider(otherOrgRoleProvider);
}
use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class AnnotationServiceJpaImplTest method setUp.
@Before
public void setUp() throws Exception {
// Set up a mock security service that always returns "me" as the current user
DefaultOrganization organization = new DefaultOrganization();
JaxbRole role = new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, organization, "");
HashSet<JaxbRole> roles = new HashSet<JaxbRole>();
roles.add(role);
User me = new JaxbUser("me", "test", organization, roles);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(me).anyTimes();
EasyMock.replay(securityService);
// Set up the annotation service
annotationService = new AnnotationServiceJpaImpl();
annotationService.setEntityManagerFactory(newTestEntityManagerFactory(AnnotationServiceJpaImpl.PERSISTENCE_UNIT));
annotationService.setSecurityService(securityService);
}
use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class StreamingDistributionServiceTest method setUp.
@Before
public void setUp() throws Exception {
final File mediaPackageRoot = new File(getClass().getResource("/mediapackage.xml").toURI()).getParentFile();
mp = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/mediapackage.xml"), "UTF-8"));
distributionRoot = new File(mediaPackageRoot, "static");
service = new StreamingDistributionServiceImpl();
defaultOrganization = new DefaultOrganization();
User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
service.setUserDirectoryService(userDirectoryService);
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(defaultOrganization).anyTimes();
EasyMock.replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(defaultOrganization).anyTimes();
EasyMock.replay(securityService);
service.setSecurityService(securityService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
service.setServiceRegistry(serviceRegistry);
final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
final URI uri = (URI) EasyMock.getCurrentArguments()[0];
final String[] pathElems = uri.getPath().split("/");
final String file = pathElems[pathElems.length - 1];
return new File(mediaPackageRoot, file);
}
}).anyTimes();
EasyMock.replay(workspace);
service.setWorkspace(workspace);
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getProperty("org.opencastproject.streaming.url")).andReturn("rtmp://localhost/").anyTimes();
EasyMock.expect(bc.getProperty("org.opencastproject.streaming.directory")).andReturn(distributionRoot.getPath()).anyTimes();
EasyMock.replay(bc);
ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
EasyMock.replay(cc);
service.activate(cc);
}
use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class LiveScheduleServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
mimeType = MimeTypes.parseMimeType(MIME_TYPE);
// Osgi Services
serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
searchService = EasyMock.createNiceMock(SearchService.class);
seriesService = EasyMock.createNiceMock(SeriesService.class);
captureAgentService = EasyMock.createNiceMock(CaptureAgentStateService.class);
EasyMock.expect(captureAgentService.getAgentCapabilities("demo-capture-agent")).andReturn(new Properties());
downloadDistributionService = EasyMock.createNiceMock(DownloadDistributionService.class);
EasyMock.expect(downloadDistributionService.getDistributionType()).andReturn(LiveScheduleServiceImpl.DEFAULT_LIVE_DISTRIBUTION_SERVICE).anyTimes();
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://someUrl"));
dublinCoreService = EasyMock.createNiceMock(DublinCoreCatalogService.class);
assetManager = EasyMock.createNiceMock(AssetManager.class);
authService = new AuthorizationServiceMock();
organizationService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
Organization defOrg = new DefaultOrganization();
Map<String, String> orgProps = new HashMap<String, String>();
orgProps.put(LiveScheduleServiceImpl.PLAYER_PROPERTY, PATH_TO_PLAYER);
orgProps.put(LiveScheduleServiceImpl.ENGAGE_URL_PROPERTY, ENGAGE_URL);
org = new JaxbOrganization(ORG_ID, "Test Organization", defOrg.getServers(), defOrg.getAdminRole(), defOrg.getAnonymousRole(), orgProps);
EasyMock.expect(organizationService.getOrganization(ORG_ID)).andReturn(org).anyTimes();
// Live service configuration
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(LiveScheduleServiceImpl.LIVE_STREAMING_URL, STREAMING_SERVER_URL);
props.put(LiveScheduleServiceImpl.LIVE_STREAM_MIME_TYPE, "video/x-flv");
props.put(LiveScheduleServiceImpl.LIVE_STREAM_NAME, STREAM_NAME);
props.put(LiveScheduleServiceImpl.LIVE_STREAM_RESOLUTION, "1920x540,960x270");
props.put(LiveScheduleServiceImpl.LIVE_TARGET_FLAVORS, "presenter/delivery");
cc = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(cc.getBundleContext()).andReturn(bc);
EasyMock.expect(cc.getProperties()).andReturn(props);
EasyMock.replay(bc, cc);
service = new LiveScheduleServiceImpl();
service.setJobPollingInterval(1L);
service.setSearchService(searchService);
service.setSeriesService(seriesService);
service.setCaptureAgentService(captureAgentService);
service.setServiceRegistry(serviceRegistry);
service.setWorkspace(workspace);
service.setDublinCoreService(dublinCoreService);
service.setAssetManager(assetManager);
service.setAuthorizationService(authService);
service.setOrganizationService(organizationService);
service.activate(cc);
}
Aggregations