Search in sources :

Example 26 with JaxbUser

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

the class CommentParserTest method setUp.

@Before
public void setUp() throws Exception {
    userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
    testUser = new JaxbUser("test", "test", new DefaultOrganization());
    EasyMock.expect(userDirectoryService.loadUser(EasyMock.anyObject(String.class))).andReturn(testUser).anyTimes();
    EasyMock.replay(userDirectoryService);
}
Also used : JaxbUser(org.opencastproject.security.api.JaxbUser) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 27 with JaxbUser

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

the class EventCommentDatabaseImplTest method testGetEventsWithComments.

@Test
public void testGetEventsWithComments() throws Exception {
    Organization org1 = EasyMock.createNiceMock(Organization.class);
    EasyMock.expect(org1.getId()).andReturn("org1").anyTimes();
    EasyMock.expect(org1.getName()).andReturn("org1").anyTimes();
    Organization org2 = EasyMock.createNiceMock(Organization.class);
    EasyMock.expect(org2.getId()).andReturn("org2").anyTimes();
    EasyMock.expect(org2.getName()).andReturn("org2").anyTimes();
    EasyMock.replay(org1, org2);
    User userOrg1 = new JaxbUser("userOrg1", "default", JaxbOrganization.fromOrganization(org1));
    User userOrg2 = new JaxbUser("userOrg2", "default", JaxbOrganization.fromOrganization(org2));
    EventComment eventComment1 = EventComment.create(none(Long.class), "event1", org1.getId(), "test", userOrg1);
    EventComment eventComment2 = EventComment.create(none(Long.class), "event2", org1.getId(), "test", userOrg1);
    EventComment eventComment3 = EventComment.create(none(Long.class), "event3", org2.getId(), "test", userOrg2);
    persistence.updateComment(eventComment1);
    persistence.updateComment(eventComment2);
    persistence.updateComment(eventComment3);
    Map<String, List<String>> eventsWithComments = persistence.getEventsWithComments();
    assertEquals(2, eventsWithComments.keySet().size());
    assertTrue(eventsWithComments.keySet().contains(org1.getId()));
    assertTrue(eventsWithComments.keySet().contains(org2.getId()));
    assertTrue(eventsWithComments.get(org1.getId()).contains(eventComment1.getEventId()));
    assertTrue(eventsWithComments.get(org1.getId()).contains(eventComment2.getEventId()));
    assertTrue(eventsWithComments.get(org2.getId()).contains(eventComment3.getEventId()));
    assertFalse(eventsWithComments.get(org1.getId()).contains(eventComment3.getEventId()));
    assertFalse(eventsWithComments.get(org2.getId()).contains(eventComment1.getEventId()));
    assertFalse(eventsWithComments.get(org2.getId()).contains(eventComment2.getEventId()));
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbUser(org.opencastproject.security.api.JaxbUser) List(java.util.List) Test(org.junit.Test)

Example 28 with JaxbUser

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

the class CommentSchedulerConflictNotifierTest method setUp.

@Before
public void setUp() throws Exception {
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(IoSupport.classPathResourceAsFile("/dublincore.xml").get()).anyTimes();
    EasyMock.replay(workspace);
    EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
    EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(episodeAdapter);
    EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
    EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(extendedAdapter);
    conflictNotifier = new CommentSchedulerConflictNotifier();
    conflictNotifier.setSecurityService(securityService);
    conflictNotifier.setWorkspace(workspace);
    conflictNotifier.addCatalogUIAdapter(episodeAdapter);
    conflictNotifier.addCatalogUIAdapter(extendedAdapter);
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 29 with JaxbUser

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

the class EmailSchedulerConflictNotifierTest method setUp.

@Before
public void setUp() throws Exception {
    Dictionary<String, String> properties = new Hashtable<>();
    properties.put("to", "test@test.com");
    properties.put("subject", "Test email scheduler conflict");
    properties.put("template", "Dear Administrator,\n\nthe following recording schedules are conflicting with existing ones:\n\n${recordings}\nBye!");
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(IoSupport.classPathResourceAsFile("/dublincore.xml").get()).anyTimes();
    EasyMock.replay(workspace);
    EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
    EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(episodeAdapter);
    EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
    EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(extendedAdapter);
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bundleContext.getProperty(OpencastConstants.SERVER_URL_PROPERTY)).andReturn("http://localhost:8080").anyTimes();
    EasyMock.replay(bundleContext);
    ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
    EasyMock.expect(componentContext.getProperties()).andReturn(new Hashtable<String, Object>()).anyTimes();
    EasyMock.replay(componentContext);
    conflictNotifier = new EmailSchedulerConflictNotifier();
    conflictNotifier.setSecurityService(securityService);
    conflictNotifier.setWorkspace(workspace);
    conflictNotifier.addCatalogUIAdapter(episodeAdapter);
    conflictNotifier.addCatalogUIAdapter(extendedAdapter);
    conflictNotifier.activate(componentContext);
    conflictNotifier.updated(properties);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 30 with JaxbUser

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

the class WorkflowServiceSolrIndexTest method testNonAdminQuery.

/**
 * Tests whether a simple query is built correctly with the authentication fragment
 */
@Test
public void testNonAdminQuery() throws Exception {
    String userRole = "ROLE_USER";
    User nonAdminUser = new JaxbUser("noAdmin", "test", new DefaultOrganization(), new JaxbRole(userRole, new DefaultOrganization()));
    // security service
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(nonAdminUser).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    dao.setSecurityService(securityService);
    WorkflowQuery q = new WorkflowQuery().withMediaPackage("123").withSeriesId("series1");
    String solrQuery = dao.createQuery(q, Permissions.Action.READ.toString(), true);
    String expected = "oc_org:mh_default_org AND mediapackageid:123 AND seriesid:series1 AND oc_org:" + DefaultOrganization.DEFAULT_ORGANIZATION_ID + " AND (oc_creator:" + nonAdminUser.getUsername() + " OR oc_acl_read:" + userRole + ")";
    assertEquals(expected, solrQuery);
}
Also used : WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) 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) 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