use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class StreamAlertResource method addReceiver.
@POST
@Timed
@Path("receivers")
@ApiOperation(value = "Add an alert receiver")
@ApiResponses(value = { @ApiResponse(code = 404, message = "Stream not found."), @ApiResponse(code = 400, message = "Invalid ObjectId."), @ApiResponse(code = 400, message = "Stream has no email alarm callbacks.") })
@AuditEvent(type = AuditEventTypes.ALERT_RECEIVER_CREATE)
@Deprecated
public Response addReceiver(@ApiParam(name = "streamId", value = "The stream id this new alert condition belongs to.", required = true) @PathParam("streamId") String streamId, @ApiParam(name = "entity", value = "Name/ID of user or email address to add as alert receiver.", required = true) @QueryParam("entity") String entity, @ApiParam(name = "type", value = "Type: users or emails", required = true) @QueryParam("type") String type) throws org.graylog2.database.NotFoundException {
checkPermission(RestPermissions.STREAMS_EDIT, streamId);
checkArgument(!Strings.isNullOrEmpty(entity));
if (type == null || !"users".equals(type) && !"emails".equals(type)) {
final String msg = "No such type: [" + type + "]";
LOG.warn(msg);
throw new BadRequestException(msg);
}
final Stream stream = streamService.load(streamId);
// TODO What's the actual URI of the created resource?
final URI streamAlertUri = getUriBuilderToSelf().path(StreamAlertResource.class).build(streamId);
// Maybe the list already contains this receiver?
if (stream.getAlertReceivers().containsKey(type) || stream.getAlertReceivers().get(type) != null && stream.getAlertReceivers().get(type).contains(entity)) {
return Response.created(streamAlertUri).build();
}
streamService.addAlertReceiver(stream, type, entity);
return Response.created(streamAlertUri).build();
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class StreamOutputResource method add.
@POST
@Timed
@ApiOperation(value = "Associate outputs with a stream")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_CREATE)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid output specification in input.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_CREATE)
public Response add(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "JSON body", required = true) @Valid @NotNull AddOutputRequest aor) throws ValidationException, NotFoundException {
final Stream stream = streamService.load(streamid);
for (String outputId : aor.outputs()) {
final Output output = outputService.load(outputId);
streamService.addOutput(stream, output);
clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
return Response.accepted().build();
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class StreamOutputResource method remove.
@DELETE
@Path("/{outputId}")
@Timed
@RequiresPermissions(RestPermissions.STREAM_OUTPUTS_DELETE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete output of a stream")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream/output on this node.") })
@AuditEvent(type = AuditEventTypes.STREAM_OUTPUT_ASSIGNMENT_DELETE)
public void remove(@ApiParam(name = "streamid", value = "The id of the stream whose outputs we want.", required = true) @PathParam("streamid") String streamid, @ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId) throws NotFoundException {
final Stream stream = streamService.load(streamid);
final Output output = outputService.load(outputId);
streamService.removeOutput(stream, output);
outputRegistry.removeOutput(output);
clusterEventBus.post(StreamsChangedEvent.create(stream.getId()));
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class RolesResource method addMember.
@PUT
@Path("{rolename}/members/{username}")
@ApiOperation("Add a user to a role")
@AuditEvent(type = AuditEventTypes.ROLE_MEMBERSHIP_UPDATE)
public Response addMember(@ApiParam(name = "rolename") @PathParam("rolename") String rolename, @ApiParam(name = "username") @PathParam("username") String username, @ApiParam(name = "JSON Body", value = "Placeholder because PUT requests should have a body. Set to '{}', the content will be ignored.", defaultValue = "{}") String body) throws NotFoundException {
checkPermission(RestPermissions.ROLES_EDIT, username);
final User user = userService.load(username);
if (user == null) {
throw new NotFoundException("User " + username + " has not been found.");
}
// verify that the role exists
final Role role = roleService.load(rolename);
final HashSet<String> roles = Sets.newHashSet(user.getRoleIds());
roles.add(role.getId());
user.setRoleIds(roles);
try {
userService.save(user);
} catch (ValidationException e) {
throw new BadRequestException("Validation failed", e);
}
return status(Response.Status.NO_CONTENT).build();
}
use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.
the class RolesResource method removeMember.
@DELETE
@Path("{rolename}/members/{username}")
@ApiOperation("Remove a user from a role")
@AuditEvent(type = AuditEventTypes.ROLE_MEMBERSHIP_DELETE)
public Response removeMember(@ApiParam(name = "rolename") @PathParam("rolename") String rolename, @ApiParam(name = "username") @PathParam("username") String username) throws NotFoundException {
checkPermission(RestPermissions.ROLES_EDIT, username);
final User user = userService.load(username);
if (user == null) {
throw new NotFoundException("User " + username + " has not been found.");
}
// verify that the role exists
final Role role = roleService.load(rolename);
final HashSet<String> roles = Sets.newHashSet(user.getRoleIds());
roles.remove(role.getId());
user.setRoleIds(roles);
try {
userService.save(user);
} catch (ValidationException e) {
throw new BadRequestException("Validation failed", e);
}
return status(Response.Status.NO_CONTENT).build();
}
Aggregations