Search in sources :

Example 31 with AccessControlList

use of org.opencastproject.security.api.AccessControlList 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 32 with AccessControlList

use of org.opencastproject.security.api.AccessControlList 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)

Example 33 with AccessControlList

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

the class SeriesServiceImplTest method testACLEquality3.

@Test
public void testACLEquality3() {
    AccessControlList a = new AccessControlList();
    AccessControlList b = new AccessControlList(new AccessControlEntry("b", Permissions.Action.WRITE.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 34 with AccessControlList

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

the class SeriesServiceSolrTest method testAccessControlManagmentRewrite.

@Test
public void testAccessControlManagmentRewrite() throws Exception {
    // sample access control list
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    User user = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole("ROLE_ANONYMOUS", new DefaultOrganization()));
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.replay(securityService);
    // deactivate the default index created in setUp()
    index.deactivate();
    // create a new index with the security service anonymous user
    index = new SeriesServiceSolrIndex();
    index.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
    dcService = new DublinCoreCatalogService();
    index.setDublinCoreService(dcService);
    index.setSecurityService(securityService);
    index.activate(null);
    AccessControlList accessControlList = new AccessControlList();
    List<AccessControlEntry> acl = accessControlList.getEntries();
    acl.add(new AccessControlEntry("ROLE_ANONYMOUS", Permissions.Action.READ.toString(), true));
    index.updateIndex(testCatalog);
    String seriesID = testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER);
    index.updateSecurityPolicy(seriesID, accessControlList);
    SeriesQuery q = new SeriesQuery();
    DublinCoreCatalogList result = index.search(q);
    Assert.assertTrue("Only one anomymous series", result.size() == 1);
    index.updateSecurityPolicy(seriesID, new AccessControlList());
    q = new SeriesQuery();
    result = index.search(q);
    Assert.assertTrue("No anomymous series", result.size() == 0);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SeriesQuery(org.opencastproject.series.api.SeriesQuery) DublinCoreCatalogList(org.opencastproject.metadata.dublincore.DublinCoreCatalogList) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) JaxbUser(org.opencastproject.security.api.JaxbUser) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Test(org.junit.Test)

Example 35 with AccessControlList

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

the class SeriesServiceSolrTest method testAccessControlManagment.

@Test
public void testAccessControlManagment() throws Exception {
    // sample access control list
    AccessControlList accessControlList = new AccessControlList();
    List<AccessControlEntry> acl = accessControlList.getEntries();
    acl.add(new AccessControlEntry("admin", "delete", true));
    index.updateIndex(testCatalog);
    String seriesID = testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER);
    index.updateSecurityPolicy(seriesID, accessControlList);
    AccessControlList retrievedACL = index.getAccessControl(seriesID);
    Assert.assertNotNull(retrievedACL);
    acl = retrievedACL.getEntries();
    Assert.assertEquals(acl.size(), 1);
    Assert.assertEquals(acl.get(0).getRole(), "admin");
    try {
        index.updateSecurityPolicy("failid", accessControlList);
        Assert.fail("Should fail when indexing ACL to nonexistent series");
    } catch (NotFoundException e) {
    // expected
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) NotFoundException(org.opencastproject.util.NotFoundException) Test(org.junit.Test)

Aggregations

AccessControlList (org.opencastproject.security.api.AccessControlList)108 NotFoundException (org.opencastproject.util.NotFoundException)46 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)38 AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)30 MediaPackage (org.opencastproject.mediapackage.MediaPackage)27 Test (org.junit.Test)26 IOException (java.io.IOException)22 Organization (org.opencastproject.security.api.Organization)22 User (org.opencastproject.security.api.User)21 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)19 ArrayList (java.util.ArrayList)18 SeriesException (org.opencastproject.series.api.SeriesException)18 ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)16 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)16 Date (java.util.Date)15 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)14 Path (javax.ws.rs.Path)13 RestQuery (org.opencastproject.util.doc.rest.RestQuery)13 WebApplicationException (javax.ws.rs.WebApplicationException)12 File (java.io.File)10