use of org.opencastproject.authorization.xacml.manager.api.AclServiceException in project opencast by opencast.
the class SeriesEndpoint method applyAclToSeries.
@POST
@Path("/{seriesId}/access")
@RestQuery(name = "applyAclToSeries", description = "Immediate application of an ACL to a series", returnDescription = "Status code", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series ID", type = STRING) }, restParameters = { @RestParameter(name = "acl", isRequired = true, description = "The ACL to apply", type = STRING), @RestParameter(name = "override", isRequired = false, defaultValue = "false", description = "If true the series ACL will take precedence over any existing episode ACL", type = BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the given ACL"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series has not been found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToSeries(@PathParam("seriesId") String seriesId, @FormParam("acl") String acl, @DefaultValue("false") @FormParam("override") boolean override) throws SearchIndexException {
AccessControlList accessControlList;
try {
accessControlList = AccessControlParser.parseAcl(acl);
} catch (Exception e) {
logger.warn("Unable to parse ACL '{}'", acl);
return badRequest();
}
Opt<Series> series = indexService.getSeries(seriesId, searchIndex);
if (series.isNone())
return notFound("Cannot find a series with id {}", seriesId);
if (hasProcessingEvents(seriesId)) {
logger.warn("Can not update the ACL from series {}. Events being part of the series are currently processed.", seriesId);
return conflict();
}
try {
if (getAclService().applyAclToSeries(seriesId, accessControlList, override, Option.none()))
return ok();
else {
logger.warn("Unable to find series '{}' to apply the ACL.", seriesId);
return notFound();
}
} catch (AclServiceException e) {
logger.error("Error applying acl to series {}", seriesId);
return serverError();
}
}
use of org.opencastproject.authorization.xacml.manager.api.AclServiceException in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method addEpisodeTransition.
@POST
@Path("/episode/{episodeId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "addepisodetransition", description = "Add an episode transition", returnDescription = "Add an episode transition", pathParameters = { @RestParameter(name = "episodeId", isRequired = true, description = "The episode 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 added"), @RestResponse(responseCode = SC_CONFLICT, description = "The episode transition with the applicationDate already exists"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding an episode transition") })
public String addEpisodeTransition(@PathParam("episodeId") String episodeId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") Long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) {
try {
final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
final EpisodeACLTransition transition = aclService().addEpisodeTransition(episodeId, option(managedAclId), at, workflow);
return JsonConv.full(transition).toJson();
} catch (AclTransitionDbDuplicatedException e) {
logger.info("Error adding episode transition: transition with date {} already exists", applicationDate);
throw new WebApplicationException(Status.CONFLICT);
} catch (AclServiceException e) {
logger.warn("Error adding episode 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);
}
}
use of org.opencastproject.authorization.xacml.manager.api.AclServiceException in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method applyAclToEpisode.
@POST
@Path("/apply/episode/{episodeId}")
@RestQuery(name = "applyAclToEpisode", description = "Immediate application of an ACL to an episode", returnDescription = "Status code", pathParameters = { @RestParameter(name = "episodeId", isRequired = true, description = "The episode ID", type = STRING) }, restParameters = { @RestParameter(name = "aclId", isRequired = false, description = "The ID of the ACL to apply. If missing the episode ACL will be deleted to fall back to the series ACL", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The optional workflow to apply to the episode after", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "Parameters for the optional workflow", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The ACL or the episode has not been found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToEpisode(@PathParam("episodeId") String episodeId, @FormParam("aclId") Long aclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) {
final AclService aclService = aclService();
final Option<Option<ManagedAcl>> macl = option(aclId).map(getManagedAcl(aclService));
if (macl.isSome() && macl.get().isNone())
return notFound();
final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
try {
if (aclService.applyAclToEpisode(episodeId, Options.join(macl), workflow))
return ok();
else
return notFound();
} catch (AclServiceException e) {
logger.error("Error applying acl to episode {}", episodeId);
return serverError();
}
}
use of org.opencastproject.authorization.xacml.manager.api.AclServiceException in project opencast by opencast.
the class AclScanner method removeAcl.
/**
* Remove an ACL based upon an XACML file from all the organizations.
*
* @param artifact
* The File representing the XACML File.
* @throws IOException
* @throws JAXBException
*/
private void removeAcl(File artifact) throws IOException, JAXBException {
List<Organization> organizations = organizationDirectoryService.getOrganizations();
logger.debug("Removing Acl {}", artifact.getAbsolutePath());
String fileName = FilenameUtils.removeExtension(artifact.getName());
// Remove the Acl on all the organizations
for (Organization org : organizations) {
securityService.setOrganization(org);
Long id = managedAcls.get(generateAclId(fileName, org));
if (id != null) {
try {
getAclService(org).deleteAcl(id);
} catch (NotFoundException e) {
logger.warn("Unable to delete managec acl {}: Managed acl already deleted!", id);
} catch (AclServiceException e) {
logger.error("Unable to delete managed acl {}: {}", id, ExceptionUtils.getStackTrace(e));
}
} else {
logger.debug("No Acl found with the id {}.", id);
}
}
}
use of org.opencastproject.authorization.xacml.manager.api.AclServiceException in project opencast by opencast.
the class AbstractEventEndpoint method applyAclToEvent.
@POST
@Path("{eventId}/access")
@RestQuery(name = "applyAclToEvent", description = "Immediate application of an ACL to an event", returnDescription = "Status code", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event ID", type = STRING) }, restParameters = { @RestParameter(name = "acl", isRequired = true, description = "The ACL to apply", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the given ACL"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The the event has not been found"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "Not authorized to perform this action"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToEvent(@PathParam("eventId") String eventId, @FormParam("acl") String acl) throws NotFoundException, UnauthorizedException, SearchIndexException, IndexServiceException {
final AccessControlList accessControlList;
try {
accessControlList = AccessControlParser.parseAcl(acl);
} catch (Exception e) {
logger.warn("Unable to parse ACL '{}'", acl);
return badRequest();
}
try {
final Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone()) {
logger.warn("Unable to find the event '{}'", eventId);
return notFound();
}
Source eventSource = getIndexService().getEventSource(optEvent.get());
if (eventSource == Source.ARCHIVE) {
if (getAclService().applyAclToEpisode(eventId, accessControlList, Option.<ConfiguredWorkflowRef>none())) {
return ok();
} else {
logger.warn("Unable to find the event '{}'", eventId);
return notFound();
}
} else if (eventSource == Source.WORKFLOW) {
logger.warn("An ACL cannot be edited while an event is part of a current workflow because it might" + " lead to inconsistent ACLs i.e. changed after distribution so that the old ACL is still " + "being used by the distribution channel.");
JSONObject json = new JSONObject();
json.put("Error", "Unable to edit an ACL for a current workflow.");
return conflict(json.toJSONString());
} else {
MediaPackage mediaPackage = getIndexService().getEventMediapackage(optEvent.get());
mediaPackage = getAuthorizationService().setAcl(mediaPackage, AclScope.Episode, accessControlList).getA();
getSchedulerService().updateEvent(eventId, Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), some(mediaPackage), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
return ok();
}
} catch (AclServiceException e) {
logger.error("Error applying acl '{}' to event '{}' because: {}", accessControlList, eventId, ExceptionUtils.getStackTrace(e));
return serverError();
} catch (SchedulerException e) {
logger.error("Error applying ACL to scheduled event {} because {}", eventId, ExceptionUtils.getStackTrace(e));
return serverError();
}
}
Aggregations