Search in sources :

Example 6 with AccessControlEntry

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

the class SolrIndexManager method setAuthorization.

/**
 * Adds authorization fields to the solr document.
 *
 * @param doc
 *          the solr document
 * @param acl
 *          the access control list
 */
static void setAuthorization(SolrInputDocument doc, SecurityService securityService, AccessControlList acl) {
    Map<String, List<String>> permissions = new HashMap<String, List<String>>();
    // Define containers for common permissions
    List<String> reads = new ArrayList<String>();
    permissions.put(READ.toString(), reads);
    List<String> writes = new ArrayList<String>();
    permissions.put(WRITE.toString(), writes);
    String adminRole = securityService.getOrganization().getAdminRole();
    // The admin user can read and write
    if (adminRole != null) {
        reads.add(adminRole);
        writes.add(adminRole);
    }
    for (AccessControlEntry entry : acl.getEntries()) {
        if (!entry.isAllow()) {
            logger.warn("Search service does not support denial via ACL, ignoring {}", entry);
            continue;
        }
        List<String> actionPermissions = permissions.get(entry.getAction());
        /*
       * MH-8353 a series could have a permission defined we don't know how to handle -DH
       */
        if (actionPermissions == null) {
            logger.warn("Search service doesn't know how to handle action: " + entry.getAction());
            continue;
        }
        if (acl == null) {
            actionPermissions = new ArrayList<String>();
            permissions.put(entry.getAction(), actionPermissions);
        }
        actionPermissions.add(entry.getRole());
    }
    // Write the permissions to the solr document
    for (Map.Entry<String, List<String>> entry : permissions.entrySet()) {
        Schema.setOcAcl(doc, new DField<String>(mkString(entry.getValue(), " "), entry.getKey()));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) List(java.util.List) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) Map(java.util.Map) HashMap(java.util.HashMap) Collections.flatMap(org.opencastproject.util.data.Collections.flatMap)

Example 7 with AccessControlEntry

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

the class SearchServiceImplTest method testDeleteMediaPackage.

/**
 * Test removal from the search index.
 */
@Test
public void testDeleteMediaPackage() throws Exception {
    MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
    // Make sure our mocked ACL has the read and write permission
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
    acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
    // Add the media package to the search index
    Job job = service.add(mediaPackage);
    JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    // Now take the role away from the user
    userResponder.setResponse(userWithoutPermissions);
    Map<String, Integer> servers = new HashMap<String, Integer>();
    servers.put("http://localhost", 8080);
    organizationResponder.setResponse(new JaxbOrganization(DefaultOrganization.DEFAULT_ORGANIZATION_ID, DefaultOrganization.DEFAULT_ORGANIZATION_NAME, servers, DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, null));
    // Try to delete it
    job = service.delete(mediaPackage.getIdentifier().toString());
    barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Job to delete mediapackage did not finish", Job.Status.FINISHED, job.getStatus());
    assertEquals("Unauthorized user was able to delete a mediapackage", Boolean.FALSE.toString(), job.getPayload());
    // Second try with a "fixed" roleset
    User adminUser = new JaxbUser("admin", "test", defaultOrganization, new JaxbRole(defaultOrganization.getAdminRole(), defaultOrganization));
    userResponder.setResponse(adminUser);
    Date deletedDate = new Date();
    job = service.delete(mediaPackage.getIdentifier().toString());
    barrier = new JobBarrier(null, serviceRegistry, 1000, job);
    barrier.waitForJobs();
    assertEquals("Unauthorized user was able to delete a mediapackage", Job.Status.FINISHED, job.getStatus());
    // Now go back to the original security service and user
    userResponder.setResponse(defaultUser);
    organizationResponder.setResponse(defaultOrganization);
    SearchQuery q = new SearchQuery();
    q.includeEpisodes(true);
    q.includeSeries(false);
    q.withId("10.0000/1");
    assertEquals(0, service.getByQuery(q).size());
    // Clear the ID requirement
    q.withId(null);
    assertEquals(0, service.getByQuery(q).size());
    q = new SearchQuery();
    q.withDeletedSince(deletedDate);
    assertEquals(1, service.getByQuery(q).size());
}
Also used : SearchQuery(org.opencastproject.search.api.SearchQuery) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) HashMap(java.util.HashMap) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) JobBarrier(org.opencastproject.job.api.JobBarrier) Date(java.util.Date) JaxbRole(org.opencastproject.security.api.JaxbRole) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 8 with AccessControlEntry

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

