Search in sources :

Example 61 with JaxbUser

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

the class SearchServicePersistenceTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    securityService = EasyMock.createNiceMock(SecurityService.class);
    DefaultOrganization defaultOrganization = new DefaultOrganization();
    User user = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, defaultOrganization));
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.replay(securityService);
    searchDatabase = new SearchServiceDatabaseImpl();
    searchDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SearchServiceDatabaseImpl.PERSISTENCE_UNIT));
    searchDatabase.setSecurityService(securityService);
    searchDatabase.activate(null);
    mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    accessControlList = new AccessControlList();
    List<AccessControlEntry> acl = accessControlList.getEntries();
    acl.add(new AccessControlEntry("admin", Permissions.Action.WRITE.toString(), true));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 62 with JaxbUser

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

the class VideoSegmenterTest method setUp.

/**
 * Setup for the video segmenter service, including creation of a mock workspace.
 *
 * @throws Exception
 *           if setup fails
 */
@Before
public void setUp() throws Exception {
    mpeg7Service = new Mpeg7CatalogService();
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(track.getURI()));
    tempFile = testFolder.newFile(getClass().getName() + ".xml");
    EasyMock.expect(workspace.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andAnswer(new IAnswer<URI>() {

        @Override
        public URI answer() throws Throwable {
            InputStream in = (InputStream) EasyMock.getCurrentArguments()[2];
            IOUtils.copy(in, new FileOutputStream(tempFile));
            return tempFile.toURI();
        }
    });
    EasyMock.replay(workspace);
    mpeg7Service1 = new Mpeg7CatalogService();
    Workspace workspace1 = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace1.get((URI) EasyMock.anyObject())).andReturn(new File(track1.getURI()));
    tempFile1 = testFolder.newFile(getClass().getName() + "-1.xml");
    EasyMock.expect(workspace1.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andAnswer(new IAnswer<URI>() {

        @Override
        public URI answer() throws Throwable {
            InputStream in = (InputStream) EasyMock.getCurrentArguments()[2];
            IOUtils.copy(in, new FileOutputStream(tempFile1));
            return tempFile1.toURI();
        }
    });
    EasyMock.replay(workspace1);
    User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new 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);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    vsegmenter = new VideoSegmenterServiceImpl();
    serviceRegistry = new ServiceRegistryInMemoryImpl(vsegmenter, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    vsegmenter.setServiceRegistry(serviceRegistry);
    vsegmenter.setMpeg7CatalogService(mpeg7Service);
    vsegmenter.setWorkspace(workspace);
    vsegmenter.setSecurityService(securityService);
    vsegmenter.setUserDirectoryService(userDirectoryService);
    vsegmenter.setOrganizationDirectoryService(organizationDirectoryService);
    vsegmenter1 = new VideoSegmenterServiceImpl();
    serviceRegistry1 = new ServiceRegistryInMemoryImpl(vsegmenter1, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    vsegmenter1.setServiceRegistry(serviceRegistry1);
    vsegmenter1.setMpeg7CatalogService(mpeg7Service1);
    vsegmenter1.setWorkspace(workspace1);
    vsegmenter1.setSecurityService(securityService);
    vsegmenter1.setUserDirectoryService(userDirectoryService);
    vsegmenter1.setOrganizationDirectoryService(organizationDirectoryService);
    // set parameters for segmentation because the default parameters are not suitable for too short videos
    vsegmenter.prefNumber = 2;
    vsegmenter.stabilityThreshold = 2;
    vsegmenter.absoluteMin = 1;
    vsegmenter1.stabilityThreshold = 2;
    vsegmenter1.changesThreshold = 0.025f;
    vsegmenter1.prefNumber = 5;
    vsegmenter1.maxCycles = 5;
    vsegmenter1.maxError = 0.2f;
    vsegmenter1.absoluteMin = 1;
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) InputStream(java.io.InputStream) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) Mpeg7CatalogService(org.opencastproject.metadata.mpeg7.Mpeg7CatalogService) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 63 with JaxbUser

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

the class WorkflowServiceImplAuthzTest method setUp.

