use of org.opencastproject.security.api.User 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.User in project opencast by opencast.
the class OaiPmhUpdatedEventHandler method handleEvent.
public void handleEvent(AssetManagerItem.TakeSnapshot snapshotItem) {
if (!propagateEpisode) {
logger.trace("Skipping automatic propagation of episode meta data to OAI-PMH since it is turned off.");
return;
}
// An episode or its ACL has been updated. Construct the MediaPackage and publish it to OAI-PMH.
logger.debug("Handling update event for media package {}", snapshotItem.getMediapackage().getIdentifier().compact());
// We must be an administrative user to make a query to the OaiPmhPublicationService
final User prevUser = securityService.getUser();
final Organization prevOrg = securityService.getOrganization();
try {
securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
// Check weather the media package contains elements to republish
MediaPackage snapshotMp = snapshotItem.getMediapackage();
SimpleElementSelector mpeSelector = new SimpleElementSelector();
for (String flavor : flavors) {
mpeSelector.addFlavor(flavor);
}
for (String tag : tags) {
mpeSelector.addTag(tag);
}
Collection<MediaPackageElement> elementsToUpdate = mpeSelector.select(snapshotMp, true);
if (elementsToUpdate == null || elementsToUpdate.isEmpty()) {
logger.debug("The media package {} does not contain any elements matching the given flavors and tags", snapshotMp.getIdentifier().compact());
return;
}
SearchResult result = oaiPmhPersistence.search(QueryBuilder.query().mediaPackageId(snapshotMp).isDeleted(false).build());
for (SearchResultItem searchResultItem : result.getItems()) {
try {
Job job = oaiPmhPublicationService.updateMetadata(snapshotMp, searchResultItem.getRepository(), flavors, tags, false);
// we don't want to wait for job completion here because it will block the message queue
} catch (Exception e) {
logger.error("Unable to update OAI-PMH publication for the media package {} in repository {}", snapshotItem.getMediapackage().getIdentifier().compact(), searchResultItem.getRepository(), e);
}
}
} finally {
securityService.setOrganization(prevOrg);
securityService.setUser(prevUser);
}
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class SeriesUpdatedEventHandler method handleEvent.
public void handleEvent(final SeriesItem seriesItem) {
// A series or its ACL has been updated. Find any mediapackages with that series, and update them.
logger.debug("Handling {}", seriesItem);
String seriesId = seriesItem.getSeriesId();
// We must be an administrative user to make this query
final User prevUser = securityService.getUser();
final Organization prevOrg = securityService.getOrganization();
try {
securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
SearchQuery q = new SearchQuery().withSeriesId(seriesId);
SearchResult result = searchService.getForAdministrativeRead(q);
for (SearchResultItem item : result.getItems()) {
MediaPackage mp = item.getMediaPackage();
Organization org = organizationDirectoryService.getOrganization(item.getOrganization());
securityService.setOrganization(org);
// to the distribution channels as well
if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
// Build a new XACML file for this mediapackage
Attachment fileRepoCopy = authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl()).getB();
// Distribute the updated XACML file
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, fileRepoCopy.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(fileRepoCopy);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute XACML {}", fileRepoCopy.getIdentifier());
continue;
}
}
// Update the series dublin core
if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
DublinCoreCatalog seriesDublinCore = seriesItem.getMetadata();
mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
// Update the series dublin core
Catalog[] seriesCatalogs = mp.getCatalogs(MediaPackageElements.SERIES);
if (seriesCatalogs.length == 1) {
Catalog c = seriesCatalogs[0];
String filename = FilenameUtils.getName(c.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
// Distribute the updated series dc
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, c.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(c);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute series catalog {}", c.getIdentifier());
continue;
}
}
}
// Remove the series catalog and isPartOf from episode catalog
if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
mp.setSeries(null);
mp.setSeriesTitle(null);
boolean retractSeriesCatalog = retractSeriesCatalog(mp);
boolean updateEpisodeCatalog = updateEpisodeCatalog(mp);
if (!retractSeriesCatalog || !updateEpisodeCatalog)
continue;
}
// Update the search index with the modified mediapackage
Job searchJob = searchService.add(mp);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, searchJob);
barrier.waitForJobs();
}
} catch (SearchException e) {
logger.warn("Unable to find mediapackages in search: ", e.getMessage());
} catch (UnauthorizedException e) {
logger.warn(e.getMessage());
} catch (MediaPackageException e) {
logger.warn(e.getMessage());
} catch (ServiceRegistryException e) {
logger.warn(e.getMessage());
} catch (NotFoundException e) {
logger.warn(e.getMessage());
} catch (IOException e) {
logger.warn(e.getMessage());
} catch (DistributionException e) {
logger.warn(e.getMessage());
} finally {
securityService.setOrganization(prevOrg);
securityService.setUser(prevUser);
}
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class SakaiUserProviderTest method testLoadUser.
@Test
@Ignore
public void testLoadUser() throws Exception {
User user = sakaiProvider.loadUser("datest");
assertNotNull(user);
// Generic group role added for all Sakai users
assertTrue(hasRole(user.getRoles(), "ROLE_GROUP_SAKAI"));
// Test role specific to user datest on test Sakai instances
assertTrue(hasRole(user.getRoles(), "DAC-EDUCATION-DEPT1-SUBJ3-426_Instructor"));
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class JpaUserReferenceProvider method getRolesForUser.
/**
* {@inheritDoc}
*
* @see org.opencastproject.security.api.RoleProvider#getRolesForUser(String)
*/
@Override
public List<Role> getRolesForUser(String userName) {
ArrayList<Role> roles = new ArrayList<Role>();
User user = loadUser(userName);
if (user != null)
roles.addAll(user.getRoles());
return roles;
}
Aggregations