use of org.opencastproject.security.api.JaxbRole in project opencast by opencast.
the class TestSearchIndex method createSecurityService.
public static final SecurityService createSecurityService(DefaultOrganization organization) {
JaxbUser creator = new JaxbUser("creator", "password", "Creator", null, "test", organization, new HashSet<JaxbRole>());
SecurityService securityService = createNiceMock(SecurityService.class);
expect(securityService.getOrganization()).andReturn(organization).anyTimes();
expect(securityService.getUser()).andReturn(creator).anyTimes();
replay(securityService);
return securityService;
}
use of org.opencastproject.security.api.JaxbRole in project opencast by opencast.
the class MailServiceTest method testCRUDMessageSignature.
@Test
public void testCRUDMessageSignature() {
User admin = new JaxbUser("george@test.com", null, "George", "george@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
User help = new JaxbUser("frank@test.com", null, "Frank", "frank@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
MessageSignature signatureAdmin = MessageSignature.messageSignature("Administrator", admin, EmailAddress.emailAddress("admin@test.com", "Dr. Admin"), "Sincerly");
MessageSignature signatureHelp = MessageSignature.messageSignature("Helpdesk", help, EmailAddress.emailAddress("help@test.com", "Mr. Help"), "Sincerly");
List<MessageSignature> signatures;
// Create
try {
signatureAdmin = mailService.updateMessageSignature(signatureAdmin);
signatureHelp = mailService.updateMessageSignature(signatureHelp);
} catch (MailServiceException e) {
fail("Not able to save a message signature entity: " + e.getMessage());
}
// Read
try {
signatures = mailService.getMessageSignatures();
assertEquals(2, signatures.size());
assertTrue(signatures.contains(signatureAdmin) && signatures.contains(signatureHelp));
} catch (MailServiceException e) {
fail("Not able to get the message signatures: " + e.getMessage());
}
// Update
try {
signatureHelp.setCreator(admin);
signatureHelp = mailService.updateMessageSignature(signatureHelp);
signatures = mailService.getMessageSignatures();
assertEquals(2, signatures.size());
assertTrue(signatures.contains(signatureHelp));
} catch (MailServiceException e) {
fail("Not able to update a message signature entity: " + e.getMessage());
}
// Delete
try {
mailService.deleteMessageSignature(signatureAdmin.getId());
signatures = mailService.getMessageSignatures();
assertEquals(1, signatures.size());
assertTrue(signatures.contains(signatureHelp));
} catch (MailServiceException e) {
fail("Not able to delete the message signature " + signatureAdmin.getName() + ": " + e.getMessage());
} catch (NotFoundException e) {
fail("Not able to get the message signatures: " + e.getMessage());
}
}
use of org.opencastproject.security.api.JaxbRole in project opencast by opencast.
the class DownloadDistributionServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
final File mediaPackageRoot = new File(getClass().getResource("/mediapackage.xml").toURI()).getParentFile();
mp = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/mediapackage.xml"), "UTF-8"));
distributionRoot = new File(mediaPackageRoot, "static");
service = new DownloadDistributionServiceImpl();
StatusLine statusLine = EasyMock.createNiceMock(StatusLine.class);
EasyMock.expect(statusLine.getStatusCode()).andReturn(HttpServletResponse.SC_OK).anyTimes();
EasyMock.replay(statusLine);
HttpResponse response = EasyMock.createNiceMock(HttpResponse.class);
EasyMock.expect(response.getStatusLine()).andReturn(statusLine).anyTimes();
EasyMock.replay(response);
final TrustedHttpClient httpClient = EasyMock.createNiceMock(TrustedHttpClient.class);
EasyMock.expect(httpClient.execute((HttpUriRequest) EasyMock.anyObject())).andReturn(response).anyTimes();
EasyMock.expect(httpClient.run((HttpUriRequest) EasyMock.anyObject())).andAnswer(new IAnswer<Function<Function<HttpResponse, Object>, Either<Exception, Object>>>() {
@Override
public Function<Function<HttpResponse, Object>, Either<Exception, Object>> answer() throws Throwable {
HttpUriRequest req = (HttpUriRequest) EasyMock.getCurrentArguments()[0];
return StandAloneTrustedHttpClientImpl.run(httpClient, req);
}
}).anyTimes();
EasyMock.replay(httpClient);
defaultOrganization = new DefaultOrganization();
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);
service.setUserDirectoryService(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
service.setOrganizationDirectoryService(organizationDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
EasyMock.replay(securityService);
service.setSecurityService(securityService);
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
service.setServiceRegistry(serviceRegistry);
service.setTrustedHttpClient(httpClient);
final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
service.setWorkspace(workspace);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
final URI uri = (URI) EasyMock.getCurrentArguments()[0];
final String[] pathElems = uri.getPath().split("/");
final String file = pathElems[pathElems.length - 1];
return new File(mediaPackageRoot, file);
}
}).anyTimes();
EasyMock.replay(workspace);
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getProperty("org.opencastproject.download.directory")).andReturn(distributionRoot.toString()).anyTimes();
EasyMock.expect(bc.getProperty("org.opencastproject.download.url")).andReturn(UrlSupport.DEFAULT_BASE_URL).anyTimes();
ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
Dictionary<String, Object> p = new Hashtable<String, Object>();
p.put(DistributionService.CONFIG_KEY_STORE_TYPE, "download");
EasyMock.expect(cc.getProperties()).andReturn(p).anyTimes();
EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
EasyMock.replay(bc, cc);
service.activate(cc);
}
use of org.opencastproject.security.api.JaxbRole in project opencast by opencast.
the class CaptureAgentStateServiceImplTest method setupService.
private void setupService() throws Exception {
service = new CaptureAgentStateServiceImpl();
service.setEntityManagerFactory(newTestEntityManagerFactory(CaptureAgentStateServiceImpl.PERSISTENCE_UNIT));
DefaultOrganization organization = new DefaultOrganization();
HashSet<JaxbRole> roles = new HashSet<>();
roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, organization, ""));
User user = new JaxbUser("testuser", "test", organization, roles);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.replay(securityService);
service.setSecurityService(securityService);
setupCC();
service.activate(cc);
service.setupAgentCache(1, TimeUnit.HOURS);
}
use of org.opencastproject.security.api.JaxbRole in project opencast by opencast.
the class OaiPmhPublicationServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
mp = MediaPackageSupport.loadFromClassPath("/mediapackage.xml");
mp2 = MediaPackageSupport.loadFromClassPath("/mediapackage2.xml");
validOaiPmhRepositories = Collections.list("default");
OaiPmhServerInfo oaiPmhServerInfo = EasyMock.createNiceMock(OaiPmhServerInfo.class);
EasyMock.expect(oaiPmhServerInfo.hasRepo(anyString())).andAnswer(() -> validOaiPmhRepositories.contains((String) EasyMock.getCurrentArguments()[0])).anyTimes();
EasyMock.expect(oaiPmhServerInfo.getMountPoint()).andReturn(OAI_PMH_SERVER_MOUNT_POINT).anyTimes();
DefaultOrganization org = new DefaultOrganization() {
@Override
public Map<String, String> getProperties() {
HashMap<String, String> props = new HashMap<>();
props.putAll(DEFAULT_PROPERTIES);
props.put(ORG_CFG_OAIPMH_SERVER_HOSTURL, OAI_PMH_SERVER_URL);
return props;
}
};
HashSet<JaxbRole> roles = new HashSet<JaxbRole>();
roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, org, ""));
User user = new JaxbUser("admin", "test", org, roles);
OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(org).anyTimes();
UserDirectoryService userDirectory = EasyMock.createNiceMock(UserDirectoryService.class);
EasyMock.expect(userDirectory.loadUser("admin")).andReturn(user).anyTimes();
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectory, orgDirectory, EasyMock.createNiceMock(IncidentService.class));
// Finish setting up the mocks
EasyMock.replay(oaiPmhServerInfo, orgDirectory, userDirectory, securityService);
service = new OaiPmhPublicationServiceImpl();
service.setOaiPmhServerInfo(oaiPmhServerInfo);
service.setSecurityService(securityService);
service.setServiceRegistry(serviceRegistry);
// mock streaming/download distribution jobs dispatching
AbstractJobProducer distributionJobProducerMock = new AbstractJobProducer("distribute") {
@Override
protected ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
@Override
protected SecurityService getSecurityService() {
return securityService;
}
@Override
protected UserDirectoryService getUserDirectoryService() {
return userDirectory;
}
@Override
protected OrganizationDirectoryService getOrganizationDirectoryService() {
return orgDirectory;
}
@Override
protected String process(Job job) throws Exception {
return job.getPayload();
}
@Override
public boolean isReadyToAccept(Job job) throws ServiceRegistryException, UndispatchableJobException {
return true;
}
};
serviceRegistry.registerService(distributionJobProducerMock);
}
Aggregations