use of org.graylog2.rest.models.roles.responses.RoleResponse 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());
}
use of org.graylog2.rest.models.roles.responses.RoleResponse in project graylog2-server by Graylog2.
the class RolesResource method create.
@POST
@RequiresPermissions(RestPermissions.ROLES_CREATE)
@ApiOperation(value = "Create a new role", notes = "")
@AuditEvent(type = AuditEventTypes.ROLE_CREATE)
public Response create(@ApiParam(name = "JSON body", value = "The new role to create", required = true) @Valid @NotNull RoleResponse roleResponse) {
if (roleService.exists(roleResponse.name())) {
throw new BadRequestException("Role " + roleResponse.name() + " already exists.");
}
Role role = new RoleImpl();
role.setName(roleResponse.name());
role.setPermissions(roleResponse.permissions());
role.setDescription(roleResponse.description().orNull());
try {
role = roleService.save(role);
} catch (ValidationException e) {
log.error("Invalid role creation request.");
throw new BadRequestException(e);
}
final URI uri = getUriBuilderToSelf().path(RolesResource.class).path("{rolename}").build(role.getName());
return Response.created(uri).entity(RoleResponse.create(role.getName(), Optional.fromNullable(role.getDescription()), role.getPermissions(), role.isReadOnly())).build();
}
use of org.graylog2.rest.models.roles.responses.RoleResponse 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());
}
use of org.graylog2.rest.models.roles.responses.RoleResponse 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);
}
Aggregations