Search in sources :

Example 1 with AclServiceException

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

the class AbstractAclServiceRestEndpoint method updateEpisodeTransition.

@PUT
@Path("/episode/{transitionId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateepisodetransition", description = "Update an existing episode transition", returnDescription = "Update an existing episode transition", pathParameters = { @RestParameter(name = "transitionId", isRequired = true, description = "The transition id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = false, description = "The managed access control list id", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The workflow definition identifier", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "The workflow parameters as JSON", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The episode transition has successfully been updated"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during updating an episode transition") })
public String updateEpisodeTransition(@PathParam("transitionId") long transitionId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") Long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) throws NotFoundException {
    try {
        final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
        final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
        final EpisodeACLTransition t = aclService().updateEpisodeTransition(transitionId, option(managedAclId), at, workflow);
        return JsonConv.full(t).toJson();
    } catch (AclServiceException e) {
        logger.warn("Error updating episode transition:", e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.warn("Unable to parse the application date");
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(org.opencastproject.util.NotFoundException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Date(java.util.Date) 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) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 2 with AclServiceException

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

the class AbstractAclServiceRestEndpoint method addSeriesTransition.

@POST
@Path("/series/{seriesId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "addseriestransition", description = "Add a series transition", returnDescription = "Add a series transition", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = true, description = "The managed access control list id", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The workflow definition identifier", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "The workflow parameters as JSON", type = STRING), @RestParameter(name = "override", isRequired = false, description = "If to override the episode ACL's", type = STRING, defaultValue = "false") }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series transition has successfully been added"), @RestResponse(responseCode = SC_CONFLICT, description = "The series transition with the applicationDate already exists"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The given managed acl id could not be found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding a series transition") })
public String addSeriesTransition(@PathParam("seriesId") String seriesId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams, @FormParam("override") boolean override) {
    try {
        final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
        final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
        SeriesACLTransition seriesTransition = aclService().addSeriesTransition(seriesId, managedAclId, at, override, workflow);
        return JsonConv.full(seriesTransition).toJson();
    } catch (AclServiceNoReferenceException e) {
        logger.info("Managed acl with id '{}' coudl not be found", managedAclId);
        throw new WebApplicationException(Status.BAD_REQUEST);
    } catch (AclTransitionDbDuplicatedException e) {
        logger.info("Error adding series transition: transition with date {} already exists", applicationDate);
        throw new WebApplicationException(Status.CONFLICT);
    } catch (AclServiceException e) {
        logger.warn("Error adding series transition:", e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (Exception e) {
        logger.warn("Unable to parse the application date");
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) WebApplicationException(javax.ws.rs.WebApplicationException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) Date(java.util.Date) 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) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 3 with AclServiceException

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

the class AbstractAclServiceRestEndpoint method updateSeriesTransition.

@PUT
@Path("/series/{transitionId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateseriestransition", description = "Update an existing series transition", returnDescription = "Update an existing series transition", pathParameters = { @RestParameter(name = "transitionId", isRequired = true, description = "The transition id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = true, description = "The managed access control list id", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The workflow definition identifier", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "The workflow parameters as JSON", type = STRING), @RestParameter(name = "override", isRequired = false, description = "If to override the episode ACL's", type = STRING, defaultValue = "false") }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series transition has successfully been updated"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The given managed acl id could not be found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during updating a series transition") })
public String updateSeriesTransition(@PathParam("transitionId") long transitionId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams, @FormParam("override") boolean override) throws NotFoundException {
    try {
        final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
        final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
        final SeriesACLTransition t = aclService().updateSeriesTransition(transitionId, managedAclId, at, workflow, override);
        return JsonConv.full(t).toJson();
    } catch (AclServiceNoReferenceException e) {
        logger.info("Managed acl with id '{}' could not be found", managedAclId);
        throw new WebApplicationException(Status.BAD_REQUEST);
    } catch (AclServiceException e) {
        logger.warn("Error updating series transition:", e);
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        logger.warn("Unable to parse the application date");
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) WebApplicationException(javax.ws.rs.WebApplicationException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) NotFoundException(org.opencastproject.util.NotFoundException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) Date(java.util.Date) 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) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 4 with AclServiceException

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

the class AclServiceImpl method applyAclToEpisode.

@Override
public boolean applyAclToEpisode(String episodeId, AccessControlList acl, Option<ConfiguredWorkflowRef> workflow) throws AclServiceException {
    try {
        Option<MediaPackage> mediaPackage = Option.none();
        if (assetManager != null)
            mediaPackage = getFromAssetManagerByMpId(episodeId);
        Option<AccessControlList> aclOpt = Option.option(acl);
        // the episode service is the source of authority for the retrieval of media packages
        for (final MediaPackage episodeSvcMp : mediaPackage) {
            aclOpt.fold(new Option.EMatch<AccessControlList>() {

                // set the new episode ACL
                @Override
                public void esome(final AccessControlList acl) {
                    // update in episode service
                    MediaPackage mp = authorizationService.setAcl(episodeSvcMp, AclScope.Episode, acl).getA();
                    if (assetManager != null)
                        assetManager.takeSnapshot(mp);
                }

                // if none EpisodeACLTransition#isDelete returns true so delete the episode ACL
                @Override
                public void enone() {
                    // update in episode service
                    MediaPackage mp = authorizationService.removeAcl(episodeSvcMp, AclScope.Episode);
                    if (assetManager != null)
                        assetManager.takeSnapshot(mp);
                }
            });
            // apply optional workflow
            for (ConfiguredWorkflowRef workflowRef : workflow) applyWorkflow(list(episodeSvcMp), workflowRef);
            return true;
        }
        // not found
        return false;
    } catch (Exception e) {
        logger.error("Error applying episode ACL", e);
        throw new AclServiceException(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Option(org.opencastproject.util.data.Option) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 5 with AclServiceException

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

the class AbstractEventEndpoint method updateEventTransition.

@PUT
@Path("{eventId}/transitions/{transitionId}")
@RestQuery(name = "updateEventTransition", description = "Updates an ACL transition of an event", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING), @RestParameter(name = "transitionId", isRequired = true, description = "The transition identifier", type = RestParameter.Type.INTEGER) }, restParameters = { @RestParameter(name = "transition", isRequired = true, description = "The updated transition (JSON object)", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event or transtion has not been found."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method doesn't return any content") })
public Response updateEventTransition(@PathParam("eventId") String eventId, @PathParam("transitionId") long transitionId, @FormParam("transition") String transitionStr) throws NotFoundException, SearchIndexException {
    if (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().updateEpisodeTransition(transitionId, managedAclId, new Date(DateTimeSupport.fromUTC(t.getString("application_date"))), workflowRef);
        return Response.noContent().build();
    } 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 (AclServiceException e) {
        logger.error("Unable to update transtion {} of event {}: {}", transitionId, eventId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
    } catch (ParseException e) {
        // That should never happen
        throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
    }
}
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) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

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