Search in sources :

Example 11 with EpisodeACLTransition

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

Example 12 with EpisodeACLTransition

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

the class AccessInformationUtilTest method testSerializeEpisodeACLTransition.

/**
 * Test method for {@link AccessInformationUtil#serializeEpisodeACLTransition(EpisodeACLTransition)}
 */
@Test
public void testSerializeEpisodeACLTransition() throws Exception {
    ManagedAcl acl = createNiceMock(ManagedAcl.class);
    expect(acl.getId()).andStubReturn(TRANSITION_ACL_ID);
    replay(acl);
    EpisodeACLTransition trans = createNiceMock(EpisodeACLTransition.class);
    expect(trans.getTransitionId()).andStubReturn(TRANSITION_ID);
    expect(trans.getApplicationDate()).andStubReturn(TRANSITION_APPLICATION_DATE);
    expect(trans.getWorkflow()).andStubReturn(TRANSITION_WORKFLOW_ID);
    expect(trans.isDone()).andStubReturn(TRANSITION_DONE);
    expect(trans.getAccessControlList()).andStubReturn(Option.some(acl));
    expect(trans.isDelete()).andStubReturn(TRANSITION_IS_DELETED);
    replay(trans);
    JSONObject t = AccessInformationUtil.serializeEpisodeACLTransition(trans);
    assertEquals(TRANSITION_ID, t.getLong("id"));
    assertEquals(TRANSITION_APPLICATION_DATE, new Date(DateTimeSupport.fromUTC(t.getString("application_date"))));
    assertEquals(TRANSITION_WORKFLOW_ID, Option.some(ConfiguredWorkflowRef.workflow(t.getString("workflow_id"))));
    assertEquals(TRANSITION_IS_DELETED, t.getBoolean("is_deleted"));
    assertEquals(TRANSITION_ACL_ID, t.getLong("acl_id"));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Date(java.util.Date) Test(org.junit.Test)

Example 13 with EpisodeACLTransition

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

the class AbstractEventEndpoint method getEventAccessInformation.

@GET
@Path("{eventId}/access.json")
@SuppressWarnings("unchecked")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getEventAccessInformation", description = "Get the access information of an event", returnDescription = "The access information", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required form params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event has not been found."), @RestResponse(responseCode = SC_OK, description = "The access information ") })
public Response getEventAccessInformation(@PathParam("eventId") String eventId) throws Exception {
    Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
    if (optEvent.isNone())
        return notFound("Cannot find an event with id '%s'.", eventId);
    // Add all available ACLs to the response
    JSONArray systemAclsJson = new JSONArray();
    List<ManagedAcl> acls = getAclService().getAcls();
    for (ManagedAcl acl : acls) {
        systemAclsJson.add(AccessInformationUtil.serializeManagedAcl(acl));
    }
    // Get the episode ACL
    final TransitionQuery q = TransitionQuery.query().withId(eventId).withScope(AclScope.Episode);
    List<EpisodeACLTransition> episodeTransistions;
    JSONArray transitionsJson = new JSONArray();
    try {
        episodeTransistions = getAclService().getTransitions(q).getEpisodeTransistions();
        for (EpisodeACLTransition trans : episodeTransistions) {
            transitionsJson.add(AccessInformationUtil.serializeEpisodeACLTransition(trans));
        }
    } catch (AclServiceException e) {
        logger.error("There was an error while trying to get the ACL transitions for series '{}' from the ACL service: {}", eventId, ExceptionUtils.getStackTrace(e));
        return RestUtil.R.serverError();
    }
    AccessControlList activeAcl = new AccessControlList();
    try {
        if (optEvent.get().getAccessPolicy() != null)
            activeAcl = AccessControlParser.parseAcl(optEvent.get().getAccessPolicy());
    } catch (Exception e) {
        logger.error("Unable to parse access policy because: {}", ExceptionUtils.getStackTrace(e));
    }
    Option<ManagedAcl> currentAcl = AccessInformationUtil.matchAcls(acls, activeAcl);
    JSONObject episodeAccessJson = new JSONObject();
    episodeAccessJson.put("current_acl", currentAcl.isSome() ? currentAcl.get().getId() : 0L);
    episodeAccessJson.put("acl", AccessControlParser.toJsonSilent(activeAcl));
    episodeAccessJson.put("privileges", AccessInformationUtil.serializePrivilegesByRole(activeAcl));
    episodeAccessJson.put("transitions", transitionsJson);
    if (StringUtils.isNotBlank(optEvent.get().getWorkflowState()) && WorkflowUtil.isActive(WorkflowInstance.WorkflowState.valueOf(optEvent.get().getWorkflowState())))
        episodeAccessJson.put("locked", true);
    JSONObject jsonReturnObj = new JSONObject();
    jsonReturnObj.put("episode_access", episodeAccessJson);
    jsonReturnObj.put("system_acls", systemAclsJson);
    return Response.ok(jsonReturnObj.toString()).build();
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) JSONArray(org.json.simple.JSONArray) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) EventCommentException(org.opencastproject.event.comment.EventCommentException) JSONException(org.codehaus.jettison.json.JSONException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) JSONObject(org.json.simple.JSONObject) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) Event(org.opencastproject.index.service.impl.index.event.Event) 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

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