Search in sources :

Example 61 with DefaultOrganization

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);
}
Also used : SecurityService(org.opencastproject.security.api.SecurityService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 62 with DefaultOrganization

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);
}
Also used : SecurityService(org.opencastproject.security.api.SecurityService) MessageSender(org.opencastproject.message.broker.api.MessageSender) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 63 with DefaultOrganization

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));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) ServiceException(org.osgi.framework.ServiceException) NoResultException(javax.persistence.NoResultException) NotFoundException(org.opencastproject.util.NotFoundException) ServiceException(org.osgi.framework.ServiceException) Effect0(org.opencastproject.util.data.Effect0) ArrayList(java.util.ArrayList) List(java.util.List) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 64 with DefaultOrganization

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);
}
Also used : User(org.opencastproject.security.api.User) SecurityService(org.opencastproject.security.api.SecurityService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 65 with DefaultOrganization

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);
}
Also used : SchedulerService(org.opencastproject.scheduler.api.SchedulerService) Opt(com.entwinemedia.fn.data.Opt) AuthorizationService(org.opencastproject.security.api.AuthorizationService) SecurityService(org.opencastproject.security.api.SecurityService) JaxbUser(org.opencastproject.security.api.JaxbUser) SchedulerTransaction(org.opencastproject.scheduler.api.SchedulerService.SchedulerTransaction) URI(java.net.URI) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Aggregations

DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)88 SecurityService (org.opencastproject.security.api.SecurityService)62 Before (org.junit.Before)47 JaxbUser (org.opencastproject.security.api.JaxbUser)45 JaxbRole (org.opencastproject.security.api.JaxbRole)39 User (org.opencastproject.security.api.User)38 Organization (org.opencastproject.security.api.Organization)31 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)29 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)26 Test (org.junit.Test)24 Workspace (org.opencastproject.workspace.api.Workspace)23 HashSet (java.util.HashSet)21 ArrayList (java.util.ArrayList)20 MediaPackage (org.opencastproject.mediapackage.MediaPackage)18 File (java.io.File)17 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)17 IOException (java.io.IOException)16 MessageSender (org.opencastproject.message.broker.api.MessageSender)15 InputStream (java.io.InputStream)14 AuthorizationService (org.opencastproject.security.api.AuthorizationService)13