Search in sources :

Example 26 with AuditEvent

use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.

the class LookupTableResource method updateCache.

@PUT
@Path("caches/{idOrName}")
@AuditEvent(type = AuditEventTypes.LOOKUP_CACHE_UPDATE)
@ApiOperation(value = "Update the given cache settings")
public CacheApi updateCache(@ApiParam(name = "idOrName") @PathParam("idOrName") @NotEmpty String idOrName, @ApiParam CacheApi toUpdate) {
    checkLookupCacheId(idOrName, toUpdate);
    checkPermission(RestPermissions.LOOKUP_TABLES_EDIT, toUpdate.id());
    CacheDto saved = dbCacheService.save(toUpdate.toDto());
    return CacheApi.fromDto(saved);
}
Also used : CacheDto(org.graylog2.lookup.dto.CacheDto) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 27 with AuditEvent

use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.

the class UsersResource method savePreferences.

@PUT
@Path("{username}/preferences")
@ApiOperation("Update a user's preferences set.")
@ApiResponses({ @ApiResponse(code = 400, message = "Missing or invalid permission data.") })
@AuditEvent(type = AuditEventTypes.USER_PREFERENCES_UPDATE)
public void savePreferences(@ApiParam(name = "username", value = "The name of the user to modify.", required = true) @PathParam("username") String username, @ApiParam(name = "JSON body", value = "The map of preferences to assign to the user.", required = true) UpdateUserPreferences preferencesRequest) throws ValidationException {
    final User user = userManagementService.load(username);
    checkPermission(RestPermissions.USERS_EDIT, username);
    if (user == null) {
        throw new NotFoundException("Couldn't find user " + username);
    }
    user.setPreferences(preferencesRequest.preferences());
    userManagementService.save(user);
}
Also used : User(org.graylog2.plugin.database.users.User) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 28 with AuditEvent

use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.

the class UsersResource method updateAccountStatus.

@PUT
@Path("{userId}/status/{newStatus}")
@Consumes(MediaType.WILDCARD)
@ApiOperation("Update the account status for a user")
@AuditEvent(type = AuditEventTypes.USER_UPDATE)
public Response updateAccountStatus(@ApiParam(name = "userId", value = "The id of the user whose status to change.", required = true) @PathParam("userId") @NotBlank String userId, @ApiParam(name = "newStatus", value = "The account status to be set", required = true, defaultValue = "enabled", allowableValues = "enabled,disabled,deleted") @PathParam("newStatus") @NotBlank String newStatusString, @Context UserContext userContext) throws ValidationException {
    if (userId.equalsIgnoreCase(userContext.getUserId())) {
        throw new BadRequestException("Users are not allowed to set their own status");
    }
    final User.AccountStatus newStatus = User.AccountStatus.valueOf(newStatusString.toUpperCase(Locale.US));
    final User user = loadUserById(userId);
    checkPermission(RestPermissions.USERS_EDIT, user.getName());
    final User.AccountStatus oldStatus = user.getAccountStatus();
    if (oldStatus.equals(newStatus)) {
        return Response.notModified().build();
    }
    userManagementService.setUserStatus(user, newStatus);
    return Response.ok().build();
}
Also used : User(org.graylog2.plugin.database.users.User) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 29 with AuditEvent

use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.

the class InputStatesResource method start.

@PUT
@Path("/{inputId}")
@Timed
@ApiOperation(value = "(Re-)Start specified input on this node")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_INPUT_START)
public InputCreated start(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws org.graylog2.database.NotFoundException {
    checkPermission(RestPermissions.INPUTS_CHANGESTATE, inputId);
    final Input input = inputService.find(inputId);
    persistDesiredState(input, IOState.Type.RUNNING);
    final InputCreated result = InputCreated.create(inputId);
    this.serverEventBus.post(result);
    return result;
}
Also used : Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) InputCreated(org.graylog2.rest.models.system.inputs.responses.InputCreated) 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) ApiResponses(io.swagger.annotations.ApiResponses)

Example 30 with AuditEvent

use of org.graylog2.audit.jersey.AuditEvent in project graylog2-server by Graylog2.

the class OutputResource method delete.

@DELETE
@Path("/{outputId}")
@Timed
@ApiOperation(value = "Delete output")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such stream/output on this node.") })
@AuditEvent(type = AuditEventTypes.MESSAGE_OUTPUT_DELETE)
public void delete(@ApiParam(name = "outputId", value = "The id of the output that should be deleted", required = true) @PathParam("outputId") String outputId) throws org.graylog2.database.NotFoundException {
    checkPermission(RestPermissions.OUTPUTS_TERMINATE);
    final Output output = outputService.load(outputId);
    outputService.destroy(output);
}
Also used : Output(org.graylog2.plugin.streams.Output) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) 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)134 ApiOperation (io.swagger.annotations.ApiOperation)132 Path (javax.ws.rs.Path)100 Timed (com.codahale.metrics.annotation.Timed)87 ApiResponses (io.swagger.annotations.ApiResponses)64 PUT (javax.ws.rs.PUT)55 POST (javax.ws.rs.POST)52 Produces (javax.ws.rs.Produces)48 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)47 BadRequestException (javax.ws.rs.BadRequestException)46 Consumes (javax.ws.rs.Consumes)38 DELETE (javax.ws.rs.DELETE)34 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)33 NotFoundException (javax.ws.rs.NotFoundException)24 URI (java.net.URI)22 ValidationException (org.graylog2.plugin.database.ValidationException)16 Stream (org.graylog2.plugin.streams.Stream)16 NotFoundException (org.graylog2.database.NotFoundException)15 User (org.graylog2.plugin.database.users.User)14 ValidationResult (org.graylog2.plugin.rest.ValidationResult)12