Search in sources :

Example 16 with JaxbOrganization

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

the class GenericUrlSigningProviderTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    /* Create mockup for organization a */
    JaxbOrganization organizationA = EasyMock.createNiceMock(JaxbOrganization.class);
    EasyMock.expect(organizationA.getId()).andReturn(ORGANIZATION_A_ID).anyTimes();
    EasyMock.replay(organizationA);
    SecurityService securityServiceA = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityServiceA.getOrganization()).andReturn(organizationA).anyTimes();
    EasyMock.replay(securityServiceA);
    signerA = new GenericUrlSigningProvider();
    signerA.setSecurityService(securityServiceA);
    /* Create mockup for organization b */
    JaxbOrganization organizationB = EasyMock.createNiceMock(JaxbOrganization.class);
    EasyMock.expect(organizationB.getId()).andReturn(ORGANIZATION_B_ID).anyTimes();
    EasyMock.replay(organizationB);
    SecurityService securityServiceB = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityServiceB.getOrganization()).andReturn(organizationB).anyTimes();
    EasyMock.replay(securityServiceB);
    signerB = new GenericUrlSigningProvider();
    signerB.setSecurityService(securityServiceB);
    properties = new Properties();
    /* To indicate that specific tests are not supposed to test multi-tenant capabilities, we just set an alias */
    signer = signerA;
}
Also used : SecurityService(org.opencastproject.security.api.SecurityService) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) Properties(java.util.Properties) BeforeClass(org.junit.BeforeClass)

Example 17 with JaxbOrganization

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

the class JobTest method setUp.

@Before
public void setUp() throws Exception {
    final EntityManagerFactory emf = newTestEntityManagerFactory(ServiceRegistryJpaImpl.PERSISTENCE_UNIT);
    serviceRegistry = new ServiceRegistryJpaImpl();
    serviceRegistry.setEntityManagerFactory(emf);
    serviceRegistry.activate(null);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    serviceRegistry.setOrganizationDirectoryService(organizationDirectoryService);
    JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
    User anonymous = new JaxbUser("anonymous", "test", jaxbOrganization, new JaxbRole(jaxbOrganization.getAnonymousRole(), jaxbOrganization));
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    serviceRegistry.setSecurityService(securityService);
    // register the hosts
    serviceRegistry.registerHost(LOCALHOST, "127.0.0.1", 1024, 1, 1.0f);
    serviceRegistry.registerHost(REMOTEHOST, "127.0.0.1", 1024, 1, 1.0f);
    // register some service instances
    regType1Localhost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_1, LOCALHOST, PATH);
    regType1Remotehost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_1, REMOTEHOST, PATH);
    regType2Localhost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_2, LOCALHOST, PATH);
    regType2Remotehost = (ServiceRegistrationJpaImpl) serviceRegistry.registerService(JOB_TYPE_2, REMOTEHOST, PATH);
    penv = persistenceEnvironment(emf);
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) PersistenceUtil.newTestEntityManagerFactory(org.opencastproject.util.persistence.PersistenceUtil.newTestEntityManagerFactory) EntityManagerFactory(javax.persistence.EntityManagerFactory) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) Arrays.mkString(org.opencastproject.util.data.Arrays.mkString) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 18 with JaxbOrganization

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

the class SeriesServiceSolrTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // Mock up a security service
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    JaxbOrganization org = new JaxbOrganization("mh-default-org");
    User user = new JaxbUser("admin", "test", org, new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, org));
    EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.replay(securityService);
    index = new SeriesServiceSolrIndex();
    index.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
    dcService = new DublinCoreCatalogService();
    index.setDublinCoreService(dcService);
    index.setSecurityService(securityService);
    index.activate(null);
    InputStream in = null;
    try {
        in = getClass().getResourceAsStream("/dublincore.xml");
        testCatalog = dcService.load(in);
    } finally {
        IOUtils.closeQuietly(in);
    }
}
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) InputStream(java.io.InputStream) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) Before(org.junit.Before)

