Search in sources :

Example 6 with SeriesACLTransition

use of org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition 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 7 with SeriesACLTransition

use of org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition 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)

Example 8 with SeriesACLTransition

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

the class OsgiJpaAclTransitionDbTest method testUpdateSeries.

@Test
public void testUpdateSeries() throws Exception {
    final ManagedAcl macl = createAcl();
    SeriesACLTransition t1 = db.storeSeriesAclTransition(ORG, "uuid", new Date(), macl.getId(), true, Option.<ConfiguredWorkflowRef>none());
    SeriesACLTransition u1 = db.updateSeriesAclTransition(ORG, t1.getTransitionId(), t1.getApplicationDate(), macl.getId(), false, Option.some(workflow("full")));
    assertEquals(t1.getTransitionId(), u1.getTransitionId());
    assertEquals(t1.getSeriesId(), u1.getSeriesId());
    assertEquals(t1.getOrganizationId(), u1.getOrganizationId());
    assertEquals(t1.getAccessControlList().getId(), u1.getAccessControlList().getId());
    assertNotSame(t1.getWorkflow(), u1.getWorkflow());
    assertNotSame(t1.isOverride(), u1.isOverride());
    try {
        db.updateSeriesAclTransition(ORG2, t1.getTransitionId(), t1.getApplicationDate(), macl.getId(), false, Option.some(workflow("full")));
        fail("Updating from non-owner org should not be possible");
    } catch (AclTransitionDbException ignore1) {
    } catch (NotFoundException ignore2) {
    }
}
Also used : SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) NotFoundException(org.opencastproject.util.NotFoundException) AclTransitionDbException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException) Date(java.util.Date) Test(org.junit.Test)

Example 9 with SeriesACLTransition

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

the class OsgiJpaAclTransitionDbTest method testGetSeriesTransitions.

@Test
public void testGetSeriesTransitions() throws Exception {
    final ManagedAcl macl = createAcl();
    db.storeSeriesAclTransition(ORG, "uuid", new Date(), macl.getId(), true, Option.<ConfiguredWorkflowRef>none());
    db.storeSeriesAclTransition(ORG, "uuid", new Date(), macl.getId(), false, Option.<ConfiguredWorkflowRef>none());
    // there should now be two transitions for series "uuid"
    List<SeriesACLTransition> series = db.getSeriesAclTransitions(ORG, "uuid");
    assertEquals(2, series.size());
    // transitions shouldn't be accessible from another organization
    assertEquals(0, db.getSeriesAclTransitions(ORG2, "uuid").size());
}
Also used : SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) Date(java.util.Date) Test(org.junit.Test)

Example 10 with SeriesACLTransition

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

the class AbstractAclServiceRestEndpoint method getTransitionsFor.

@GET
@Path("/transitionsfor.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getTransitionsForAsJson", description = "Get the transitions for a list of episodes and/or series as json. At least one of the lists must not be empty.", returnDescription = "Get the transitions as json", restParameters = { @RestParameter(name = "episodeIds", isRequired = false, description = "A list of comma separated episode IDs", type = STRING), @RestParameter(name = "seriesIds", isRequired = false, description = "A list of comma separated series IDs", type = STRING), @RestParameter(name = "done", isRequired = false, description = "Indicates if already applied transitions should be included", type = BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The request was processed succesfully"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Parameter error"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during processing the request") })
public Response getTransitionsFor(@QueryParam("episodeIds") String episodeIds, @QueryParam("seriesIds") String seriesIds, @DefaultValue("false") @QueryParam("done") final boolean done) {
    final Monadics.ListMonadic<String> eIds = splitCommaSeparatedParam(option(episodeIds));
    final Monadics.ListMonadic<String> sIds = splitCommaSeparatedParam(option(seriesIds));
    if (eIds.value().isEmpty() && sIds.value().isEmpty()) {
        return badRequest();
    }
    final AclService aclService = aclService();
    try {
        // episodeId -> [transitions]
        final Map<String, List<EpisodeACLTransition>> eTs = eIds.foldl(MultiMap.<String, EpisodeACLTransition>multiHashMapWithArrayList(), new Function2.X<MultiMap<String, EpisodeACLTransition>, String, MultiMap<String, EpisodeACLTransition>>() {

            @Override
            public MultiMap<String, EpisodeACLTransition> xapply(MultiMap<String, EpisodeACLTransition> mmap, String id) throws Exception {
                // todo it is quite expensive to query each episode separately
                final TransitionQuery q = TransitionQuery.query().withId(id).withScope(AclScope.Episode).withDone(done);
                return mmap.putAll(id, aclService.getTransitions(q).getEpisodeTransistions());
            }
        }).value();
        // seriesId -> [transitions]
        final Map<String, List<SeriesACLTransition>> sTs = sIds.foldl(MultiMap.<String, SeriesACLTransition>multiHashMapWithArrayList(), new Function2.X<MultiMap<String, SeriesACLTransition>, String, MultiMap<String, SeriesACLTransition>>() {

            @Override
            public MultiMap<String, SeriesACLTransition> xapply(MultiMap<String, SeriesACLTransition> mmap, String id) throws Exception {
                // todo it is quite expensive to query each series separately
                final TransitionQuery q = TransitionQuery.query().withId(id).withScope(AclScope.Series).withDone(done);
                return mmap.putAll(id, aclService.getTransitions(q).getSeriesTransistions());
            }
        }).value();
        final Jsons.Obj episodesObj = buildEpisodesObj(eTs);
        final Jsons.Obj seriesObj = buildSeriesObj(sTs);
        return ok(obj(p("episodes", episodesObj), p("series", seriesObj)).toJson());
    } catch (Exception e) {
        logger.error("Error generating getTransitionsFor response", e);
        return serverError();
    }
}
Also used : Monadics(org.opencastproject.util.data.Monadics) Jsons(org.opencastproject.util.Jsons) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) NotFoundException(org.opencastproject.util.NotFoundException) MultiMap(org.opencastproject.util.data.MultiMap) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) JsonConv.fullAccessControlList(org.opencastproject.authorization.xacml.manager.endpoint.JsonConv.fullAccessControlList) List(java.util.List) AccessControlList(org.opencastproject.security.api.AccessControlList) AclService(org.opencastproject.authorization.xacml.manager.api.AclService) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)12 Date (java.util.Date)9 ManagedAcl (org.opencastproject.authorization.xacml.manager.api.ManagedAcl)8 Test (org.junit.Test)6 NotFoundException (org.opencastproject.util.NotFoundException)5 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)4 AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)4 SeriesException (org.opencastproject.series.api.SeriesException)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 AclServiceNoReferenceException (org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException)3 EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)3 TransitionQuery (org.opencastproject.authorization.xacml.manager.api.TransitionQuery)3 GET (javax.ws.rs.GET)2 AclTransitionDbException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbException)2 AccessControlList (org.opencastproject.security.api.AccessControlList)2 ConfiguredWorkflowRef (org.opencastproject.workflow.api.ConfiguredWorkflowRef)2 ArrayList (java.util.ArrayList)1