Search in sources :

Example 71 with SecurityService

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

the class PublishEngageWorkflowOperationHandlerTest method testDefaultPlayerPath.

@Test
public void testDefaultPlayerPath() throws URISyntaxException {
    URI engageURI = new URI("http://engage.org");
    String mpId = "mp-id";
    MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
    Id id = new IdImpl(mpId);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(getOrgWithoutPlayerPath()).once();
    EasyMock.replay(element, mp, securityService);
    // Test default player path
    PublishEngageWorkflowOperationHandler publishEngagePublish = new PublishEngageWorkflowOperationHandler();
    publishEngagePublish.setSecurityService(securityService);
    URI result = publishEngagePublish.createEngageUri(engageURI, mp);
    assertEquals(engageURI.toString() + PublishEngageWorkflowOperationHandler.DEFAULT_PLAYER_PATH + "?id=" + mpId, result.toString());
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Test(org.junit.Test)

Example 72 with SecurityService

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

the class PublishEngageWorkflowOperationHandlerTest method testPlayerUrl.

@Test
public void testPlayerUrl() throws WorkflowOperationException, URISyntaxException {
    URI engageURI = new URI("http://engage.org");
    String mpId = "mp-id";
    MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
    Id id = new IdImpl(mpId);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(getOrgWithPlayerPath()).once();
    EasyMock.replay(element, mp, securityService);
    // Test configured organization player path
    PublishEngageWorkflowOperationHandler publishEngagePublish = new PublishEngageWorkflowOperationHandler();
    publishEngagePublish.setSecurityService(securityService);
    URI result = publishEngagePublish.createEngageUri(engageURI, mp);
    assertEquals(engageURI.toString() + examplePlayer + "?id=" + mpId, result.toString());
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Test(org.junit.Test)

Example 73 with SecurityService

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

the class ConfigurablePublishWorkflowOperationHandlerTest method testTemplateReplacement.

@Test
public void testTemplateReplacement() throws WorkflowOperationException, URISyntaxException {
    URI elementUri = new URI("http://element.com/path/to/element/element.mp4");
    String mpId = "mp-id";
    String pubUUID = "test-uuid";
    String seriesId = "series-id";
    MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
    Id id = new IdImpl(mpId);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
    EasyMock.expect(element.getURI()).andStubReturn(elementUri);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andStubReturn(org);
    EasyMock.replay(element, mp, securityService);
    // Test player path and mediapackage id
    ConfigurablePublishWorkflowOperationHandler configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    URI result = configurePublish.populateUrlWithVariables("${player_path}${event_id}", mp, pubUUID);
    assertEquals(examplePlayer + "mp-id", result.toString());
    // Test without series
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${series_id}/${event_id}", mp, pubUUID);
    assertEquals("/mp-id", result.toString());
    // Test with series
    mp = EasyMock.createNiceMock(MediaPackage.class);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    EasyMock.expect(mp.getSeries()).andStubReturn(seriesId);
    EasyMock.replay(mp);
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${series_id}/${event_id}", mp, pubUUID);
    assertEquals("series-id/mp-id", result.toString());
    // Test publication uuid
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${publication_id}", mp, pubUUID);
    assertEquals(pubUUID, result.toString());
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Test(org.junit.Test)

Example 74 with SecurityService

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

the class CommentWorkflowOperationHandlerTest method testDuplicateComments.

@Test
public void testDuplicateComments() throws WorkflowOperationException, EventCommentException {
    // Testing that a duplicate comment won't be created but a different one will still be created.
    Long workflowId = 10L;
    String mediaPackageId = "abc-def";
    String action = "create";
    String reason = "Waiting for Trim";
    String description = "The comment description";
    Organization org = createNiceMock(Organization.class);
    expect(org.getId()).andStubReturn("demo");
    replay(org);
    SecurityService secSrv = createNiceMock(SecurityService.class);
    expect(secSrv.getOrganization()).andStubReturn(org);
    replay(secSrv);
    // Setup WorkflowOperation Instance
    WorkflowOperationInstance workflowOperationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(action).anyTimes();
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.REASON)).andReturn(reason).anyTimes();
    EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.DESCRIPTION)).andReturn(description).anyTimes();
    // Setup mediaPackage
    MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
    EasyMock.expect(mediaPackage.getIdentifier()).andReturn(new IdImpl(mediaPackageId)).anyTimes();
    // Setup user
    User creator = EasyMock.createMock(User.class);
    // Setup WorkflowInstance
    WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getId()).andReturn(workflowId).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(workflowOperationInstance).anyTimes();
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getCreator()).andReturn(creator).anyTimes();
    // Test no previous comments
    EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>());
    Capture<EventComment> comment = EasyMock.newCapture();
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
    EasyMock.replay(creator, eventCommentService, mediaPackage, workflowInstance, workflowOperationInstance);
    CommentWorkflowOperationHandler commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
    // Test previous comment with same reason and description
    List<EventComment> comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(13L), mediaPackageId, org.getId(), description, creator, reason, true));
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments);
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
    // Test previous comment with different reasons and descriptions
    comments = new ArrayList<EventComment>();
    comments.add(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), "Different description", creator, reason, true));
    comments.add(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator, "Different reason", true));
    eventCommentService = EasyMock.createMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments);
    comment = EasyMock.newCapture();
    EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
    EasyMock.replay(eventCommentService);
    commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
    commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
    commentWorkflowOperationHandler.setSecurityService(secSrv);
    commentWorkflowOperationHandler.start(workflowInstance, null);
    assertTrue(comment.hasCaptured());
    assertEquals(creator, comment.getValue().getAuthor());
    assertEquals(description, comment.getValue().getText());
    assertEquals(reason, comment.getValue().getReason());
}
Also used : Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) EventComment(org.opencastproject.event.comment.EventComment) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) EventCommentService(org.opencastproject.event.comment.EventCommentService) Test(org.junit.Test)

Example 75 with SecurityService

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

the class CaptureAgentStateServiceImplTest method setupService.

private void setupService() throws Exception {
    service = new CaptureAgentStateServiceImpl();
    service.setEntityManagerFactory(newTestEntityManagerFactory(CaptureAgentStateServiceImpl.PERSISTENCE_UNIT));
    DefaultOrganization organization = new DefaultOrganization();
    HashSet<JaxbRole> roles = new HashSet<>();
    roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, organization, ""));
    User user = new JaxbUser("testuser", "test", organization, roles);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    setupCC();
    service.activate(cc);
    service.setupAgentCache(1, TimeUnit.HOURS);
}
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)

Aggregations

SecurityService (org.opencastproject.security.api.SecurityService)99 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)62 Before (org.junit.Before)55 JaxbUser (org.opencastproject.security.api.JaxbUser)44 User (org.opencastproject.security.api.User)43 JaxbRole (org.opencastproject.security.api.JaxbRole)39 Organization (org.opencastproject.security.api.Organization)31 Test (org.junit.Test)30 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)29 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)29 Workspace (org.opencastproject.workspace.api.Workspace)29 MediaPackage (org.opencastproject.mediapackage.MediaPackage)22 InputStream (java.io.InputStream)21 URI (java.net.URI)21 File (java.io.File)20 ArrayList (java.util.ArrayList)20 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)18 MessageSender (org.opencastproject.message.broker.api.MessageSender)16 AuthorizationService (org.opencastproject.security.api.AuthorizationService)16 IOException (java.io.IOException)15