use of org.opencastproject.security.api.User in project opencast by opencast.
the class AssetManagerWithSecurityTest method runWith.
/**
* Evaluate product <code>p</code> in a given security context.
*
* @param user
* the user under whose roles and organization <code>p</code> shall be evaluated
* @param assertAccess
* if true assert that the current user is authorized to evaluate <code>p</code>,
* if false assert that the current user is prohibited to evaluate <code>p</code>
* @param p
* the product that contains the calls to the asset manager
* @return the result of the evaluation of <code>p</code>
*/
private <A> A runWith(User user, boolean assertAccess, P1<A> p) {
final User stashedUser = currentUser;
currentUser = user;
A result = null;
try {
result = p.get1();
if (!assertAccess) {
fail("Access should be prohibited");
}
} catch (Exception e) {
if ((e instanceof UnauthorizedException) && assertAccess) {
fail("Access should be granted");
} else if (!(e instanceof UnauthorizedException)) {
Prelude.chuck(e);
}
}
currentUser = stashedUser;
return result;
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class ContributorsListProviderTest method setUp.
@Before
public void setUp() throws Exception {
String expectedFormat = "{\"organization\":\"mh_default\",\"username\":\"akm220\",\"presentation\":\"Adam McKenzie\"}";
organization = new JpaOrganization(ORG_ID, "name", null, null, null, null);
users = new ArrayList<User>();
user1 = new JpaUser("user1", "pass", organization, "User 1", "email1", "provider1", true);
user2 = new JpaUser("user2", "pass", organization, "User 2", "email1", "provider1", true);
user3 = new JpaUser("user3", "pass", organization, null, "email1", "provider1", true);
user4 = new JpaUser("user4", "pass", organization, "User 1", "email3", "provider1", true);
users.add(user1);
users.add(user2);
users.add(user3);
users.add(user4);
userDirectoryService = new UserDirectoryService() {
private Iterator<User> iterator;
@Override
public User loadUser(String userName) {
return null;
}
@Override
public Iterator<User> getUsers() {
return null;
}
@Override
public Iterator<User> findUsers(String query, int offset, int limit) {
iterator = users.iterator();
List<User> filteredList = new ArrayList<User>();
int i = 0;
while ((filteredList.size() < limit || limit == 0) && iterator.hasNext()) {
User item = iterator.next();
if (i++ >= offset) {
filteredList.add(item);
}
}
return filteredList.iterator();
}
@Override
public long countUsers() {
return users.size();
}
@Override
public void invalidate(String userName) {
return;
}
};
List<String> contributors = new ArrayList<String>();
contributors.add("User 1");
contributors.add("User 5");
searchIndex = EasyMock.createNiceMock(AbstractSearchIndex.class);
EasyMock.expect(searchIndex.getTermsForField(EasyMock.anyString(), EasyMock.anyObject(Option.class))).andReturn(contributors).anyTimes();
contributorsListProvider = new ContributorsListProvider();
contributorsListProvider.setUserDirectoryService(userDirectoryService);
contributorsListProvider.setIndex(searchIndex);
EasyMock.replay(searchIndex);
}
use of org.opencastproject.security.api.User in project opencast by opencast.
the class InboxScannerService method updated.
// synchronized with activate(ComponentContext)
@Override
public synchronized void updated(Dictionary properties) throws ConfigurationException {
// build scanner configuration
final String orgId = getCfg(properties, USER_ORG);
final String userId = getCfg(properties, USER_NAME);
final String mediaFlavor = getCfg(properties, MEDIA_FLAVOR);
final String workflowDefinition = getCfg(properties, WORKFLOW_DEFINITION);
final Map<String, String> workflowConfig = getCfgAsMap(properties, WORKFLOW_CONFIG);
final int interval = getCfgAsInt(properties, INBOX_POLL);
final File inbox = new File(getCfg(properties, INBOX_PATH));
if (!inbox.isDirectory()) {
try {
FileUtils.forceMkdir(inbox);
} catch (IOException e) {
throw new ConfigurationException(INBOX_PATH, String.format("%s does not exists and could not be created", inbox.getAbsolutePath()));
}
}
/* We need to be able to read from the inbox to get files from there */
if (!inbox.canRead()) {
throw new ConfigurationException(INBOX_PATH, String.format("Cannot read from %s", inbox.getAbsolutePath()));
}
/* We need to be able to write to the inbox to remove files after they have been ingested */
if (!inbox.canWrite()) {
throw new ConfigurationException(INBOX_PATH, String.format("Cannot write to %s", inbox.getAbsolutePath()));
}
final int maxthreads = option(cc.getBundleContext().getProperty("org.opencastproject.inbox.threads")).bind(Strings.toInt).getOrElse(1);
final Option<SecurityContext> secCtx = getUserAndOrganization(securityService, orgDir, orgId, userDir, userId).bind(new Function<Tuple<User, Organization>, Option<SecurityContext>>() {
@Override
public Option<SecurityContext> apply(Tuple<User, Organization> a) {
return some(new SecurityContext(securityService, a.getB(), a.getA()));
}
});
// Only setup new inbox if security context could be aquired
if (secCtx.isSome()) {
// remove old file install configuration
fileInstallCfg.foreach(removeFileInstallCfg);
// set up new file install config
fileInstallCfg = some(configureFileInstall(cc.getBundleContext(), inbox, interval));
// create new scanner
ingestor = some(new Ingestor(ingestService, workingFileRepository, secCtx.get(), workflowDefinition, workflowConfig, mediaFlavor, inbox, maxthreads));
logger.info("Now watching inbox {}", inbox.getAbsolutePath());
} else {
logger.warn("Cannot create security context for user {}, organization {}. " + "Either the organization or the user does not exist", userId, orgId);
}
}
use of org.opencastproject.security.api.User 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.User in project opencast by opencast.
the class UsersListProviderTest method setUp.
@Before
public void setUp() throws Exception {
users = new ArrayList<User>();
user1 = new JpaUser("user1", "pass", null, "user1", "email1", "provider1", true);
user2 = new JpaUser("user2", "pass", null, "user2", "email1", "provider1", true);
user3 = new JpaUser("user3", "pass", null, "user3", "email1", "provider1", true);
user4 = new JpaUser("user4", "pass", null, "user1", "email3", "provider1", true);
users.add(user1);
users.add(user2);
users.add(user3);
users.add(user4);
userDirectoryService = new UserDirectoryService() {
private Iterator<User> iterator;
@Override
public User loadUser(String userName) {
return null;
}
@Override
public Iterator<User> getUsers() {
return null;
}
@Override
public Iterator<User> findUsers(String query, int offset, int limit) {
iterator = users.iterator();
List<User> filteredList = new ArrayList<User>();
int i = 0;
while ((filteredList.size() < limit || limit == 0) && iterator.hasNext()) {
User item = iterator.next();
if (i++ >= offset) {
filteredList.add(item);
}
}
return filteredList.iterator();
}
@Override
public long countUsers() {
return users.size();
}
@Override
public void invalidate(String userName) {
return;
}
};
usersListProvider = new UsersListProvider();
usersListProvider.setUserDirectoryService(userDirectoryService);
}
Aggregations