Search in sources :

Example 11 with AclServiceException

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

Example 12 with AclServiceException

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

the class AbstractEventEndpoint method addEventTransition.

@POST
@Path("{eventId}/transitions")
@RestQuery(name = "addEventTransition", description = "Adds an ACL transition to an event", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(name = "transition", isRequired = true, description = "The transition (JSON object) to add", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required params were missing in the request."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method doesn't return any content"), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event has not been found.") })
public Response addEventTransition(@PathParam("eventId") String eventId, @FormParam("transition") String transitionStr) throws SearchIndexException {
    if (StringUtils.isBlank(eventId) || StringUtils.isBlank(transitionStr))
        return RestUtil.R.badRequest("Missing parameters");
    Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
    if (optEvent.isNone())
        return notFound("Cannot find an event with id '%s'.", eventId);
    try {
        final org.codehaus.jettison.json.JSONObject t = new org.codehaus.jettison.json.JSONObject(transitionStr);
        Option<ConfiguredWorkflowRef> workflowRef;
        if (t.has("workflow_id"))
            workflowRef = Option.some(ConfiguredWorkflowRef.workflow(t.getString("workflow_id")));
        else
            workflowRef = Option.none();
        Option<Long> managedAclId;
        if (t.has("acl_id"))
            managedAclId = Option.some(t.getLong("acl_id"));
        else
            managedAclId = Option.none();
        getAclService().addEpisodeTransition(eventId, managedAclId, new Date(DateTimeSupport.fromUTC(t.getString("application_date"))), workflowRef);
        return Response.noContent().build();
    } catch (AclServiceException e) {
        logger.error("Error while trying to get ACL transitions for event '{}' from ACL service: {}", eventId, e);
        throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
    } catch (JSONException e) {
        return RestUtil.R.badRequest("The transition object is not valid");
    } catch (IllegalStateException e) {
        // That should never happen
        throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
    } catch (ParseException e) {
        return RestUtil.R.badRequest("The date could not be parsed");
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) JSONException(org.codehaus.jettison.json.JSONException) Date(java.util.Date) JSONObject(org.json.simple.JSONObject) Event(org.opencastproject.index.service.impl.index.event.Event) ParseException(java.text.ParseException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 13 with AclServiceException

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

AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)13 Path (javax.ws.rs.Path)11 RestQuery (org.opencastproject.util.doc.rest.RestQuery)11 WebApplicationException (javax.ws.rs.WebApplicationException)9 NotFoundException (org.opencastproject.util.NotFoundException)9 ConfiguredWorkflowRef (org.opencastproject.workflow.api.ConfiguredWorkflowRef)8 Date (java.util.Date)7 POST (javax.ws.rs.POST)6 Produces (javax.ws.rs.Produces)6 SeriesException (org.opencastproject.series.api.SeriesException)6 JSONObject (org.json.simple.JSONObject)5 AccessControlList (org.opencastproject.security.api.AccessControlList)5 ParseException (java.text.ParseException)4 JSONException (org.codehaus.jettison.json.JSONException)4 AclServiceNoReferenceException (org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException)4 AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)4 Event (org.opencastproject.index.service.impl.index.event.Event)4 PUT (javax.ws.rs.PUT)3 EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)3 SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)3