@Before
public void setUp() throws Exception {
    Map<String, Integer> servers = new HashMap<String, Integer>();
    servers.put("http://somewhere", 80);
    defaultOrganization = new DefaultOrganization();
    otherOrganization = new JaxbOrganization("other_org", "Another organization", servers, defaultOrganization.getAdminRole(), defaultOrganization.getAnonymousRole(), null);
    JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(defaultOrganization);
    instructor1 = new JaxbUser("instructor1", "test", jaxbOrganization, new JaxbRole("ROLE_INSTRUCTOR", jaxbOrganization));
    instructor2 = new JaxbUser("instructor2", "test", jaxbOrganization, new JaxbRole("ROLE_INSTRUCTOR", jaxbOrganization));
    JaxbOrganization differentOrg = new JaxbOrganization("differentorg");
    instructorFromDifferentOrg = new JaxbUser("instructor3", "test", differentOrg, new JaxbRole("ROLE_INSTRUCTOR", differentOrg));
    JaxbOrganization doesntMatterOrg = new JaxbOrganization("org doesn't matter");
    globalAdmin = new JaxbUser("global_admin", "test", doesntMatterOrg, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, doesntMatterOrg));
    users = new HashMap<String, User>();
    users.put(instructor1.getUsername(), instructor1);
    users.put(instructor2.getUsername(), instructor2);
    users.put(instructorFromDifferentOrg.getUsername(), instructorFromDifferentOrg);
    users.put(DEFAULT_ORG_ADMIN.getUsername(), DEFAULT_ORG_ADMIN);
    users.put(globalAdmin.getUsername(), globalAdmin);
    service = new WorkflowServiceImpl() {

        @Override
        public Set<HandlerRegistration> getRegisteredHandlers() {
            return new HashSet<WorkflowServiceImpl.HandlerRegistration>();
        }
    };
    scanner = new WorkflowDefinitionScanner();
    service.addWorkflowDefinitionScanner(scanner);
    // Organization Service
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(defaultOrganization);
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andAnswer(new IAnswer<Organization>() {

        @Override
        public Organization answer() throws Throwable {
            String orgId = (String) EasyMock.getCurrentArguments()[0];
            Map<String, Integer> servers = new HashMap<String, Integer>();
            servers.put("http://" + orgId, 80);
            defaultOrganization = new DefaultOrganization();
            return new JaxbOrganization(orgId, orgId, servers, "ROLE_ADMIN", "ROLE_ANONYMOUS", null);
        }
    }).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    // Metadata Service
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    // Workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    EasyMock.replay(workspace);
    // User Directory
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andAnswer(new IAnswer<User>() {

        @Override
        public User answer() throws Throwable {
            String userName = (String) EasyMock.getCurrentArguments()[0];
            return users.get(userName);
        }
    }).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    // security service
    userResponder = new Responder<User>(DEFAULT_ORG_ADMIN);
    organizationResponder = new Responder<Organization>(defaultOrganization);
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andAnswer(userResponder).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andAnswer(organizationResponder).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    // Authorization Service
    AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.replay(authzService);
    service.setAuthorizationService(authzService);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    // Service Registry
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    service.setServiceRegistry(serviceRegistry);
    // Search Index
    sRoot = new File(getStorageRoot());
    FileUtils.forceMkdir(sRoot);
    dao = new WorkflowServiceSolrIndex();
    dao.setServiceRegistry(serviceRegistry);
    dao.setAuthorizationService(authzService);
    dao.setSecurityService(securityService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
    dao.activate("System Admin");
    service.setDao(dao);
    service.setMessageSender(messageSender);
    // Activate
    service.activate(null);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashSet(java.util.HashSet) Set(java.util.Set) Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashMap(java.util.HashMap) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) JaxbUser(org.opencastproject.security.api.JaxbUser) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) IAnswer(org.easymock.IAnswer) JaxbRole(org.opencastproject.security.api.JaxbRole) AuthorizationService(org.opencastproject.security.api.AuthorizationService) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Aggregations

JaxbUser (org.opencastproject.security.api.JaxbUser)63 JaxbRole (org.opencastproject.security.api.JaxbRole)54 User (org.opencastproject.security.api.User)47 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)46 SecurityService (org.opencastproject.security.api.SecurityService)44 Before (org.junit.Before)34 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)21 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)19 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)19 Test (org.junit.Test)15 Organization (org.opencastproject.security.api.Organization)15 Workspace (org.opencastproject.workspace.api.Workspace)15 HashSet (java.util.HashSet)14 URI (java.net.URI)12 BundleContext (org.osgi.framework.BundleContext)12 ComponentContext (org.osgi.service.component.ComponentContext)12 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)11 File (java.io.File)10 Job (org.opencastproject.job.api.Job)8 InputStream (java.io.InputStream)7