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;
}
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()));
}
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);
}
}
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);
}
}
}
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);
}
Aggregations