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));
}
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);
}
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();
}
Aggregations