Search in sources :

Example 11 with SeriesACLTransition

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

the class AccessInformationUtilTest method testSerializeSeriesACLTransition.

/**
 * Test method for {@link AccessInformationUtil#serializeSeriesACLTransition(SeriesACLTransition)}
 */
@Test
public void testSerializeSeriesACLTransition() throws Exception {
    ManagedAcl acl = createNiceMock(ManagedAcl.class);
    expect(acl.getId()).andStubReturn(TRANSITION_ACL_ID);
    replay(acl);
    SeriesACLTransition trans = createNiceMock(SeriesACLTransition.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(acl);
    expect(trans.isOverride()).andStubReturn(TRANSITION_OVERRIDE_EPISODES);
    replay(trans);
    JSONObject t = AccessInformationUtil.serializeSeriesACLTransition(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_DONE, t.getBoolean("done"));
    assertEquals(TRANSITION_ACL_ID, t.getLong("acl_id"));
    assertEquals(TRANSITION_OVERRIDE_EPISODES, t.getBoolean("override_episodes"));
}
Also used : SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) JSONObject(org.codehaus.jettison.json.JSONObject) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) Date(java.util.Date) Test(org.junit.Test)

Example 12 with SeriesACLTransition

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

the class SeriesEndpoint method getSeriesAccessInformation.

@GET
@Path("{seriesId}/access.json")
@SuppressWarnings("unchecked")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getseriesaccessinformation", description = "Get the access information of a series", returnDescription = "The access information", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = 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 series has not been found."), @RestResponse(responseCode = SC_OK, description = "The access information ") })
public Response getSeriesAccessInformation(@PathParam("seriesId") String seriesId) throws NotFoundException {
    if (StringUtils.isBlank(seriesId))
        return RestUtil.R.badRequest("Path parameter series ID is missing");
    boolean hasProcessingEvents = hasProcessingEvents(seriesId);
    // 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));
    }
    final TransitionQuery q = TransitionQuery.query().withId(seriesId).withScope(AclScope.Series);
    List<SeriesACLTransition> seriesTransistions;
    JSONArray transitionsJson = new JSONArray();
    try {
        seriesTransistions = getAclService().getTransitions(q).getSeriesTransistions();
        for (SeriesACLTransition trans : seriesTransistions) {
            transitionsJson.add(AccessInformationUtil.serializeSeriesACLTransition(trans));
        }
    } catch (AclServiceException e) {
        logger.error("There was an error while trying to get the ACL transitions for serie '{}' from the ACL service: {}", seriesId, e);
        return RestUtil.R.serverError();
    }
    JSONObject seriesAccessJson = new JSONObject();
    try {
        AccessControlList seriesAccessControl = seriesService.getSeriesAccessControl(seriesId);
        Option<ManagedAcl> currentAcl = AccessInformationUtil.matchAcls(acls, seriesAccessControl);
        seriesAccessJson.put("current_acl", currentAcl.isSome() ? currentAcl.get().getId() : 0);
        seriesAccessJson.put("privileges", AccessInformationUtil.serializePrivilegesByRole(seriesAccessControl));
        seriesAccessJson.put("acl", AccessControlParser.toJsonSilent(seriesAccessControl));
        seriesAccessJson.put("transitions", transitionsJson);
        seriesAccessJson.put("locked", hasProcessingEvents);
    } catch (SeriesException e) {
        logger.error("Unable to get ACL from series {}: {}", seriesId, ExceptionUtils.getStackTrace(e));
        return RestUtil.R.serverError();
    }
    JSONObject jsonReturnObj = new JSONObject();
    jsonReturnObj.put("system_acls", systemAclsJson);
    jsonReturnObj.put("series_access", seriesAccessJson);
    return Response.ok(jsonReturnObj.toString()).build();
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) SeriesException(org.opencastproject.series.api.SeriesException) 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