use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class SeriesServiceSolrTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// Mock up a security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
JaxbOrganization org = new JaxbOrganization("mh-default-org");
User user = new JaxbUser("admin", "test", org, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org));
EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
index = new SeriesServiceSolrIndex();
index.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
dcService = new DublinCoreCatalogService();
index.setDublinCoreService(dcService);
index.setSecurityService(securityService);
index.activate(null);
InputStream in = null;
try {
in = getClass().getResourceAsStream("/dublincore.xml");
testCatalog = dcService.load(in);
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class WorkflowServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
// always start with a fresh solr root directory
sRoot = new File(getStorageRoot());
try {
FileUtils.forceMkdir(sRoot);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
// create operation handlers for our workflows
succeedingOperationHandler = new SucceedingWorkflowOperationHandler();
failingOperationHandler = new FailingWorkflowOperationHandler();
handlerRegistrations = new HashSet<HandlerRegistration>();
handlerRegistrations.add(new HandlerRegistration("op1", succeedingOperationHandler));
handlerRegistrations.add(new HandlerRegistration("op2", succeedingOperationHandler));
handlerRegistrations.add(new HandlerRegistration("op3", failingOperationHandler));
handlerRegistrations.add(new HandlerRegistration(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID, new ErrorResolutionWorkflowOperationHandler()));
handlerRegistrations.add(new HandlerRegistration("opPause", new ResumableTestWorkflowOperationHandler()));
handlerRegistrations.add(new HandlerRegistration("failOnHost", new FailOnHostWorkflowOperationHandler()));
handlerRegistrations.add(new HandlerRegistration("failOneTime", new FailOnceWorkflowOperationHandler()));
handlerRegistrations.add(new HandlerRegistration("failTwice", new FailTwiceWorkflowOperationHandler()));
scanner = new WorkflowDefinitionScanner();
// instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
service = new WorkflowServiceImpl() {
@Override
public Set<HandlerRegistration> getRegisteredHandlers() {
return handlerRegistrations;
}
};
// Add scanner to activate workflow service and store definitions
service.addWorkflowDefinitionScanner(scanner);
// security service
DefaultOrganization organization = new DefaultOrganization();
securityService = createNiceMock(SecurityService.class);
expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
expect(securityService.getOrganization()).andReturn(organization).anyTimes();
replay(securityService);
service.setSecurityService(securityService);
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
replay(userDirectoryService);
service.setUserDirectoryService(userDirectoryService);
AuthorizationService authzService = createNiceMock(AuthorizationService.class);
expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
replay(authzService);
service.setAuthorizationService(authzService);
List<Organization> organizationList = new ArrayList<Organization>();
organizationList.add(organization);
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(securityService.getOrganization()).anyTimes();
expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
MediaPackageMetadataService mds = createNiceMock(MediaPackageMetadataService.class);
replay(mds);
service.addMetadataService(mds);
workspace = createNiceMock(Workspace.class);
expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
replay(workspace);
IncidentService incidentService = createNiceMock(IncidentService.class);
replay(incidentService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, incidentService);
serviceRegistry.registerHost(REMOTE_HOST, REMOTE_HOST, Runtime.getRuntime().totalMemory(), Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors());
serviceRegistry.registerService(REMOTE_SERVICE, REMOTE_HOST, "/path", true);
service.setWorkspace(workspace);
MessageSender messageSender = createNiceMock(MessageSender.class);
replay(messageSender);
dao = new WorkflowServiceSolrIndex();
dao.setServiceRegistry(serviceRegistry);
dao.setSecurityService(securityService);
dao.setOrgDirectory(organizationDirectoryService);
dao.setAuthorizationService(authzService);
dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
dao.activate("System Admin");
service.setDao(dao);
service.setServiceRegistry(serviceRegistry);
service.setMessageSender(messageSender);
service.activate(null);
InputStream is = null;
try {
is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-1.xml");
workingDefinition = WorkflowParser.parseWorkflowDefinition(is);
IOUtils.closeQuietly(is);
is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-2.xml");
failingDefinitionWithoutErrorHandler = WorkflowParser.parseWorkflowDefinition(is);
IOUtils.closeQuietly(is);
is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-3.xml");
failingDefinitionWithErrorHandler = WorkflowParser.parseWorkflowDefinition(is);
IOUtils.closeQuietly(is);
is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-4.xml");
pausingWorkflowDefinition = WorkflowParser.parseWorkflowDefinition(is);
IOUtils.closeQuietly(is);
service.registerWorkflowDefinition(workingDefinition);
service.registerWorkflowDefinition(failingDefinitionWithoutErrorHandler);
service.registerWorkflowDefinition(failingDefinitionWithErrorHandler);
service.registerWorkflowDefinition(pausingWorkflowDefinition);
MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
is = WorkflowServiceImplTest.class.getResourceAsStream("/mediapackage-1.xml");
mediapackage1 = mediaPackageBuilder.loadFromXml(is);
IOUtils.closeQuietly(is);
is = WorkflowServiceImplTest.class.getResourceAsStream("/mediapackage-2.xml");
mediapackage2 = mediaPackageBuilder.loadFromXml(is);
Assert.assertNotNull(mediapackage1.getIdentifier());
Assert.assertNotNull(mediapackage2.getIdentifier());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class WorkingFileRepositoryRestEndpointTest method setUp.
@Before
public void setUp() throws Exception {
Organization organization = EasyMock.createMock(Organization.class);
EasyMock.expect(organization.getId()).andReturn("org1").anyTimes();
Map<String, String> orgProps = new HashMap<String, String>();
orgProps.put(OpencastConstants.WFR_URL_ORG_PROPERTY, UrlSupport.DEFAULT_BASE_URL);
EasyMock.expect(organization.getProperties()).andReturn(orgProps).anyTimes();
EasyMock.replay(organization);
SecurityService securityService = EasyMock.createMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
endpoint = new WorkingFileRepositoryRestEndpoint();
endpoint.setSecurityService(securityService);
endpoint.rootDirectory = "target/endpointroot";
FileUtils.forceMkdir(new File(endpoint.rootDirectory));
endpoint.serverUrl = UrlSupport.DEFAULT_BASE_URL;
endpoint.servicePath = WorkingFileRepositoryImpl.URI_PREFIX;
endpoint.setTikaParser(new AutoDetectParser());
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class WorkingFileRepositoryTest method setUp.
@Before
public void setUp() throws Exception {
Organization organization = EasyMock.createMock(Organization.class);
EasyMock.expect(organization.getId()).andReturn("org1").anyTimes();
Map<String, String> orgProps = new HashMap<String, String>();
orgProps.put(OpencastConstants.WFR_URL_ORG_PROPERTY, UrlSupport.DEFAULT_BASE_URL);
EasyMock.expect(organization.getProperties()).andReturn(orgProps).anyTimes();
EasyMock.replay(organization);
SecurityService securityService = EasyMock.createMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
repo.setSecurityService(securityService);
repo.rootDirectory = "target" + File.separator + "repotest";
repo.serverUrl = UrlSupport.DEFAULT_BASE_URL;
repo.servicePath = WorkingFileRepositoryImpl.URI_PREFIX;
repo.createRootDirectory();
// Put an image file into the repository using the mediapackage / element storage
InputStream in = null;
try {
in = getClass().getClassLoader().getResourceAsStream("opencast_header.gif");
repo.put(mediaPackageID, mediaPackageElementID, "opencast_header.gif", in);
} finally {
IOUtils.closeQuietly(in);
}
// Repeat the put
try {
in = getClass().getClassLoader().getResourceAsStream("opencast_header.gif");
repo.put(mediaPackageID, mediaPackageElementID, "opencast_header.gif", in);
} finally {
IOUtils.closeQuietly(in);
}
// Put an image file into the repository into a collection
try {
in = getClass().getClassLoader().getResourceAsStream("opencast_header.gif");
repo.putInCollection(collectionId, filename, in);
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.opencastproject.security.api.SecurityService in project opencast by opencast.
the class JpaGroupRoleProviderTest method testRemoveGroupNotAllowedAsNonAdminUser.
@Test
public void testRemoveGroupNotAllowedAsNonAdminUser() throws UnauthorizedException {
JpaGroup group = new JpaGroup("test", org1, "Test", "Test group", Collections.set(new JpaRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org1)));
try {
provider.addGroup(group);
Group loadGroup = provider.loadGroup(group.getGroupId(), group.getOrganization().getId());
assertNotNull(loadGroup);
assertEquals(group.getGroupId(), loadGroup.getGroupId());
} catch (Exception e) {
fail("The group should be added");
}
JpaUser user = new JpaUser("user", "pass1", org1, "User", "user@localhost", "opencast", true, Collections.set(new JpaRole("ROLE_USER", org1)));
// Set the security sevice
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(org1).anyTimes();
EasyMock.replay(securityService);
provider.setSecurityService(securityService);
Response removeGroupResponse = provider.removeGroup(group.getGroupId());
assertNotNull(removeGroupResponse);
assertEquals(HttpStatus.SC_FORBIDDEN, removeGroupResponse.getStatus());
}
Aggregations