use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class WorkflowOperationSkippingTest method setUp.
@Before
public void setUp() throws Exception {
sRoot = new File(getStorageRoot());
try {
FileUtils.forceMkdir(sRoot);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
// create operation handlers for our workflows
succeedingOperationHandler = new SucceedingWorkflowOperationHandler(mediapackage1);
handlerRegistrations = new HashSet<HandlerRegistration>();
handlerRegistrations.add(new HandlerRegistration("op1", succeedingOperationHandler));
handlerRegistrations.add(new HandlerRegistration("op2", succeedingOperationHandler));
// 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;
}
};
scanner = new WorkflowDefinitionScanner();
service.addWorkflowDefinitionScanner(scanner);
MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
EasyMock.replay(mds);
service.addMetadataService(mds);
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
EasyMock.replay(workspace);
// security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.replay(securityService);
service.setSecurityService(securityService);
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
EasyMock.replay(userDirectoryService);
service.setUserDirectoryService(userDirectoryService);
Organization organization = new DefaultOrganization();
List<Organization> organizationList = new ArrayList<Organization>();
organizationList.add(organization);
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
dao = new WorkflowServiceSolrIndex();
dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
EasyMock.replay(messageSender);
AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.replay(authzService);
service.setAuthorizationService(authzService);
dao.setServiceRegistry(serviceRegistry);
dao.setSecurityService(securityService);
dao.setAuthorizationService(authzService);
dao.setOrgDirectory(organizationDirectoryService);
dao.activate("System Admin");
service.setDao(dao);
service.setServiceRegistry(serviceRegistry);
service.setMessageSender(messageSender);
service.setUserDirectoryService(userDirectoryService);
service.activate(null);
InputStream is = null;
try {
is = WorkflowOperationSkippingTest.class.getResourceAsStream("/workflow-definition-skipping.xml");
workingDefinition = WorkflowParser.parseWorkflowDefinition(is);
service.registerWorkflowDefinition(workingDefinition);
IOUtils.closeQuietly(is);
MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
is = WorkflowOperationSkippingTest.class.getResourceAsStream("/mediapackage-1.xml");
mediapackage1 = mediaPackageBuilder.loadFromXml(is);
IOUtils.closeQuietly(is);
Assert.assertNotNull(mediapackage1.getIdentifier());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class SecurityContext method runInContext.
/**
* Run function <code>f</code> within the context.
*/
public <A> A runInContext(Function0<A> f) {
final Organization prevOrg = sec.getOrganization();
// workaround: if no organization is bound to the current thread sec.getUser() will throw a NPE
final User prevUser = prevOrg != null ? sec.getUser() : null;
sec.setOrganization(org);
sec.setUser(user);
try {
return f.apply();
} finally {
sec.setOrganization(prevOrg);
sec.setUser(prevUser);
}
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class SecurityUtil method getUserAndOrganization.
/**
* Get a user and an organization. Only returns something if both elements can be determined.
*/
public static Option<Tuple<User, Organization>> getUserAndOrganization(SecurityService sec, OrganizationDirectoryService orgDir, String orgId, UserDirectoryService userDir, String userId) {
final Organization prevOrg = sec.getOrganization();
try {
final Organization org = orgDir.getOrganization(orgId);
sec.setOrganization(org);
return option(userDir.loadUser(userId)).fmap(new Function<User, Tuple<User, Organization>>() {
@Override
public Tuple<User, Organization> apply(User user) {
return tuple(user, org);
}
});
} catch (NotFoundException e) {
return none();
} finally {
sec.setOrganization(prevOrg);
}
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class SecurityUtil method runAs.
/**
* Run function <code>f</code> in the context described by the given organization and user.
*
* @return the function's outcome.
*/
public static <A> A runAs(SecurityService sec, Organization org, User user, Function0<A> f) {
final Organization prevOrg = sec.getOrganization();
final User prevUser = prevOrg != null ? sec.getUser() : null;
sec.setOrganization(org);
sec.setUser(user);
try {
return f.apply();
} finally {
sec.setOrganization(prevOrg);
sec.setUser(prevUser);
}
}
use of org.opencastproject.security.api.Organization in project opencast by opencast.
the class OrganizationDirectoryServiceTest method setUp.
@Before
public void setUp() {
OrganizationDatabase organizationDatabase = new OrganizationDatabase() {
private int i = 0;
private Organization organization;
@Override
public void storeOrganization(Organization organization) throws OrganizationDatabaseException {
this.organization = organization;
if (i == 0) {
assertNotNull(organization);
assertEquals("mh_default", organization.getId());
assertEquals("Opencast Test", organization.getName());
assertEquals("ROLE_TEST_ADMIN", organization.getAdminRole());
assertEquals("ROLE_TEST_ANONYMOUS", organization.getAnonymousRole());
Map<String, Integer> servers = organization.getServers();
assertEquals(1, servers.size());
assertTrue(servers.containsKey("localhost"));
assertTrue(servers.containsValue(8080));
assertEquals("true", organization.getProperties().get("org.test"));
} else if (i == 1) {
assertNotNull(organization);
assertEquals("mh_default", organization.getId());
assertEquals("Opencast Test 2", organization.getName());
assertEquals("ROLE_TEST2_ADMIN", organization.getAdminRole());
assertEquals("ROLE_TEST2_ANONYMOUS", organization.getAnonymousRole());
Map<String, Integer> servers = organization.getServers();
assertEquals(3, servers.size());
assertTrue(servers.containsKey("localhost"));
assertTrue(servers.containsValue(8080));
assertTrue(servers.containsKey("localhost2"));
assertTrue(servers.containsValue(8081));
assertTrue(servers.containsKey("another"));
assertEquals("false", organization.getProperties().get("org.test"));
} else {
fail("Too many storeOrganization calls: " + i);
}
i++;
}
@Override
public List<Organization> getOrganizations() throws OrganizationDatabaseException {
return null;
}
@Override
public Organization getOrganizationByHost(String host, int port) throws OrganizationDatabaseException, NotFoundException {
return null;
}
@Override
public Organization getOrganization(String orgId) throws OrganizationDatabaseException, NotFoundException {
if (organization == null)
throw new NotFoundException();
return organization;
}
@Override
public void deleteOrganization(String orgId) throws OrganizationDatabaseException, NotFoundException {
}
@Override
public int countOrganizations() throws OrganizationDatabaseException {
return 0;
}
@Override
public boolean containsOrganization(String orgId) throws OrganizationDatabaseException {
return false;
}
};
orgDirectoryService = new OrganizationDirectoryServiceImpl();
orgDirectoryService.setOrgPersistence(organizationDatabase);
}
Aggregations