Search in sources :

Example 11 with JaxbUser

use of org.opencastproject.security.api.JaxbUser 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);
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) SecurityService(org.opencastproject.security.api.SecurityService) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 12 with JaxbUser

use of org.opencastproject.security.api.JaxbUser 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);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) ComponentContext(org.osgi.service.component.ComponentContext) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) File(java.io.File) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 13 with JaxbUser

use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.

the class MailServiceTest method setUp.

@Before
public void setUp() throws Exception {
    // Set up the mail service
    User user = new JaxbUser("test", null, "Test User", "test@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
    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);
    mailService = new MailService();
    mailService.setUserDirectoryService(userDirectoryService);
    mailService.setSecurityService(securityService);
    mailService.setEntityManagerFactory(newTestEntityManagerFactory(MailService.PERSISTENCE_UNIT));
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) Before(org.junit.Before)

Example 14 with JaxbUser

use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.

the class MailServiceTest method testCRUDMessageTemplate.

@Test
public void testCRUDMessageTemplate() {
    User admin = new JaxbUser("george@test.com", null, "George", "george@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
    User student = new JaxbUser("frank@test.com", null, "Frank", "frank@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
    String name = "Invitation";
    MessageTemplate msgTmpl1 = new MessageTemplate(name, student, "Course invitation", "Please watch this course recording.");
    MessageTemplate msgTmpl2 = new MessageTemplate("Acknowledge 1", admin, "Recording ready!", "The recording of the course XYZ is finished. Please review it.");
    msgTmpl2.setType(TemplateType.Type.ACKNOWLEDGE.getType());
    msgTmpl2.setHidden(true);
    MessageTemplate msgTmpl3 = new MessageTemplate("Acknowledge 2", admin, "Recording ready!", "The recording of the course ZYX is finished. Please review it.");
    msgTmpl3.setType(TemplateType.Type.ACKNOWLEDGE.getType());
    // Create
    try {
        msgTmpl1 = mailService.updateMessageTemplate(msgTmpl1);
        msgTmpl2 = mailService.updateMessageTemplate(msgTmpl2);
        msgTmpl3 = mailService.updateMessageTemplate(msgTmpl3);
    } catch (MailServiceException e) {
        fail("Not able to save a message template entity: " + e.getMessage());
    }
    // Read
    TemplateMessageQuery query = new TemplateMessageQuery();
    // Search without hidden
    List<MessageTemplate> savedMsgTemplates = mailService.findMessageTemplates(query);
    assertEquals(2, savedMsgTemplates.size());
    // Search with hidden
    query.withIncludeHidden();
    savedMsgTemplates = mailService.findMessageTemplates(query);
    assertEquals(3, savedMsgTemplates.size());
    // Search with only the creator admin
    query.withCreator(admin.getUsername());
    savedMsgTemplates = mailService.findMessageTemplates(query);
    assertEquals(2, savedMsgTemplates.size());
    assertTrue(savedMsgTemplates.contains(msgTmpl2) && savedMsgTemplates.contains(msgTmpl3));
    // Search with only creator student (no template)
    query.withCreator(student.getUsername());
    savedMsgTemplates = mailService.findMessageTemplates(query);
    assertEquals(1, savedMsgTemplates.size());
    assertEquals(msgTmpl1, savedMsgTemplates.get(0));
    // Search with only the name
    query.withCreator(null);
    query.withName(name);
    savedMsgTemplates = mailService.findMessageTemplates(query);
    assertEquals(1, savedMsgTemplates.size());
    assertTrue(msgTmpl1.equals(savedMsgTemplates.get(0)));
    // Search with only the type
    query.withName(null);
    query.withType(msgTmpl1.getType().getType());
    savedMsgTemplates = mailService.findMessageTemplates(query);
    assertEquals(1, savedMsgTemplates.size());
    assertTrue(msgTmpl1.equals(savedMsgTemplates.get(0)));
    // Search with only fullText
    query.withType(null);
    query.withFullText("ready");
    savedMsgTemplates = mailService.findMessageTemplates(query);
    assertEquals(2, savedMsgTemplates.size());
    assertTrue(savedMsgTemplates.contains(msgTmpl2) && savedMsgTemplates.contains(msgTmpl3));
    // Search with different options
    query.withCreator(admin.getUsername());
    query.withType(TemplateType.Type.ACKNOWLEDGE);
    query.withFullText("ready");
    savedMsgTemplates = mailService.findMessageTemplates(query);
    assertEquals(2, savedMsgTemplates.size());
    assertTrue(savedMsgTemplates.contains(msgTmpl2) && savedMsgTemplates.contains(msgTmpl3));
    // Update
    try {
        msgTmpl2.setSubject("Informations");
        msgTmpl2 = mailService.updateMessageTemplate(msgTmpl2);
        query.withCreator(null);
        query.withType(null);
        query.withFullText(null);
        savedMsgTemplates = mailService.findMessageTemplates(query);
        assertEquals(3, savedMsgTemplates.size());
        assertTrue(savedMsgTemplates.contains(msgTmpl2));
    } catch (MailServiceException e) {
        fail("Not able to save a message template entity: " + e.getMessage());
    }
    // Delete
    try {
        mailService.deleteMessageTemplate(msgTmpl2.getId());
        savedMsgTemplates = mailService.findMessageTemplates(query);
        assertEquals(2, savedMsgTemplates.size());
        assertTrue(savedMsgTemplates.contains(msgTmpl1) && savedMsgTemplates.contains(msgTmpl3));
    } catch (Exception e) {
        fail("Not able to get the message template entity " + msgTmpl2.getName() + " : " + e.getMessage());
    }
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbUser(org.opencastproject.security.api.JaxbUser) NotFoundException(org.opencastproject.util.NotFoundException) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 15 with JaxbUser

use of org.opencastproject.security.api.JaxbUser in project opencast by opencast.

the class MessageSenderImplTest method testSendSerializableObjectMessage.

@Test
public void testSendSerializableObjectMessage() throws JMSException {
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization());
    EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser()).anyTimes();
    Serializable serailizableObject = new Long(20L);
    ObjectMessage objectMessage = EasyMock.createMock(ObjectMessage.class);
    EasyMock.expect(objectMessage.getObject()).andReturn(serailizableObject);
    // Create MessageProducer
    MessageProducer messageProducer = EasyMock.createMock(MessageProducer.class);
    messageProducer.send(EasyMock.anyObject(Destination.class), EasyMock.eq(objectMessage));
    EasyMock.expectLastCall();
    // Create queue.
    Queue queue = EasyMock.createMock(Queue.class);
    // Create session.
    Session session = EasyMock.createMock(Session.class);
    EasyMock.expect(session.createQueue(destinationId)).andReturn(queue);
    EasyMock.expect(session.createProducer(queue)).andReturn(messageProducer);
    EasyMock.expect(session.createObjectMessage((Serializable) EasyMock.anyObject())).andReturn(objectMessage);
    session.close();
    EasyMock.expectLastCall();
    // Replay all of the mocks
    EasyMock.replay(objectMessage, messageProducer, queue, session, securityService);
    MockMessageSender messageSenderImpl = new MockMessageSender(session, messageProducer);
    messageSenderImpl.setSecurityService(securityService);
    messageSenderImpl.enable(true);
    messageSenderImpl.sendObjectMessage(destinationId, DestinationType.Queue, serailizableObject);
}
Also used : Destination(javax.jms.Destination) Serializable(java.io.Serializable) SecurityService(org.opencastproject.security.api.SecurityService) ObjectMessage(javax.jms.ObjectMessage) JaxbUser(org.opencastproject.security.api.JaxbUser) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

JaxbUser (org.opencastproject.security.api.JaxbUser)63 JaxbRole (org.opencastproject.security.api.JaxbRole)54 User (org.opencastproject.security.api.User)47 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)46 SecurityService (org.opencastproject.security.api.SecurityService)44 Before (org.junit.Before)34 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)21 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)19 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)19 Test (org.junit.Test)15 Organization (org.opencastproject.security.api.Organization)15 Workspace (org.opencastproject.workspace.api.Workspace)15 HashSet (java.util.HashSet)14 URI (java.net.URI)12 BundleContext (org.osgi.framework.BundleContext)12 ComponentContext (org.osgi.service.component.ComponentContext)12 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)11 File (java.io.File)10 Job (org.opencastproject.job.api.Job)8 InputStream (java.io.InputStream)7