Search in sources :

Example 56 with Organization

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());
    }
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) Set(java.util.Set) HashSet(java.util.HashSet) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) MessageSender(org.opencastproject.message.broker.api.MessageSender) MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) ArrayList(java.util.ArrayList) DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) InputStream(java.io.InputStream) IOException(java.io.IOException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) IOException(java.io.IOException) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 57 with Organization

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

Example 58 with Organization

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);
    }
}
Also used : JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) NotFoundException(org.opencastproject.util.NotFoundException) Tuple(org.opencastproject.util.data.Tuple)

Example 59 with Organization

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

Example 60 with Organization

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);
}
Also used : Organization(org.opencastproject.security.api.Organization) NotFoundException(org.opencastproject.util.NotFoundException) OrganizationDatabase(org.opencastproject.kernel.security.persistence.OrganizationDatabase) Map(java.util.Map) Before(org.junit.Before)

Aggregations

Organization (org.opencastproject.security.api.Organization)135 User (org.opencastproject.security.api.User)60 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)46 NotFoundException (org.opencastproject.util.NotFoundException)43 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)29 SecurityService (org.opencastproject.security.api.SecurityService)29 IOException (java.io.IOException)24 Before (org.junit.Before)24 ArrayList (java.util.ArrayList)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)22 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)22 JaxbRole (org.opencastproject.security.api.JaxbRole)21 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 JaxbUser (org.opencastproject.security.api.JaxbUser)20 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)19 File (java.io.File)18 HashMap (java.util.HashMap)17 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)17 Test (org.junit.Test)15