use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class DecoratorResource method delete.
@DELETE
@Path("/{decoratorId}")
@Timed
@ApiOperation(value = "Create a decorator")
@AuditEvent(type = AuditEventTypes.MESSAGE_DECORATOR_DELETE)
public void delete(@ApiParam(name = "decorator id", required = true) @PathParam("decoratorId") final String decoratorId) throws NotFoundException {
checkPermission(RestPermissions.DECORATORS_EDIT);
final Decorator decorator = this.decoratorService.findById(decoratorId);
if (decorator.stream().isPresent()) {
checkPermission(RestPermissions.STREAMS_EDIT, decorator.stream().get());
}
this.decoratorService.delete(decoratorId);
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class StreamAlarmCallbackResource method create.
@POST
@Timed
@ApiOperation(value = "Create an alarm callback", response = CreateAlarmCallbackResponse.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ALARM_CALLBACK_CREATE)
public Response create(@ApiParam(name = "streamid", value = "The stream id this new alarm callback belongs to.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "JSON body", required = true) CreateAlarmCallbackRequest originalCr) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_EDIT, streamid);
// make sure the values are correctly converted to the declared configuration types
final CreateAlarmCallbackRequest cr = CreateAlarmCallbackRequest.create(originalCr.type(), originalCr.title(), convertConfigurationValues(originalCr));
final AlarmCallbackConfiguration alarmCallbackConfiguration = alarmCallbackConfigurationService.create(streamid, cr, getCurrentUser().getName());
final String id;
try {
alarmCallbackFactory.create(alarmCallbackConfiguration).checkConfiguration();
id = alarmCallbackConfigurationService.save(alarmCallbackConfiguration);
} catch (ValidationException | AlarmCallbackConfigurationException | ConfigurationException e) {
LOG.error("Invalid alarm callback configuration.", e);
throw new BadRequestException(e.getMessage(), e);
} catch (ClassNotFoundException e) {
LOG.error("Invalid alarm callback type.", e);
throw new BadRequestException("Invalid alarm callback type.", e);
}
final URI alarmCallbackUri = getUriBuilderToSelf().path(StreamAlarmCallbackResource.class).path("{alarmCallbackId}").build(streamid, id);
return Response.created(alarmCallbackUri).entity(CreateAlarmCallbackResponse.create(id)).build();
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class AuditEventModelProcessor method checkResources.
private void checkResources(List<Resource> resources) {
for (Resource resource : resources) {
for (ResourceMethod method : resource.getResourceMethods()) {
final Method m = method.getInvocable().getDefinitionMethod();
if (m.isAnnotationPresent(POST.class) || m.isAnnotationPresent(PUT.class) || m.isAnnotationPresent(DELETE.class)) {
if (!m.isAnnotationPresent(AuditEvent.class) && !m.isAnnotationPresent(NoAuditEvent.class)) {
LOG.warn("REST endpoint not included in audit trail: {}", String.format(Locale.US, "%6s %s", method.getHttpMethod(), getPathFromResource(resource)));
LOG.debug("Missing @AuditEvent or @NoAuditEvent annotation: {}#{}", m.getDeclaringClass().getCanonicalName(), m.getName());
} else {
if (m.isAnnotationPresent(AuditEvent.class)) {
final AuditEvent annotation = m.getAnnotation(AuditEvent.class);
if (!auditEventTypes.contains(annotation.type())) {
LOG.warn("REST endpoint does not use a registered audit type: {} (type: \"{}\")", String.format(Locale.US, "%6s %s", method.getHttpMethod(), getPathFromResource(resource)), annotation.type());
LOG.debug("Make sure the audit event types are registered in a class that implements PluginAuditEventTypes: {}#{}", m.getDeclaringClass().getCanonicalName(), m.getName());
}
} else if (m.isAnnotationPresent(NoAuditEvent.class)) {
final NoAuditEvent annotation = m.getAnnotation(NoAuditEvent.class);
if (isNullOrEmpty(annotation.value())) {
LOG.warn("REST endpoint uses @NoAuditEvent annotation with an empty value: {}", String.format(Locale.US, "%6s %s", method.getHttpMethod(), getPathFromResource(resource)));
}
}
}
}
}
// Make sure to also check all child resources! Otherwise some resources will not be checked.
checkResources(resource.getChildResources());
}
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class SystemProcessingResource method resumeProcessing.
@PUT
@Timed
@ApiOperation(value = "Resume message processing")
@Path("resume")
@AuditEvent(type = AuditEventTypes.MESSAGE_PROCESSING_START)
public void resumeProcessing() {
checkPermission(RestPermissions.PROCESSING_CHANGESTATE, serverStatus.getNodeId().toString());
try {
serverStatus.resumeMessageProcessing();
} catch (ProcessingPauseLockedException e) {
LOG.error("Message processing pause is locked. Returning HTTP 403.");
throw new ForbiddenException(e);
}
LOG.info("Resumed message processing - triggered by REST call.");
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class BundleResource method createBundle.
@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Upload a content pack")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Missing or invalid content pack"), @ApiResponse(code = 500, message = "Error while saving content pack") })
@AuditEvent(type = AuditEventTypes.CONTENT_PACK_CREATE)
public Response createBundle(@ApiParam(name = "Request body", value = "Content pack", required = true) @NotNull @Valid final ConfigurationBundle configurationBundle) {
checkPermission(RestPermissions.BUNDLE_CREATE);
final ConfigurationBundle bundle = bundleService.insert(configurationBundle);
final URI bundleUri = getUriBuilderToSelf().path(BundleResource.class).path("{bundleId}").build(bundle.getId());
return Response.created(bundleUri).build();
}
Aggregations