use of org.opencastproject.security.api.JaxbUser 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.JaxbUser 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.JaxbUser in project opencast by opencast.
the class SeriesServiceImplTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
long currentTime = System.currentTimeMillis();
// Mock up a security service
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
User user = new JaxbUser("admin", "test", new DefaultOrganization(), new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, new DefaultOrganization()));
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
seriesDatabase = new SeriesServiceDatabaseImpl();
seriesDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SeriesServiceDatabaseImpl.PERSISTENCE_UNIT));
dcService = new DublinCoreCatalogService();
seriesDatabase.setDublinCoreService(dcService);
seriesDatabase.activate(null);
seriesDatabase.setSecurityService(securityService);
root = PathSupport.concat("target", Long.toString(currentTime));
index = new SeriesServiceSolrIndex(root);
index.setDublinCoreService(dcService);
index.setSecurityService(securityService);
index.activate(null);
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
EasyMock.replay(messageSender);
seriesService = new SeriesServiceImpl();
seriesService.setPersistence(seriesDatabase);
seriesService.setIndex(index);
seriesService.setSecurityService(securityService);
seriesService.setMessageSender(messageSender);
BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn("System Admin");
EasyMock.replay(bundleContext);
ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
EasyMock.replay(componentContext);
seriesService.activate(componentContext);
InputStream in = null;
try {
in = getClass().getResourceAsStream("/dublincore.xml");
testCatalog = dcService.load(in);
} finally {
IOUtils.closeQuietly(in);
}
try {
in = getClass().getResourceAsStream("/dublincore2.xml");
testCatalog2 = dcService.load(in);
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.opencastproject.security.api.JaxbUser 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.JaxbUser in project opencast by opencast.
the class UserAndRoleDirectoryServiceImpl method mergeUsers.
/**
* Merges two representations of a user, as returned by two different user providers. The set or roles from the
* provided users will be merged into one set.
*
* @param user1
* the first user to merge
* @param user2
* the second user to merge
* @return a user with a merged set of roles
*/
protected User mergeUsers(User user1, User user2) {
HashSet<JaxbRole> mergedRoles = new HashSet<JaxbRole>();
for (Role role : user1.getRoles()) {
mergedRoles.add(JaxbRole.fromRole(role));
}
for (Role role : user2.getRoles()) {
mergedRoles.add(JaxbRole.fromRole(role));
}
String name = StringUtils.isNotBlank(user1.getName()) ? user1.getName() : user2.getName();
String email = StringUtils.isNotBlank(user1.getEmail()) ? user1.getEmail() : user2.getEmail();
String password = user1.getPassword() == null ? user2.getPassword() : user1.getPassword();
boolean manageable = user1.isManageable() || user2.isManageable() ? true : false;
JaxbOrganization organization = JaxbOrganization.fromOrganization(user1.getOrganization());
String provider = StringUtils.join(Collections.nonNullList(user1.getProvider(), user2.getProvider()), ",");
JaxbUser jaxbUser = new JaxbUser(user1.getUsername(), password, name, email, provider, organization, mergedRoles);
jaxbUser.setManageable(manageable);
return jaxbUser;
}
Aggregations