Example 19 with JaxbOrganization

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

the class UserAndRoleDirectoryServiceImpl method mergeUsers.

/**
 * Merges two representations of a user, as returned by two different user providers. The set or roles from the
 * provided users will be merged into one set.
 *
 * @param user1
 *          the first user to merge
 * @param user2
 *          the second user to merge
 * @return a user with a merged set of roles
 */
protected User mergeUsers(User user1, User user2) {
    HashSet<JaxbRole> mergedRoles = new HashSet<JaxbRole>();
    for (Role role : user1.getRoles()) {
        mergedRoles.add(JaxbRole.fromRole(role));
    }
    for (Role role : user2.getRoles()) {
        mergedRoles.add(JaxbRole.fromRole(role));
    }
    String name = StringUtils.isNotBlank(user1.getName()) ? user1.getName() : user2.getName();
    String email = StringUtils.isNotBlank(user1.getEmail()) ? user1.getEmail() : user2.getEmail();
    String password = user1.getPassword() == null ? user2.getPassword() : user1.getPassword();
    boolean manageable = user1.isManageable() || user2.isManageable() ? true : false;
    JaxbOrganization organization = JaxbOrganization.fromOrganization(user1.getOrganization());
    String provider = StringUtils.join(Collections.nonNullList(user1.getProvider(), user2.getProvider()), ",");
    JaxbUser jaxbUser = new JaxbUser(user1.getUsername(), password, name, email, provider, organization, mergedRoles);
    jaxbUser.setManageable(manageable);
    return jaxbUser;
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) Role(org.opencastproject.security.api.Role) JaxbRole(org.opencastproject.security.api.JaxbRole) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) HashSet(java.util.HashSet)

Example 20 with JaxbOrganization

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

the class CustomRoleProvider method findRoles.

/**
 * @see org.opencastproject.security.api.RoleProvider#findRoles(String, Role.Target, int, int)
 */
@Override
public Iterator<Role> findRoles(String query, Role.Target target, int offset, int limit) {
    if (query == null)
        throw new IllegalArgumentException("Query must be set");
    Organization organization = securityService.getOrganization();
    // Match the custom regular expression first if this is an ACL role query
    if ((target == Role.Target.ACL) && (rolematch != null)) {
        String exactQuery = StringUtils.removeEnd(query, "%");
        Matcher m = rolematch.matcher(exactQuery);
        if (m.matches()) {
            List<Role> roles = new LinkedList<Role>();
            JaxbOrganization jaxbOrganization = JaxbOrganization.fromOrganization(organization);
            roles.add(new JaxbRole(exactQuery, jaxbOrganization, "Custom Role", Role.Type.EXTERNAL));
            return roles.iterator();
        }
    }
    // Otherwise match on the custom roles specified in a list
    return Stream.$(roles).filter(filterByName._2(query)).drop(offset).apply(limit > 0 ? StreamOp.<String>id().take(limit) : StreamOp.<String>id()).map(toRole._2(organization)).iterator();
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) Role(org.opencastproject.security.api.Role) Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbRole(org.opencastproject.security.api.JaxbRole) Matcher(java.util.regex.Matcher) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) LinkedList(java.util.LinkedList)

Aggregations

JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)25 JaxbRole (org.opencastproject.security.api.JaxbRole)21 JaxbUser (org.opencastproject.security.api.JaxbUser)18 User (org.opencastproject.security.api.User)14 HashSet (java.util.HashSet)9 Before (org.junit.Before)9 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)9 Organization (org.opencastproject.security.api.Organization)9 SecurityService (org.opencastproject.security.api.SecurityService)9 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)8 HashMap (java.util.HashMap)5 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)5 Workspace (org.opencastproject.workspace.api.Workspace)5 File (java.io.File)4 URI (java.net.URI)4 LinkedList (java.util.LinkedList)4 Role (org.opencastproject.security.api.Role)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)3