Search in sources :

Example 66 with DefaultOrganization

use of org.opencastproject.security.api.DefaultOrganization 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());
    }
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) NotFoundException(org.opencastproject.util.NotFoundException) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 67 with DefaultOrganization

use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.

the class TestThemesEndpoint method setupServices.

private void setupServices() throws Exception {
    user = new JaxbUser("test", null, "Test User", "test@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
    UserDirectoryService userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(user).anyTimes();
    EasyMock.replay(userDirectoryService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.replay(securityService);
    SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
    EasyMock.replay(seriesService);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    messageSender.sendObjectMessage(EasyMock.anyObject(String.class), EasyMock.anyObject(MessageSender.DestinationType.class), EasyMock.anyObject(Serializable.class));
    EasyMock.expectLastCall().anyTimes();
    EasyMock.replay(messageSender);
    // Create AdminUI Search Index
    AdminUISearchIndex adminUISearchIndex = EasyMock.createMock(AdminUISearchIndex.class);
    final Capture<ThemeSearchQuery> themeQueryCapture = new Capture<ThemeSearchQuery>();
    EasyMock.expect(adminUISearchIndex.getByQuery(EasyMock.capture(themeQueryCapture))).andAnswer(new IAnswer<SearchResult<org.opencastproject.index.service.impl.index.theme.Theme>>() {

        @Override
        public SearchResult<org.opencastproject.index.service.impl.index.theme.Theme> answer() throws Throwable {
            return createThemeCaptureResult(themeQueryCapture);
        }
    });
    final Capture<SeriesSearchQuery> seriesQueryCapture = new Capture<SeriesSearchQuery>();
    EasyMock.expect(adminUISearchIndex.getByQuery(EasyMock.capture(seriesQueryCapture))).andAnswer(new IAnswer<SearchResult<Series>>() {

        @Override
        public SearchResult<Series> answer() throws Throwable {
            return createSeriesCaptureResult(seriesQueryCapture);
        }
    });
    EasyMock.replay(adminUISearchIndex);
    themesServiceDatabaseImpl = new ThemesServiceDatabaseImpl();
    themesServiceDatabaseImpl.setEntityManagerFactory(newTestEntityManagerFactory(ThemesServiceDatabaseImpl.PERSISTENCE_UNIT));
    themesServiceDatabaseImpl.setUserDirectoryService(userDirectoryService);
    themesServiceDatabaseImpl.setSecurityService(securityService);
    themesServiceDatabaseImpl.setMessageSender(messageSender);
    themesServiceDatabaseImpl.activate(null);
    StaticFileService staticFileService = EasyMock.createNiceMock(StaticFileService.class);
    EasyMock.expect(staticFileService.getFile(EasyMock.anyString())).andReturn(new ByteArrayInputStream("test".getBytes("utf-8"))).anyTimes();
    EasyMock.expect(staticFileService.getFileName(EasyMock.anyString())).andStubReturn("test.mp4");
    EasyMock.replay(staticFileService);
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bundleContext.getProperty("org.opencastproject.server.url")).andReturn("http://localhost:8080").anyTimes();
    EasyMock.replay(bundleContext);
    ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
    EasyMock.expect(componentContext.getProperties()).andReturn(new Hashtable<String, Object>()).anyTimes();
    EasyMock.replay(componentContext);
    StaticFileRestService staticFileRestService = new StaticFileRestService();
    staticFileRestService.setStaticFileService(staticFileService);
    staticFileRestService.activate(componentContext);
    this.setThemesServiceDatabase(themesServiceDatabaseImpl);
    this.setSecurityService(securityService);
    this.setSeriesService(seriesService);
    this.setStaticFileService(staticFileService);
    this.setStaticFileRestService(staticFileRestService);
    this.setIndex(adminUISearchIndex);
}
Also used : Serializable(java.io.Serializable) MessageSender(org.opencastproject.message.broker.api.MessageSender) AdminUISearchIndex(org.opencastproject.adminui.impl.index.AdminUISearchIndex) JaxbUser(org.opencastproject.security.api.JaxbUser) StaticFileRestService(org.opencastproject.staticfiles.endpoint.StaticFileRestService) Capture(org.easymock.Capture) ThemesServiceDatabaseImpl(org.opencastproject.themes.persistence.ThemesServiceDatabaseImpl) SecurityService(org.opencastproject.security.api.SecurityService) HashSet(java.util.HashSet) ComponentContext(org.osgi.service.component.ComponentContext) SeriesSearchQuery(org.opencastproject.index.service.impl.index.series.SeriesSearchQuery) Hashtable(java.util.Hashtable) SearchResult(org.opencastproject.matterhorn.search.SearchResult) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StaticFileService(org.opencastproject.staticfiles.api.StaticFileService) SeriesService(org.opencastproject.series.api.SeriesService) ByteArrayInputStream(java.io.ByteArrayInputStream) ThemeSearchQuery(org.opencastproject.index.service.impl.index.theme.ThemeSearchQuery) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) BundleContext(org.osgi.framework.BundleContext)

