use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class SearchServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
// workspace
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
return new File(new URI(EasyMock.getCurrentArguments()[0].toString()));
}
}).anyTimes();
EasyMock.replay(workspace);
// User, organization and service registry
userResponder = new Responder<User>(defaultUser);
organizationResponder = new Responder<Organization>(defaultOrganization);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andAnswer(userResponder).anyTimes();
EasyMock.expect(securityService.getOrganization()).andAnswer(organizationResponder).anyTimes();
EasyMock.replay(securityService);
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);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
// mpeg7 service
Mpeg7CatalogService mpeg7CatalogService = new Mpeg7CatalogService();
// Persistence storage
searchDatabase = new SearchServiceDatabaseImpl();
searchDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SearchServiceDatabaseImpl.PERSISTENCE_UNIT));
searchDatabase.activate(null);
searchDatabase.setSecurityService(securityService);
// search service
service = new SearchServiceImpl();
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
StaticMetadataService mdService = newStaticMetadataService(workspace);
SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
DublinCoreCatalog seriesCatalog = getSeriesDublinCoreCatalog("/series-dublincore.xml");
AccessControlList seriesAcl = new AccessControlList();
EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andReturn(seriesCatalog).anyTimes();
EasyMock.expect(seriesService.getSeriesAccessControl((String) EasyMock.anyObject())).andReturn(seriesAcl).anyTimes();
EasyMock.replay(seriesService);
service.setStaticMetadataService(mdService);
service.setWorkspace(workspace);
service.setMpeg7CatalogService(mpeg7CatalogService);
service.setSecurityService(securityService);
service.setOrganizationDirectoryService(organizationDirectoryService);
service.setUserDirectoryService(userDirectoryService);
service.setServiceRegistry(serviceRegistry);
service.setPersistence(searchDatabase);
SolrServer solrServer = SearchServiceImpl.setupSolr(new File(solrRoot));
service.testSetup(solrServer, new SolrRequester(solrServer, securityService), new SolrIndexManager(solrServer, workspace, Arrays.asList(mdService), seriesService, mpeg7CatalogService, securityService));
// acl
String anonymousRole = securityService.getOrganization().getAnonymousRole();
acl = new AccessControlList(new AccessControlEntry(anonymousRole, Permissions.Action.READ.toString(), true));
authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.expect(authorizationService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(true).anyTimes();
service.setAuthorizationService(authorizationService);
EasyMock.replay(authorizationService);
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class SearchServiceImpl method populateIndex.
protected void populateIndex(String systemUserName) {
long instancesInSolr = 0L;
try {
instancesInSolr = indexManager.count();
} catch (Exception e) {
throw new IllegalStateException(e);
}
if (instancesInSolr > 0) {
logger.debug("Search index found");
return;
}
if (instancesInSolr == 0L) {
logger.info("No search index found");
logger.info("Starting population of search index from database");
Iterator<Tuple<MediaPackage, String>> mediaPackages;
try {
mediaPackages = persistence.getAllMediaPackages();
} catch (SearchServiceDatabaseException e) {
logger.error("Unable to load the search entries: {}", e.getMessage());
throw new ServiceException(e.getMessage());
}
int errors = 0;
while (mediaPackages.hasNext()) {
try {
Tuple<MediaPackage, String> mediaPackage = mediaPackages.next();
String mediaPackageId = mediaPackage.getA().getIdentifier().toString();
Organization organization = organizationDirectory.getOrganization(mediaPackage.getB());
securityService.setOrganization(organization);
securityService.setUser(SecurityUtil.createSystemUser(systemUserName, organization));
AccessControlList acl = persistence.getAccessControlList(mediaPackageId);
Date modificationDate = persistence.getModificationDate(mediaPackageId);
Date deletionDate = persistence.getDeletionDate(mediaPackageId);
indexManager.add(mediaPackage.getA(), acl, deletionDate, modificationDate);
} catch (Exception e) {
logger.error("Unable to index search instances:", e);
if (retryToPopulateIndex(systemUserName)) {
logger.warn("Trying to re-index search index later. Aborting for now.");
return;
}
errors++;
} finally {
securityService.setOrganization(null);
securityService.setUser(null);
}
}
if (errors > 0)
logger.error("Skipped {} erroneous search entries while populating the search index", errors);
logger.info("Finished populating search index");
}
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class SchedulerServiceImpl method removeTransactionsAfterRestart.
/**
* Remove incomplete transactions after a restart
*/
private void removeTransactionsAfterRestart() {
logger.info("Checking for incomplete transactions from a shutdown or restart.");
for (final Organization org : orgDirectoryService.getOrganizations()) {
SecurityUtil.runAs(securityService, org, SecurityUtil.createSystemUser(systemUserName, org), new Effect0() {
private void rollbackTransaction(String transactionID) throws NotFoundException, UnauthorizedException, SchedulerException {
SchedulerTransaction transaction = getTransaction(transactionID);
logger.info("Rolling back transaction with id: {}", transactionID);
transaction.rollback();
logger.info("Finished rolling back transaction with id: {}", transactionID);
}
@Override
protected void run() {
try {
for (String transactionID : persistence.getTransactions()) {
try {
rollbackTransaction(transactionID);
} catch (NotFoundException e) {
logger.info("Unable to find the transaction with id {}, so it wasn't rolled back.", transactionID);
} catch (UnauthorizedException e) {
logger.error("Unable to delete transaction with id: {} using organization {} because: {}", new Object[] { transactionID, org, getStackTrace(e) });
} catch (Exception e) {
logger.error("Unable to rollback transaction because: {}", getStackTrace(e));
}
}
} catch (SchedulerServiceDatabaseException e) {
logger.error("Unable to get transactions to cleanup incomplete transactions because: {}", getStackTrace(e));
}
}
});
}
logger.info("Finished checking for incomplete transactions from a shutdown or a restart.");
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class JobTest method setUp.
@Before
public void setUp() throws Exception {
final EntityManagerFactory emf = newTestEntityManagerFactory(ServiceRegistryJpaImpl.PERSISTENCE_UNIT);
serviceRegistry = new ServiceRegistryJpaImpl();
serviceRegistry.setEntityManagerFactory(emf);
serviceRegistry.activate(null);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
serviceRegistry.setOrganizationDirectoryService(organizationDirectoryService);
JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
User anonymous = new JaxbUser("anonymous", "test", jaxbOrganization, new JaxbRole(jaxbOrganization.getAnonymousRole(), jaxbOrganization));
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
serviceRegistry.setSecurityService(securityService);
// register the hosts
serviceRegistry.registerHost(LOCALHOST, "127.0.0.1", 1024, 1, 1.0f);
serviceRegistry.registerHost(REMOTEHOST, "127.0.0.1", 1024, 1, 1.0f);
// register some service instances
regType1Localhost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_1, LOCALHOST, PATH);
regType1Remotehost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_1, REMOTEHOST, PATH);
regType2Localhost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_2, LOCALHOST, PATH);
regType2Remotehost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_2, REMOTEHOST, PATH);
penv = persistenceEnvironment(emf);
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class WorkflowServiceImplTest method setupMockOrganizationDirectoryService.
private OrganizationDirectoryService setupMockOrganizationDirectoryService() {
List<Organization> organizations = new LinkedList<Organization>();
organizations.add(securityService.getOrganization());
OrganizationDirectoryService orgDirService = EasyMock.createMock(OrganizationDirectoryService.class);
expect(orgDirService.getOrganizations()).andReturn(organizations).anyTimes();
replay(orgDirService);
return orgDirService;
}
Aggregations