Search in sources :

Example 11 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class RolesResource method delete.

@DELETE
@Path("{rolename}")
@ApiOperation(value = "Remove the named role and dissociate any users from it")
@AuditEvent(type = AuditEventTypes.ROLE_DELETE)
public void delete(@ApiParam(name = "rolename", required = true) @PathParam("rolename") String name) throws NotFoundException {
    checkPermission(RestPermissions.ROLES_DELETE, name);
    final Role role = roleService.load(name);
    if (role.isReadOnly()) {
        throw new BadRequestException("Cannot delete read only system role " + name);
    }
    userService.dissociateAllUsersFromRole(role);
    if (roleService.delete(name) == 0) {
        throw new NotFoundException("Couldn't find role " + name);
    }
}
Also used : Role(org.graylog2.shared.users.Role) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(org.graylog2.database.NotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 12 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class RolesResource method read.

@GET
@Path("{rolename}")
@ApiOperation("Retrieve permissions for a single role")
public RoleResponse read(@ApiParam(name = "rolename", required = true) @PathParam("rolename") String name) throws NotFoundException {
    checkPermission(RestPermissions.ROLES_READ, name);
    final Role role = roleService.load(name);
    return RoleResponse.create(role.getName(), Optional.fromNullable(role.getDescription()), role.getPermissions(), role.isReadOnly());
}
Also used : Role(org.graylog2.shared.users.Role) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 13 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class RolesResource method update.

@PUT
@Path("{rolename}")
@ApiOperation("Update an existing role")
@AuditEvent(type = AuditEventTypes.ROLE_UPDATE)
public RoleResponse update(@ApiParam(name = "rolename", required = true) @PathParam("rolename") String name, @ApiParam(name = "JSON Body", value = "The new representation of the role", required = true) RoleResponse role) throws NotFoundException {
    final Role roleToUpdate = roleService.load(name);
    if (roleToUpdate.isReadOnly()) {
        throw new BadRequestException("Cannot update read only role " + name);
    }
    roleToUpdate.setName(role.name());
    roleToUpdate.setDescription(role.description().orNull());
    roleToUpdate.setPermissions(role.permissions());
    try {
        roleService.save(roleToUpdate);
    } catch (ValidationException e) {
        throw new BadRequestException(e);
    }
    return RoleResponse.create(roleToUpdate.getName(), Optional.fromNullable(roleToUpdate.getDescription()), roleToUpdate.getPermissions(), role.readOnly());
}
Also used : Role(org.graylog2.shared.users.Role) ValidationException(org.graylog2.plugin.database.ValidationException) BadRequestException(javax.ws.rs.BadRequestException) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 14 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class RolesResource method listAll.

@GET
@RequiresPermissions(RestPermissions.ROLES_READ)
@ApiOperation(value = "List all roles", notes = "")
public RolesResponse listAll() throws NotFoundException {
    final Set<Role> roles = roleService.loadAll();
    Set<RoleResponse> roleResponses = Sets.newHashSet();
    for (Role role : roles) {
        roleResponses.add(RoleResponse.create(role.getName(), Optional.fromNullable(role.getDescription()), role.getPermissions(), role.isReadOnly()));
    }
    return RolesResponse.create(roleResponses);
}
Also used : Role(org.graylog2.shared.users.Role) RoleResponse(org.graylog2.rest.models.roles.responses.RoleResponse) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 15 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class DecoratorResource method update.

@PUT
@Path("/{decoratorId}")
@Timed
@ApiOperation(value = "Update a decorator")
@AuditEvent(type = AuditEventTypes.MESSAGE_DECORATOR_UPDATE)
public Decorator update(@ApiParam(name = "decorator id", required = true) @PathParam("decoratorId") final String decoratorId, @ApiParam(name = "JSON body", required = true) DecoratorImpl decorator) throws NotFoundException {
    final Decorator originalDecorator = decoratorService.findById(decoratorId);
    checkPermission(RestPermissions.DECORATORS_CREATE);
    if (originalDecorator.stream().isPresent()) {
        checkPermission(RestPermissions.STREAMS_EDIT, originalDecorator.stream().get());
    }
    return this.decoratorService.save(decorator.toBuilder().id(originalDecorator.id()).build());
}
Also used : SearchResponseDecorator(org.graylog2.plugin.decorators.SearchResponseDecorator) Decorator(org.graylog2.decorators.Decorator) 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)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)91 Timed (com.codahale.metrics.annotation.Timed)77 Path (javax.ws.rs.Path)75 ApiResponses (io.swagger.annotations.ApiResponses)66 AuditEvent (org.graylog2.audit.jersey.AuditEvent)60 Produces (javax.ws.rs.Produces)44 NotFoundException (org.graylog2.database.NotFoundException)32 GET (javax.ws.rs.GET)30 PUT (javax.ws.rs.PUT)28 BadRequestException (javax.ws.rs.BadRequestException)27 Stream (org.graylog2.plugin.streams.Stream)27 NotFoundException (javax.ws.rs.NotFoundException)26 Consumes (javax.ws.rs.Consumes)21 DELETE (javax.ws.rs.DELETE)21 POST (javax.ws.rs.POST)19 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)15 MessageInput (org.graylog2.plugin.inputs.MessageInput)15 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)11 Input (org.graylog2.inputs.Input)11 ValidationException (org.graylog2.plugin.database.ValidationException)11