the class SeriesServiceImplTest method testACLEquality1.

@Test
public void testACLEquality1() {
    AccessControlList a = new AccessControlList(new AccessControlEntry("a", Permissions.Action.READ.toString(), true), new AccessControlEntry("b", Permissions.Action.WRITE.toString(), false));
    AccessControlList b = new AccessControlList(new AccessControlEntry("b", Permissions.Action.WRITE.toString(), false), new AccessControlEntry("a", Permissions.Action.READ.toString(), true));
    assertTrue(AccessControlUtil.equals(a, b));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Test(org.junit.Test)

Example 9 with AccessControlEntry

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

the class SeriesServiceImplTest method testACLEquality4.

@Test
public void testACLEquality4() {
    AccessControlList a = new AccessControlList(new AccessControlEntry("b", Permissions.Action.WRITE.toString(), false));
    AccessControlList b = new AccessControlList(new AccessControlEntry("b", Permissions.Action.WRITE.toString(), false), new AccessControlEntry("b", Permissions.Action.READ.toString(), false));
    assertFalse(AccessControlUtil.equals(a, b));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Test(org.junit.Test)

Example 10 with AccessControlEntry

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

the class SeriesServiceImplTest method testACLManagement.

@Test
public void testACLManagement() throws Exception {
    // sample access control list
    AccessControlList accessControlList = new AccessControlList();
    List<AccessControlEntry> acl = accessControlList.getEntries();
    acl.add(new AccessControlEntry("admin", "delete", true));
    try {
        seriesService.updateAccessControl("failid", accessControlList);
        Assert.fail("Should fail when adding ACL to nonexistent series,");
    } catch (NotFoundException e) {
    // expected
    }
    seriesService.updateSeries(testCatalog);
    seriesService.updateAccessControl(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER), accessControlList);
    AccessControlList retrievedACL = seriesService.getSeriesAccessControl(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER));
    Assert.assertNotNull(retrievedACL);
    acl = retrievedACL.getEntries();
    Assert.assertEquals(acl.size(), 1);
    Assert.assertEquals("admin", acl.get(0).getRole());
    acl = accessControlList.getEntries();
    acl.clear();
    acl.add(new AccessControlEntry("student", Permissions.Action.READ.toString(), true));
    seriesService.updateAccessControl(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER), accessControlList);
    retrievedACL = seriesService.getSeriesAccessControl(testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER));
    Assert.assertNotNull(retrievedACL);
    acl = retrievedACL.getEntries();
    Assert.assertEquals(acl.size(), 1);
    Assert.assertEquals("student", acl.get(0).getRole());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Aggregations

AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)38 AccessControlList (org.opencastproject.security.api.AccessControlList)30 Test (org.junit.Test)18 MediaPackage (org.opencastproject.mediapackage.MediaPackage)12 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)7 Job (org.opencastproject.job.api.Job)6 JaxbRole (org.opencastproject.security.api.JaxbRole)6 JobBarrier (org.opencastproject.job.api.JobBarrier)5 JaxbUser (org.opencastproject.security.api.JaxbUser)5 Date (java.util.Date)4 List (java.util.List)4 Map (java.util.Map)4 SearchQuery (org.opencastproject.search.api.SearchQuery)4 AuthorizationService (org.opencastproject.security.api.AuthorizationService)4 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)4 SecurityService (org.opencastproject.security.api.SecurityService)4 User (org.opencastproject.security.api.User)4 NotFoundException (org.opencastproject.util.NotFoundException)4 File (java.io.File)3