Search in sources :

Example 61 with AuditEvent

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);
}
Also used : SearchResponseDecorator(org.graylog2.plugin.decorators.SearchResponseDecorator) Decorator(org.graylog2.decorators.Decorator) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 62 with AuditEvent

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();
}
Also used : CreateAlarmCallbackRequest(org.graylog2.rest.models.alarmcallbacks.requests.CreateAlarmCallbackRequest) ValidationException(org.graylog2.plugin.database.ValidationException) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlarmCallbackConfigurationException(org.graylog2.plugin.alarms.callbacks.AlarmCallbackConfigurationException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 63 with AuditEvent

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());
    }
}
Also used : DELETE(javax.ws.rs.DELETE) RestTools.getPathFromResource(org.graylog2.rest.RestTools.getPathFromResource) Resource(org.glassfish.jersey.server.model.Resource) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) Method(java.lang.reflect.Method) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod)

Example 64 with AuditEvent

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.");
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) ProcessingPauseLockedException(org.graylog2.plugin.ProcessingPauseLockedException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 65 with AuditEvent

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();
}
Also used : ConfigurationBundle(org.graylog2.bundles.ConfigurationBundle) URI(java.net.URI) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

AuditEvent (org.graylog2.audit.jersey.AuditEvent)93 ApiOperation (io.swagger.annotations.ApiOperation)92 Timed (com.codahale.metrics.annotation.Timed)76 Path (javax.ws.rs.Path)70 ApiResponses (io.swagger.annotations.ApiResponses)56 PUT (javax.ws.rs.PUT)36 Produces (javax.ws.rs.Produces)34 POST (javax.ws.rs.POST)33 BadRequestException (javax.ws.rs.BadRequestException)31 Consumes (javax.ws.rs.Consumes)29 DELETE (javax.ws.rs.DELETE)26 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)22 URI (java.net.URI)19 Stream (org.graylog2.plugin.streams.Stream)16 NotFoundException (javax.ws.rs.NotFoundException)15 NotFoundException (org.graylog2.database.NotFoundException)14 ValidationException (org.graylog2.plugin.database.ValidationException)13 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)12 Dashboard (org.graylog2.dashboards.Dashboard)9 Input (org.graylog2.inputs.Input)9