Example 68 with DefaultOrganization

use of org.opencastproject.security.api.DefaultOrganization in project opencast by opencast.

the class TestAclEndpoint method setupServices.

private void setupServices() {
    final DefaultOrganization org = new DefaultOrganization();
    AccessControlEntry ace1 = new AccessControlEntry("ROLE_ADMIN", "read", true);
    AccessControlEntry ace2 = new AccessControlEntry("ROLE_ANONYMOUS", "read", true);
    AccessControlEntry ace3 = new AccessControlEntry("ROLE_ADMIN", "read", false);
    AccessControlEntry ace4 = new AccessControlEntry("ROLE_ANONYMOUS", "read", false);
    AccessControlList publicAcl = new AccessControlList(ace1, ace2);
    AccessControlList privateAcl = new AccessControlList(ace3, ace4);
    List<ManagedAcl> managedAcls = new ArrayList<ManagedAcl>();
    managedAcls.add(new ManagedAclImpl(1L, "public", org.getId(), publicAcl));
    managedAcls.add(new ManagedAclImpl(2L, "private", org.getId(), privateAcl));
    AclService aclService = EasyMock.createNiceMock(AclService.class);
    EasyMock.expect(aclService.getAcls()).andReturn(managedAcls).anyTimes();
    EasyMock.expect(aclService.getAcl(EasyMock.anyLong())).andReturn(Option.some(managedAcls.get(0))).anyTimes();
    EasyMock.replay(aclService);
    AclServiceFactory aclServiceFactory = EasyMock.createNiceMock(AclServiceFactory.class);
    EasyMock.expect(aclServiceFactory.serviceFor(EasyMock.anyObject(Organization.class))).andReturn(aclService).anyTimes();
    EasyMock.replay(aclServiceFactory);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.replay(securityService);
    this.setAclServiceFactory(aclServiceFactory);
    this.setSecurityService(securityService);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceFactory(org.opencastproject.authorization.xacml.manager.api.AclServiceFactory) SecurityService(org.opencastproject.security.api.SecurityService) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ArrayList(java.util.ArrayList) ManagedAclImpl(org.opencastproject.authorization.xacml.manager.impl.ManagedAclImpl) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) AclService(org.opencastproject.authorization.xacml.manager.api.AclService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

Example 69 with DefaultOrganization

use of org.opencastproject.security.api.DefaultOrganization 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);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) Function(org.opencastproject.util.data.Function) SecurityService(org.opencastproject.security.api.SecurityService) Either(org.opencastproject.util.data.Either) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) TrustedHttpClient(org.opencastproject.security.api.TrustedHttpClient) ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) HttpResponse(org.apache.http.HttpResponse) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StatusLine(org.apache.http.StatusLine) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 70 with DefaultOrganization

use of org.opencastproject.security.api.DefaultOrganization 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);
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) SecurityService(org.opencastproject.security.api.SecurityService) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashSet(java.util.HashSet)

Aggregations

DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)88 SecurityService (org.opencastproject.security.api.SecurityService)62 Before (org.junit.Before)47 JaxbUser (org.opencastproject.security.api.JaxbUser)45 JaxbRole (org.opencastproject.security.api.JaxbRole)39 User (org.opencastproject.security.api.User)38 Organization (org.opencastproject.security.api.Organization)31 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)29 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)26 Test (org.junit.Test)24 Workspace (org.opencastproject.workspace.api.Workspace)23 HashSet (java.util.HashSet)21 ArrayList (java.util.ArrayList)20 MediaPackage (org.opencastproject.mediapackage.MediaPackage)18 File (java.io.File)17 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)17 IOException (java.io.IOException)16 MessageSender (org.opencastproject.message.broker.api.MessageSender)15 InputStream (java.io.InputStream)14 AuthorizationService (org.opencastproject.security.api.AuthorizationService)13