Search in sources :

Example 56 with DefaultOrganization

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

the class TrustedHttpClientImplTest method setUp.

@Before
public void setUp() throws Exception {
    // Setup bundle context for TrustedHttpClientImpl
    bundleContextMock = createNiceMock(BundleContext.class);
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.DIGEST_AUTH_USER_KEY)).andReturn("matterhorn_system_account");
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.DIGEST_AUTH_PASS_KEY)).andReturn("CHANGE_ME");
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_KEY)).andReturn("3");
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_BASE_TIME_KEY)).andReturn("0");
    expect(bundleContextMock.getProperty(TrustedHttpClientImpl.NONCE_TIMEOUT_RETRY_MAXIMUM_VARIABLE_TIME_KEY)).andReturn("0");
    replay(bundleContextMock);
    componentContextMock = createNiceMock(ComponentContext.class);
    expect(componentContextMock.getBundleContext()).andReturn(bundleContextMock).anyTimes();
    replay(componentContextMock);
    long currentJobId = 20L;
    Job currentJob = createNiceMock(Job.class);
    expect(currentJob.getId()).andReturn(currentJobId).anyTimes();
    replay(currentJob);
    securityService = createNiceMock(SecurityService.class);
    expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    expect(securityService.getUser()).andReturn(new JaxbUser()).anyTimes();
    replay(securityService);
    serviceRegistry = createNiceMock(ServiceRegistry.class);
    expect(serviceRegistry.getCurrentJob()).andReturn(currentJob).anyTimes();
    expect(serviceRegistry.getJob(currentJobId)).andReturn(currentJob).anyTimes();
    replay(serviceRegistry);
    client = new TrustedHttpClientImpl("matterhorn_system_account", "CHANGE_ME");
    client.setServiceRegistry(serviceRegistry);
    client.setSecurityService(securityService);
    client.activate(componentContextMock);
    // Setup responses.
    String digestValue = "Digest realm=\"testrealm@host.com\"," + "qop=\"auth,auth-int\"," + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\"," + "opaque=\"5ccc069c403ebaf9f0171e9517f40e41\"";
    okResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("Http", 1, 1), 200, "Good to go"));
    digestResponse = new BasicHttpResponse(new ProtocolVersion("Http", 1, 1), 401, "Unauthorized");
    digestResponse.addHeader("WWW-Authenticate", digestValue);
    nonceResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("Http", 1, 1), 401, "Nonce has expired/timed out"));
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) JaxbUser(org.opencastproject.security.api.JaxbUser) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) BundleContext(org.osgi.framework.BundleContext) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 57 with DefaultOrganization

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

the class OrganizationPersistenceTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    securityService = EasyMock.createNiceMock(SecurityService.class);
    User user = new JaxbUser("admin", "test", new DefaultOrganization(), new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, new DefaultOrganization()));
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.replay(securityService);
    organizationDatabase = new OrganizationDatabaseImpl();
    organizationDatabase.setEntityManagerFactory(newTestEntityManagerFactory(PERSISTENCE_UNIT));
    organizationDatabase.setSecurityService(securityService);
    organizationDatabase.activate(null);
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 58 with DefaultOrganization

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

the class AclScannerTest method setUp.

@Before
public void setUp() throws Exception {
    Organization org1 = new JpaOrganization("org1", "org1", new HashMap<String, Integer>(), "ADMIN", "ANONYMOUS", new HashMap<String, String>());
    Organization org2 = new JpaOrganization("org2", "org2", new HashMap<String, Integer>(), "ADMIN", "ANONYMOUS", new HashMap<String, String>());
    Organization org3 = new JpaOrganization("org3", "org3", new HashMap<String, Integer>(), "ADMIN", "ANONYMOUS", new HashMap<String, String>());
    List<Organization> orgs = new ArrayList<>();
    orgs.add(org1);
    orgs.add(org2);
    orgs.add(org3);
    aclDb = EasyMock.createNiceMock(AclDb.class);
    orgService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    EasyMock.expect(orgService.getOrganizations()).andReturn(orgs).anyTimes();
    final SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    final MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    final AclTransitionDb aclTransitionDb = EasyMock.createNiceMock(AclTransitionDb.class);
    List<EpisodeACLTransition> episodeTransitions = new ArrayList<>();
    List<SeriesACLTransition> seriesTransitions = new ArrayList<>();
    EasyMock.expect(aclTransitionDb.getByQuery(EasyMock.anyObject(Organization.class), EasyMock.anyObject(TransitionQuery.class))).andReturn(new TransitionResultImpl(episodeTransitions, seriesTransitions)).anyTimes();
    // EasyMock.replay(aclDb);
    EasyMock.replay(orgService, messageSender, aclTransitionDb, securityService);
    AclServiceFactory aclServiceFactory = new AclServiceFactory() {

        @Override
        public AclService serviceFor(Organization org) {
            return new AclServiceImpl(new DefaultOrganization(), aclDb, aclTransitionDb, null, null, null, null, messageSender, null);
        }
    };
    aclScanner = new AclScanner();
    aclScanner.setAclServiceFactory(aclServiceFactory);
    aclScanner.setOrganizationDirectoryService(orgService);
    aclScanner.setSecurityService(securityService);
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) JpaOrganization(org.opencastproject.security.impl.jpa.JpaOrganization) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) EasyMock.anyString(org.easymock.EasyMock.anyString) AclServiceFactory(org.opencastproject.authorization.xacml.manager.api.AclServiceFactory) SecurityService(org.opencastproject.security.api.SecurityService) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 59 with DefaultOrganization

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

the class OsgiJpaAclTransitionDbTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    db = new OsgiJpaAclTransitionDb();
    EntityManagerFactory emf = newTestEntityManagerFactory(OsgiJpaAclTransitionDb.PERSISTENCE_UNIT);
    db.setEntityManagerFactory(emf);
    db.activate(null);
    aclDb = new JpaAclDb(persistenceEnvironment(emf));
    InputStream in = null;
    try {
        in = getClass().getResourceAsStream(ACL_FILE);
        acl = AccessControlParser.parseAcl(in);
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : SecurityService(org.opencastproject.security.api.SecurityService) InputStream(java.io.InputStream) PersistenceUtil.newTestEntityManagerFactory(org.opencastproject.util.persistence.PersistenceUtil.newTestEntityManagerFactory) EntityManagerFactory(javax.persistence.EntityManagerFactory) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Before(org.junit.Before)

Example 60 with DefaultOrganization

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

the class OsgiAclServiceFactory method repopulate.

@Override
public void repopulate(final String indexName) {
    final String destinationId = AclItem.ACL_QUEUE_PREFIX + WordUtils.capitalize(indexName);
    for (final Organization organization : organizationDirectoryService.getOrganizations()) {
        SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

            @Override
            protected void run() {
                AclService aclService = serviceFor(organization);
                List<ManagedAcl> acls = aclService.getAcls();
                int total = aclService.getAcls().size();
                logger.info("Re-populating index with acls. There are {} acls(s) to add to the index.", total);
                int current = 1;
                for (ManagedAcl acl : acls) {
                    logger.trace("Adding acl '{}' for org '{}'", acl.getName(), organization.getId());
                    messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, AclItem.create(acl.getName()));
                    messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Acl, total, current));
                    current++;
                }
            }
        });
    }
    Organization organization = new DefaultOrganization();
    SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(cc, organization), new Effect0() {

        @Override
        protected void run() {
            messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Acl));
        }
    });
}
Also used : Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Effect0(org.opencastproject.util.data.Effect0) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) List(java.util.List) AclService(org.opencastproject.authorization.xacml.manager.api.AclService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization)

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