use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class SchedulerMessageReceiverImplTest method setUp.
@Before
public void setUp() throws Exception {
SecurityService securityService = TestSearchIndex.createSecurityService(new DefaultOrganization());
scheduler = new SchedulerMessageReceiverImpl();
scheduler.setSecurityService(securityService);
scheduler.setSearchIndex(index);
}
use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class EventCommentDatabaseImplTest method setUp.
@Before
public void setUp() throws Exception {
UserDirectoryService userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser(EasyMock.anyObject(String.class))).andReturn(USER).anyTimes();
EasyMock.replay(userDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.replay(securityService);
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
EasyMock.replay(messageSender);
persistence = new EventCommentDatabaseServiceImpl();
persistence.setEntityManagerFactory(newTestEntityManagerFactory(PERSISTENCE_UNIT));
persistence.setUserDirectoryService(userDirectoryService);
persistence.setMessageSender(messageSender);
persistence.setSecurityService(securityService);
persistence.activate(null);
}
use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class EventCommentDatabaseServiceImpl method repopulate.
@Override
public void repopulate(final String indexName) throws Exception {
final String destinationId = CommentItem.COMMENT_QUEUE_PREFIX + WordUtils.capitalize(indexName);
try {
final int total = countComments();
final int[] current = new int[1];
current[0] = 0;
logger.info("Re-populating index '{}' with comments for events. There are {} events with comments to add", indexName, total);
final int responseInterval = (total < 100) ? 1 : (total / 100);
final Map<String, List<String>> eventsWithComments = getEventsWithComments();
for (String orgId : eventsWithComments.keySet()) {
Organization organization = organizationDirectoryService.getOrganization(orgId);
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {
@Override
protected void run() {
for (String eventId : eventsWithComments.get(orgId)) {
try {
List<EventComment> comments = getComments(eventId);
boolean hasOpenComments = !Stream.$(comments).filter(filterOpenComments).toList().isEmpty();
boolean needsCutting = !Stream.$(comments).filter(filterNeedsCuttingComment).toList().isEmpty();
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, CommentItem.update(eventId, !comments.isEmpty(), hasOpenComments, needsCutting));
current[0] += comments.size();
if (responseInterval == 1 || comments.size() > responseInterval || current[0] == total || current[0] % responseInterval < comments.size()) {
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Comments, total, current[0]));
}
} catch (EventCommentDatabaseException e) {
logger.error("Unable to retrieve event comments for organization {}", orgId, e);
} catch (Throwable t) {
logger.error("Unable to update comment on event {} for organization {}", eventId, orgId, t);
}
}
}
});
}
} catch (Exception e) {
logger.warn("Unable to index event comments", e);
throw new ServiceException(e.getMessage());
}
Organization organization = new DefaultOrganization();
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {
@Override
protected void run() {
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Comments));
}
});
}
use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class OaiPmhPersistenceTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Mock up a security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
User user = SecurityUtil.createSystemUser("admin", new DefaultOrganization());
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
mp1 = MediaPackageSupport.loadFromClassPath("/mp1.xml");
mp2 = MediaPackageSupport.loadFromClassPath("/mp2.xml");
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.read(uri("series-dublincore.xml"))).andAnswer(() -> getClass().getResourceAsStream("/series-dublincore.xml")).anyTimes();
EasyMock.expect(workspace.read(uri("episode-dublincore.xml"))).andAnswer(() -> getClass().getResourceAsStream("/episode-dublincore.xml")).anyTimes();
EasyMock.expect(workspace.read(uri("mpeg7.xml"))).andAnswer(() -> getClass().getResourceAsStream("/mpeg7.xml")).anyTimes();
EasyMock.expect(workspace.read(uri("series-xacml.xml"))).andAnswer(() -> getClass().getResourceAsStream("/series-xacml.xml")).anyTimes();
EasyMock.replay(workspace);
oaiPmhDatabase = new OaiPmhDatabaseImpl();
oaiPmhDatabase.setEntityManagerFactory(newTestEntityManagerFactory(OaiPmhDatabaseImpl.PERSISTENCE_UNIT_NAME));
oaiPmhDatabase.setSecurityService(securityService);
oaiPmhDatabase.setWorkspace(workspace);
oaiPmhDatabase.activate(null);
}
use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.
the class SchedulerMigrationServiceTest method setUp.
@Before
public void setUp() throws Exception {
OrganizationDirectoryService orgDirService = createNiceMock(OrganizationDirectoryService.class);
expect(orgDirService.getOrganization(anyString())).andReturn(new DefaultOrganization()).anyTimes();
replay(orgDirService);
SecurityService securityService = createNiceMock(SecurityService.class);
expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
expect(securityService.getUser()).andReturn(new JaxbUser()).anyTimes();
replay(securityService);
SchedulerTransaction schedulerTransaction = createNiceMock(SchedulerTransaction.class);
replay(schedulerTransaction);
SchedulerService schedulerService = createNiceMock(SchedulerService.class);
expect(schedulerService.createTransaction(anyString())).andReturn(schedulerTransaction).anyTimes();
expect(schedulerService.search(anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class), anyObject(Opt.class))).andReturn(new ArrayList<>());
replay(schedulerService);
Workspace workspace = createNiceMock(Workspace.class);
expect(workspace.put(anyString(), anyString(), anyString(), anyObject(InputStream.class))).andReturn(new URI("test")).anyTimes();
replay(workspace);
AuthorizationService authorizationService = createNiceMock(AuthorizationService.class);
replay(authorizationService);
schedulerMigrationService.setAuthorizationService(authorizationService);
schedulerMigrationService.setOrganizationDirectoryService(orgDirService);
schedulerMigrationService.setSchedulerService(schedulerService);
schedulerMigrationService.setSecurityService(securityService);
schedulerMigrationService.setWorkspace(workspace);
}
Aggregations