Search in sources :

Example 66 with User

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

the class EventCommentDto method toComment.

/**
 * Returns the business object of this comment
 *
 * @return the business object model of this comment
 */
public EventComment toComment(UserDirectoryService userDirectoryService) {
    User user = userDirectoryService.loadUser(author);
    EventComment comment = EventComment.create(Option.option(id), eventId, organization, text, user, reason, resolvedStatus, creationDate, modificationDate);
    for (EventCommentReplyDto reply : replies) {
        comment.addReply(reply.toCommentReply(userDirectoryService));
    }
    return comment;
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) User(org.opencastproject.security.api.User)

Example 67 with User

use of org.opencastproject.security.api.User 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 68 with User

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

the class OaiPmhRepositoryPersistenceTest method oaiPmhDatabase.

private static AbstractOaiPmhDatabase oaiPmhDatabase(MediaPackage... mps) {
    try {
        final Organization org = new DefaultOrganization();
        final SecurityService secSvc = EasyMock.createNiceMock(SecurityService.class);
        // security service
        final User user = createSystemUser("admin", org);
        expect(secSvc.getOrganization()).andReturn(org).anyTimes();
        expect(secSvc.getUser()).andReturn(user).anyTimes();
        EasyMock.replay(secSvc);
        // series service
        final SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
        final String xacml = IOUtils.toString(OaiPmhRepositoryPersistenceTest.class.getResource("/xacml.xml").toURI());
        final AccessControlList securityACL = AccessControlParser.parseAcl(xacml);
        EasyMock.expect(seriesService.getSeriesAccessControl("10.0000/1")).andReturn(securityACL).anyTimes();
        EasyMock.replay(seriesService);
        // workspace
        final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
        final File episodeDublinCore = new File(OaiPmhRepositoryPersistenceTest.class.getResource("/episode-dublincore.xml").toURI());
        final File seriesDublinCore = new File(OaiPmhRepositoryPersistenceTest.class.getResource("/series-dublincore.xml").toURI());
        expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> {
            final String uri = getCurrentArguments()[0].toString();
            if ("dublincore.xml".equals(uri))
                return new FileInputStream(episodeDublinCore);
            if ("series-dublincore.xml".equals(uri))
                return new FileInputStream(seriesDublinCore);
            throw new Error("Workspace mock does not know about file " + uri);
        }).anyTimes();
        EasyMock.replay(workspace);
        // oai-pmh database
        final EntityManagerFactory emf = PersistenceUtil.newTestEntityManagerFactory(OaiPmhDatabaseImpl.PERSISTENCE_UNIT_NAME);
        final AbstractOaiPmhDatabase db = new AbstractOaiPmhDatabase() {

            @Override
            public EntityManagerFactory getEmf() {
                return emf;
            }

            @Override
            public SecurityService getSecurityService() {
                return secSvc;
            }

            @Override
            public Workspace getWorkspace() {
                return workspace;
            }

            @Override
            public Date currentDate() {
                return new Date();
            }
        };
        for (MediaPackage mp : mps) db.store(mp, REPOSITORY_ID);
        return db;
    } catch (Exception e) {
        return chuck(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AbstractOaiPmhDatabase(org.opencastproject.oaipmh.persistence.impl.AbstractOaiPmhDatabase) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) User(org.opencastproject.security.api.User) SecurityUtil.createSystemUser(org.opencastproject.security.util.SecurityUtil.createSystemUser) FileInputStream(java.io.FileInputStream) Date(java.util.Date) EncodingSchemeUtils.encodeDate(org.opencastproject.metadata.dublincore.EncodingSchemeUtils.encodeDate) TransformerException(javax.xml.transform.TransformerException) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) EntityManagerFactory(javax.persistence.EntityManagerFactory) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace)

Example 69 with User

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

the class WorkflowServiceImpl method fireListeners.

/**
 * Fires the workflow listeners on workflow updates.
 */
protected void fireListeners(final WorkflowInstance oldWorkflowInstance, final WorkflowInstance newWorkflowInstance) {
    final User currentUser = securityService.getUser();
    final Organization currentOrganization = securityService.getOrganization();
    for (final WorkflowListener listener : listeners) {
        if (oldWorkflowInstance == null || !oldWorkflowInstance.getState().equals(newWorkflowInstance.getState())) {
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    try {
                        securityService.setUser(currentUser);
                        securityService.setOrganization(currentOrganization);
                        listener.stateChanged(newWorkflowInstance);
                    } finally {
                        securityService.setUser(null);
                        securityService.setOrganization(null);
                    }
                }
            };
            executorService.execute(runnable);
        } else {
            logger.debug("Not notifying %s because the workflow state has not changed", listener);
        }
        if (newWorkflowInstance.getCurrentOperation() != null) {
            if (oldWorkflowInstance == null || oldWorkflowInstance.getCurrentOperation() == null || !oldWorkflowInstance.getCurrentOperation().equals(newWorkflowInstance.getCurrentOperation())) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        try {
                            securityService.setUser(currentUser);
                            securityService.setOrganization(currentOrganization);
                            listener.operationChanged(newWorkflowInstance);
                        } finally {
                            securityService.setUser(null);
                            securityService.setOrganization(null);
                        }
                    }
                };
                executorService.execute(runnable);
            }
        } else {
            logger.debug("Not notifying %s because the workflow operation has not changed", listener);
        }
    }
}
Also used : User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) WorkflowListener(org.opencastproject.workflow.api.WorkflowListener)

Example 70 with User

use of org.opencastproject.security.api.User 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

User (org.opencastproject.security.api.User)156 Organization (org.opencastproject.security.api.Organization)61 JaxbUser (org.opencastproject.security.api.JaxbUser)60 JaxbRole (org.opencastproject.security.api.JaxbRole)49 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)44 SecurityService (org.opencastproject.security.api.SecurityService)43 NotFoundException (org.opencastproject.util.NotFoundException)32 Before (org.junit.Before)31 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)26 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)24 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)23 AccessControlList (org.opencastproject.security.api.AccessControlList)21 Role (org.opencastproject.security.api.Role)21 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)21 HashSet (java.util.HashSet)20 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)18 JpaUser (org.opencastproject.security.impl.jpa.JpaUser)17 IOException (java.io.IOException)16 MediaPackage (org.opencastproject.mediapackage.MediaPackage)16