Search in sources :

Example 16 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class AclScannerTest method testCorrectFileInstall.

@Test
public void testCorrectFileInstall() throws Exception {
    File file = new File(AclScannerTest.class.getResource("/xacml_correct.xml").toURI());
    ManagedAcl acl = new ManagedAclImpl(1L, "TestAcl", "org", new AccessControlList());
    Option<ManagedAcl> managedAcl = Option.some(acl);
    EasyMock.expect(aclDb.createAcl(anyObject(Organization.class), anyObject(AccessControlList.class), anyString())).andReturn(managedAcl).times(3);
    EasyMock.expect(aclDb.getAcls(anyObject(Organization.class))).andReturn(new ArrayList<ManagedAcl>()).times(3);
    EasyMock.replay(aclDb);
    aclScanner.install(file);
    EasyMock.verify(aclDb);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 17 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class AclScannerTest method testRemoveFile.

@Test
public void testRemoveFile() throws Exception {
    File file1 = new File(AclScannerTest.class.getResource("/xacml_correct.xml").toURI());
    Long id = 1L;
    String org = "org";
    ManagedAcl acl = new ManagedAclImpl(id, "TestAcl", org, new AccessControlList());
    Option<ManagedAcl> managedAcl = Option.some(acl);
    EasyMock.expect(aclDb.createAcl(anyObject(Organization.class), anyObject(AccessControlList.class), anyString())).andReturn(managedAcl).times(3);
    EasyMock.expect(aclDb.getAcl(EasyMock.anyObject(Organization.class), anyLong())).andReturn(managedAcl).times(3);
    EasyMock.expect(aclDb.deleteAcl(anyObject(Organization.class), anyLong())).andReturn(true).times(3);
    EasyMock.expect(aclDb.getAcls(anyObject(Organization.class))).andReturn(new ArrayList<ManagedAcl>()).times(3);
    EasyMock.replay(aclDb);
    aclScanner.install(file1);
    aclScanner.uninstall(file1);
    EasyMock.verify(aclDb);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) EasyMock.anyLong(org.easymock.EasyMock.anyLong) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ArrayList(java.util.ArrayList) EasyMock.anyString(org.easymock.EasyMock.anyString) File(java.io.File) Test(org.junit.Test)

Example 18 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class AclScannerTest method testCorrectFileUpdate.

@Test
public void testCorrectFileUpdate() throws Exception {
    File file = new File(AclScannerTest.class.getResource("/xacml_correct.xml").toURI());
    ManagedAcl acl = new ManagedAclImpl(1L, "TestAcl", "org", new AccessControlList());
    Option<ManagedAcl> managedAcl = Option.some(acl);
    EasyMock.expect(aclDb.createAcl(anyObject(Organization.class), anyObject(AccessControlList.class), anyString())).andReturn(managedAcl).times(3);
    EasyMock.expect(aclDb.getAcl(anyObject(Organization.class), anyLong())).andReturn(managedAcl).times(3);
    EasyMock.expect(aclDb.updateAcl(anyObject(ManagedAcl.class))).andReturn(true).times(3);
    EasyMock.expect(aclDb.getAcls(anyObject(Organization.class))).andReturn(new ArrayList<ManagedAcl>()).times(3);
    EasyMock.replay(aclDb);
    aclScanner.install(file);
    aclScanner.update(file);
    EasyMock.verify(aclDb);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 19 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class OsgiJpaAclTransitionDbTest method testStoreAndGetEpisodeACL.

@Test
public void testStoreAndGetEpisodeACL() throws Exception {
    final Date now = new Date();
    // a fallback to series transition should be saveable
    db.storeEpisodeAclTransition(ORG, "uuid", now, none(0L), Option.<ConfiguredWorkflowRef>none());
    // a transition referencing a non existing ACL should not be saveable
    try {
        db.storeEpisodeAclTransition(ORG, "uuid", new Date(), some(1L), Option.<ConfiguredWorkflowRef>none());
        fail("No ACL with ID 1");
    } catch (AclTransitionDbException ignore) {
    }
    // a transition referencing an existing ACL should be saveable
    final ManagedAcl macl = createAcl();
    final EpisodeACLTransition t3 = db.storeEpisodeAclTransition(ORG, "uuid-2", now, some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
    assertEquals("uuid-2", t3.getEpisodeId());
    assertEquals(now, t3.getApplicationDate());
    assertTrue(t3.getAccessControlList().isSome());
    assertEquals(macl.getName(), t3.getAccessControlList().get().getName());
    // a transition with the same properties should not be saveable
    try {
        db.storeEpisodeAclTransition(ORG, "uuid", now, some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
        fail("Duplicated episode ACL must not be stored");
    } catch (AclTransitionDbDuplicatedException ignore) {
    }
    List<EpisodeACLTransition> ts = db.getEpisodeAclTransitions(ORG, "uuid");
    assertEquals(1, ts.size());
    assertEquals("uuid", ts.get(0).getEpisodeId());
    assertTrue(ts.get(0).isDelete());
    assertTrue(!ts.get(0).isDone());
}
Also used : ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) Date(java.util.Date) Test(org.junit.Test)

Example 20 with ManagedAcl

use of org.opencastproject.authorization.xacml.manager.api.ManagedAcl in project opencast by opencast.

the class OsgiJpaAclTransitionDbTest method testGetByQuery.

@Test
public void testGetByQuery() throws Exception {
    final ManagedAcl macl = createAcl();
    SeriesACLTransition st1 = db.storeSeriesAclTransition(ORG, "uuid-series", new Date(1347000000000L), macl.getId(), true, Option.<ConfiguredWorkflowRef>none());
    SeriesACLTransition st2 = db.storeSeriesAclTransition(ORG, "uuid-series", new Date(1347000900000L), macl.getId(), false, Option.<ConfiguredWorkflowRef>none());
    SeriesACLTransition st3 = db.storeSeriesAclTransition(ORG, "uuid-series2", new Date(1347000030000L), macl.getId(), false, option(workflow("full")));
    SeriesACLTransition st4 = db.markSeriesTransitionAsCompleted(ORG, st3.getTransitionId());
    EpisodeACLTransition et1 = db.storeEpisodeAclTransition(ORG, "uuid-episode", new Date(1347005303736L), Option.<Long>none(), Option.<ConfiguredWorkflowRef>none());
    EpisodeACLTransition et2 = db.storeEpisodeAclTransition(ORG, "uuid-episode", new Date(1347005343736L), some(macl.getId()), Option.<ConfiguredWorkflowRef>none());
    EpisodeACLTransition et3 = db.storeEpisodeAclTransition(ORG, "uuid-episode2", new Date(1347005343736L), some(macl.getId()), option(workflow("full")));
    EpisodeACLTransition et4 = db.markEpisodeTransitionAsCompleted(ORG, et3.getTransitionId());
    // Test All
    TransitionQuery query = TransitionQuery.query();
    TransitionResult result = db.getByQuery(ORG, query);
    assertEquals(3, result.getEpisodeTransistions().size());
    assertEquals(3, result.getSeriesTransistions().size());
    assertEquals(et1.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
    assertEquals(et2.getTransitionId(), result.getEpisodeTransistions().get(1).getTransitionId());
    assertEquals(et4.getTransitionId(), result.getEpisodeTransistions().get(2).getTransitionId());
    assertEquals(st1.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
    assertEquals(st4.getTransitionId(), result.getSeriesTransistions().get(1).getTransitionId());
    assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(2).getTransitionId());
    // Test Episode
    query.withScope(AclScope.Episode);
    result = db.getByQuery(ORG, query);
    assertEquals(3, result.getEpisodeTransistions().size());
    assertEquals(0, result.getSeriesTransistions().size());
    assertEquals(et1.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
    assertEquals(et2.getTransitionId(), result.getEpisodeTransistions().get(1).getTransitionId());
    assertEquals(et3.getTransitionId(), result.getEpisodeTransistions().get(2).getTransitionId());
    query.withScope(AclScope.Episode);
    result = db.getByQuery(ORG2, query);
    assertEquals(0, result.getEpisodeTransistions().size());
    assertEquals(0, result.getSeriesTransistions().size());
    // Test Series
    query.withScope(AclScope.Series);
    result = db.getByQuery(ORG, query);
    assertEquals(0, result.getEpisodeTransistions().size());
    assertEquals(3, result.getSeriesTransistions().size());
    assertEquals(st1.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
    assertEquals(st3.getTransitionId(), result.getSeriesTransistions().get(1).getTransitionId());
    assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(2).getTransitionId());
    // Test Date from
    query = TransitionQuery.query().after(new Date(1347000040000L));
    result = db.getByQuery(ORG, query);
    assertEquals(3, result.getEpisodeTransistions().size());
    assertEquals(1, result.getSeriesTransistions().size());
    assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
    // Test Date from, to
    query.before(new Date(1347005313736L)).after(new Date(1347000040000L));
    result = db.getByQuery(ORG, query);
    assertEquals(1, result.getEpisodeTransistions().size());
    assertEquals(1, result.getSeriesTransistions().size());
    assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
    assertEquals(et1.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
    // Test id
    query = TransitionQuery.query().withId("uuid-series");
    result = db.getByQuery(ORG, query);
    assertEquals(0, result.getEpisodeTransistions().size());
    assertEquals(2, result.getSeriesTransistions().size());
    assertEquals(st1.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
    assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(1).getTransitionId());
    query = TransitionQuery.query().withId("uuid-series");
    result = db.getByQuery(ORG2, query);
    assertEquals(0, result.getEpisodeTransistions().size());
    assertEquals(0, result.getSeriesTransistions().size());
    // Test transitionId
    result = db.getByQuery(ORG, TransitionQuery.query().withTransitionId(et2.getTransitionId()));
    assertEquals(1, result.getEpisodeTransistions().size());
    assertEquals(0, result.getSeriesTransistions().size());
    assertEquals(et2.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
    // Test is done
    query = TransitionQuery.query().withDone(false);
    result = db.getByQuery(ORG, query);
    assertEquals(2, result.getEpisodeTransistions().size());
    assertEquals(2, result.getSeriesTransistions().size());
    assertEquals(et1.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
    assertEquals(et2.getTransitionId(), result.getEpisodeTransistions().get(1).getTransitionId());
    assertEquals(st1.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
    assertEquals(st2.getTransitionId(), result.getSeriesTransistions().get(1).getTransitionId());
    query.withDone(true);
    result = db.getByQuery(ORG, query);
    assertEquals(1, result.getEpisodeTransistions().size());
    assertEquals(1, result.getSeriesTransistions().size());
    assertEquals(et3.getTransitionId(), result.getEpisodeTransistions().get(0).getTransitionId());
    assertEquals(st3.getTransitionId(), result.getSeriesTransistions().get(0).getTransitionId());
}
Also used : SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) TransitionResult(org.opencastproject.authorization.xacml.manager.api.TransitionResult) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)35 Test (org.junit.Test)18 AccessControlList (org.opencastproject.security.api.AccessControlList)16 Date (java.util.Date)12 SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)8 ArrayList (java.util.ArrayList)7 EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)7 NotFoundException (org.opencastproject.util.NotFoundException)7 File (java.io.File)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 RestQuery (org.opencastproject.util.doc.rest.RestQuery)5 TransitionQuery (org.opencastproject.authorization.xacml.manager.api.TransitionQuery)4 AclTransitionDbException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)4 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)4 GET (javax.ws.rs.GET)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 ManagedAclImpl (org.opencastproject.authorization.xacml.manager.impl.ManagedAclImpl)3 Event (org.opencastproject.index.service.impl.index.event.Event)3