Search in sources :

Example 36 with JaxbRole

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;
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) JaxbUser(org.opencastproject.security.api.JaxbUser)

Example 37 with JaxbRole

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());
    }
}
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 38 with JaxbRole

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);
}
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 39 with JaxbRole

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);
}
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)

Example 40 with JaxbRole

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);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbUser(org.opencastproject.security.api.JaxbUser) EasyMock.anyString(org.easymock.EasyMock.anyString) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) OaiPmhServerInfo(org.opencastproject.oaipmh.server.OaiPmhServerInfo) JaxbRole(org.opencastproject.security.api.JaxbRole) AbstractJobProducer(org.opencastproject.job.api.AbstractJobProducer) SecurityService(org.opencastproject.security.api.SecurityService) Job(org.opencastproject.job.api.Job) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashSet(java.util.HashSet) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Aggregations

JaxbRole (org.opencastproject.security.api.JaxbRole)66 JaxbUser (org.opencastproject.security.api.JaxbUser)53 User (org.opencastproject.security.api.User)45 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)39 SecurityService (org.opencastproject.security.api.SecurityService)39 Before (org.junit.Before)30 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)25 HashSet (java.util.HashSet)18 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)18 Organization (org.opencastproject.security.api.Organization)17 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)17 Test (org.junit.Test)14 Role (org.opencastproject.security.api.Role)13 Workspace (org.opencastproject.workspace.api.Workspace)13 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)11 URI (java.net.URI)10 BundleContext (org.osgi.framework.BundleContext)10 ComponentContext (org.osgi.service.component.ComponentContext)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9