Search in sources :

Example 1 with FilterDescription

use of org.graylog2.filters.blacklist.FilterDescription in project graylog2-server by Graylog2.

the class BlacklistSourceResource method update.

@PUT
@Timed
@Path("/{filterId}")
@ApiOperation(value = "Update an existing blacklist filter", notes = "It can take up to a second until the change is applied")
@Consumes(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.BLACKLIST_FILTER_UPDATE)
public void update(@ApiParam(name = "filterId", required = true) @PathParam("filterId") String filterId, @ApiParam(name = "filterEntry", required = true) FilterDescription filterEntry) throws org.graylog2.database.NotFoundException, ValidationException {
    FilterDescription filter = filterService.load(filterId);
    // did the filter type change?
    if (!filter.getClass().equals(filterEntry.getClass())) {
        // copy the relevant fields from the saved filter and then use the new class
        filterEntry._id = filter._id;
        filterEntry.createdAt = filter.createdAt;
        filterEntry.creatorUserId = filter.creatorUserId;
        filter = filterEntry;
    } else {
        // just copy the changable fields
        filter.description = filterEntry.description;
        filter.fieldName = filterEntry.fieldName;
        filter.name = filterEntry.name;
        filter.pattern = filterEntry.pattern;
    }
    filterService.save(filter);
    clusterEventBus.post(FilterDescriptionUpdateEvent.create(filterId));
}
Also used : FilterDescription(org.graylog2.filters.blacklist.FilterDescription) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 2 with FilterDescription

use of org.graylog2.filters.blacklist.FilterDescription in project graylog2-server by Graylog2.

the class FilterServiceImplTest method testProperDeserializationOfSubclasses.

@Test
@UsingDataSet(locations = "properDeserializationOfSubclasses.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testProperDeserializationOfSubclasses() throws Exception {
    final Set<FilterDescription> filterDescriptionSet = filterService.loadAll();
    assertThat(filterDescriptionSet).isNotNull().hasSize(1);
    final FilterDescription filterDescription = filterDescriptionSet.iterator().next();
    assertThat(filterDescription).isNotNull();
    assertThat(filterDescription).isInstanceOf(BlacklistPatternCondition.class);
}
Also used : FilterDescription(org.graylog2.filters.blacklist.FilterDescription) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 3 with FilterDescription

use of org.graylog2.filters.blacklist.FilterDescription in project graylog2-server by Graylog2.

the class BlacklistSourceResource method create.

@POST
@Timed
@ApiOperation(value = "Create a blacklist filter", notes = "It can take up to a second until the change is applied")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.BLACKLIST_FILTER_CREATE)
public Response create(@ApiParam(name = "filterEntry", required = true) @Valid @NotNull FilterDescription filterDescription) throws ValidationException {
    checkPermission(RestPermissions.BLACKLISTENTRY_CREATE);
    // force the user name to be consistent with the requesting user
    final User currentUser = getCurrentUser();
    if (currentUser == null) {
        throw new InternalServerErrorException("Could not load user.");
    }
    filterDescription.creatorUserId = currentUser.getName();
    final FilterDescription savedFilter = filterService.save(filterDescription);
    clusterEventBus.post(FilterDescriptionUpdateEvent.create(savedFilter._id.toHexString()));
    final URI filterUri = getUriBuilderToSelf().path(BlacklistSourceResource.class).path("{filterId}").build(savedFilter._id);
    return Response.created(filterUri).entity(savedFilter).build();
}
Also used : User(org.graylog2.plugin.database.users.User) FilterDescription(org.graylog2.filters.blacklist.FilterDescription) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) URI(java.net.URI) 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)

Aggregations

FilterDescription (org.graylog2.filters.blacklist.FilterDescription)3 Timed (com.codahale.metrics.annotation.Timed)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Consumes (javax.ws.rs.Consumes)2 AuditEvent (org.graylog2.audit.jersey.AuditEvent)2 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)1 URI (java.net.URI)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 User (org.graylog2.plugin.database.users.User)1 Test (org.junit.Test)1